1 |
< |
/* Copyright (c) 1986 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1991 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
32 |
|
* tn = (sqrt(.8402528435+.0072522239*Tn*Tn)-.9166530661)/.0036261119/Tn |
33 |
|
* |
34 |
|
* The transmission of standard 88% transmissivity glass is 0.96. |
35 |
+ |
* A refractive index other than the default can be used by giving |
36 |
+ |
* it as the fourth real argument. The above formula no longer applies. |
37 |
+ |
* |
38 |
|
* If we appear to hit the back side of the surface, then we |
39 |
|
* turn the normal around. |
40 |
|
*/ |
46 |
|
OBJREC *m; |
47 |
|
register RAY *r; |
48 |
|
{ |
46 |
– |
double sqrt(), pow(); |
49 |
|
COLOR mcolor; |
50 |
|
double pdot; |
51 |
|
FVECT pnorm; |
52 |
< |
double cos2; |
52 |
> |
double rindex, cos2; |
53 |
|
COLOR trans, refl; |
54 |
< |
double d, r1; |
54 |
> |
double d, r1e, r1m; |
55 |
> |
double transtest, transdist; |
56 |
|
RAY p; |
57 |
|
register int i; |
58 |
< |
|
59 |
< |
if (m->oargs.nfargs != 3) |
58 |
> |
/* check arguments */ |
59 |
> |
if (m->oargs.nfargs == 3) |
60 |
> |
rindex = RINDEX; /* default value of n */ |
61 |
> |
else if (m->oargs.nfargs == 4) |
62 |
> |
rindex = m->oargs.farg[3]; /* use their value */ |
63 |
> |
else |
64 |
|
objerror(m, USER, "bad arguments"); |
65 |
|
|
66 |
|
setcolor(mcolor, m->oargs.farg[0], m->oargs.farg[1], m->oargs.farg[2]); |
67 |
|
|
68 |
|
if (r->rod < 0.0) /* reorient if necessary */ |
69 |
|
flipsurface(r); |
70 |
+ |
transtest = 0; |
71 |
|
/* get modifiers */ |
72 |
|
raytexture(r, m->omod); |
73 |
|
pdot = raynormal(pnorm, r); |
74 |
|
/* angular transmission */ |
75 |
< |
cos2 = sqrt( (1.0-1.0/RINDEX/RINDEX) + |
76 |
< |
pdot*pdot/(RINDEX*RINDEX) ); |
75 |
> |
cos2 = sqrt( (1.0-1.0/(rindex*rindex)) + |
76 |
> |
pdot*pdot/(rindex*rindex) ); |
77 |
|
setcolor(mcolor, pow(colval(mcolor,RED), 1.0/cos2), |
78 |
|
pow(colval(mcolor,GRN), 1.0/cos2), |
79 |
|
pow(colval(mcolor,BLU), 1.0/cos2)); |
80 |
|
|
81 |
|
/* compute reflection */ |
82 |
< |
r1 = (pdot - RINDEX*cos2) / (pdot + RINDEX*cos2); |
83 |
< |
d = (1.0/pdot - RINDEX/cos2) / (1.0/pdot + RINDEX/cos2); |
84 |
< |
r1 = (r1*r1 + d*d) / 2.0; |
82 |
> |
r1e = (pdot - rindex*cos2) / (pdot + rindex*cos2); |
83 |
> |
r1e *= r1e; |
84 |
> |
r1m = (1.0/pdot - rindex/cos2) / (1.0/pdot + rindex/cos2); |
85 |
> |
r1m *= r1m; |
86 |
|
/* compute transmittance */ |
87 |
|
for (i = 0; i < 3; i++) { |
88 |
|
d = colval(mcolor, i); |
89 |
< |
colval(trans,i) = (1.0-r1)*(1.0-r1)*d / (1.0 - r1*r1*d*d); |
89 |
> |
colval(trans,i) = .5*(1.0-r1e)*(1.0-r1e)*d/(1.0-r1e*r1e*d*d); |
90 |
> |
colval(trans,i) += .5*(1.0-r1m)*(1.0-r1m)*d/(1.0-r1m*r1m*d*d); |
91 |
|
} |
92 |
|
/* transmitted ray */ |
93 |
|
if (rayorigin(&p, r, TRANS, bright(trans)) == 0) { |
94 |
< |
VCOPY(p.rdir, r->rdir); |
94 |
> |
if (!(r->crtype & SHADOW) && |
95 |
> |
DOT(r->pert,r->pert) > FTINY*FTINY) { |
96 |
> |
for (i = 0; i < 3; i++) /* perturb direction */ |
97 |
> |
p.rdir[i] = r->rdir[i] + |
98 |
> |
2.*(1.-rindex)*r->pert[i]; |
99 |
> |
if (normalize(p.rdir) == 0.0) { |
100 |
> |
objerror(m, WARNING, "bad perturbation"); |
101 |
> |
VCOPY(p.rdir, r->rdir); |
102 |
> |
} |
103 |
> |
} else { |
104 |
> |
VCOPY(p.rdir, r->rdir); |
105 |
> |
transtest = 2; |
106 |
> |
} |
107 |
|
rayvalue(&p); |
108 |
|
multcolor(p.rcol, r->pcol); /* modify */ |
109 |
|
multcolor(p.rcol, trans); |
110 |
|
addcolor(r->rcol, p.rcol); |
111 |
+ |
transtest *= bright(p.rcol); |
112 |
+ |
transdist = r->rot + p.rt; |
113 |
|
} |
114 |
+ |
|
115 |
|
if (r->crtype & SHADOW) /* skip reflected ray */ |
116 |
|
return; |
117 |
|
/* compute reflectance */ |
118 |
|
for (i = 0; i < 3; i++) { |
119 |
|
d = colval(mcolor, i); |
120 |
|
d *= d; |
121 |
< |
colval(refl,i) = r1 * (1.0 + (1.0-2.0*r1)*d) / (1.0 - r1*r1*d); |
121 |
> |
colval(refl,i) = .5*r1e*(1.0+(1.0-2.0*r1e)*d)/(1.0-r1e*r1e*d); |
122 |
> |
colval(refl,i) += .5*r1m*(1.0+(1.0-2.0*r1m)*d)/(1.0-r1m*r1m*d); |
123 |
|
} |
124 |
|
/* reflected ray */ |
125 |
|
if (rayorigin(&p, r, REFLECTED, bright(refl)) == 0) { |
129 |
|
multcolor(p.rcol, refl); |
130 |
|
addcolor(r->rcol, p.rcol); |
131 |
|
} |
132 |
+ |
if (transtest > bright(r->rcol)) |
133 |
+ |
r->rt = transdist; |
134 |
|
} |