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"; |
49 |
|
FVECT pnorm; |
50 |
|
double cos2; |
51 |
|
COLOR trans, refl; |
52 |
< |
double d, r1; |
52 |
> |
double d, r1e, r1m; |
53 |
> |
double transtest, transdist; |
54 |
|
RAY p; |
55 |
|
register int i; |
56 |
|
|
61 |
|
|
62 |
|
if (r->rod < 0.0) /* reorient if necessary */ |
63 |
|
flipsurface(r); |
64 |
+ |
transtest = 0; |
65 |
|
/* get modifiers */ |
66 |
|
raytexture(r, m->omod); |
67 |
|
pdot = raynormal(pnorm, r); |
73 |
|
pow(colval(mcolor,BLU), 1.0/cos2)); |
74 |
|
|
75 |
|
/* compute reflection */ |
76 |
< |
r1 = (pdot - RINDEX*cos2) / (pdot + RINDEX*cos2); |
77 |
< |
d = (1.0/pdot - RINDEX/cos2) / (1.0/pdot + RINDEX/cos2); |
78 |
< |
r1 = (r1*r1 + d*d) / 2.0; |
76 |
> |
r1e = (pdot - RINDEX*cos2) / (pdot + RINDEX*cos2); |
77 |
> |
r1e *= r1e; |
78 |
> |
r1m = (1.0/pdot - RINDEX/cos2) / (1.0/pdot + RINDEX/cos2); |
79 |
> |
r1m *= r1m; |
80 |
|
/* compute transmittance */ |
81 |
|
for (i = 0; i < 3; i++) { |
82 |
|
d = colval(mcolor, i); |
83 |
< |
colval(trans,i) = (1.0-r1)*(1.0-r1)*d / (1.0 - r1*r1*d*d); |
83 |
> |
colval(trans,i) = .5*(1.0-r1e)*(1.0-r1e)*d/(1.0-r1e*r1e*d*d); |
84 |
> |
colval(trans,i) += .5*(1.0-r1m)*(1.0-r1m)*d/(1.0-r1m*r1m*d*d); |
85 |
|
} |
86 |
|
/* transmitted ray */ |
87 |
|
if (rayorigin(&p, r, TRANS, bright(trans)) == 0) { |
88 |
< |
VCOPY(p.rdir, r->rdir); |
88 |
> |
if (!(r->crtype & SHADOW) && |
89 |
> |
DOT(r->pert,r->pert) > FTINY*FTINY) { |
90 |
> |
for (i = 0; i < 3; i++) /* perturb direction */ |
91 |
> |
p.rdir[i] = r->rdir[i] - r->pert[i]/RINDEX; |
92 |
> |
normalize(p.rdir); |
93 |
> |
} else { |
94 |
> |
VCOPY(p.rdir, r->rdir); |
95 |
> |
transtest = 2; |
96 |
> |
} |
97 |
|
rayvalue(&p); |
98 |
|
multcolor(p.rcol, r->pcol); /* modify */ |
99 |
|
multcolor(p.rcol, trans); |
100 |
|
addcolor(r->rcol, p.rcol); |
101 |
+ |
transtest *= bright(p.rcol); |
102 |
+ |
transdist = r->rot + p.rt; |
103 |
|
} |
104 |
+ |
|
105 |
|
if (r->crtype & SHADOW) /* skip reflected ray */ |
106 |
|
return; |
107 |
|
/* compute reflectance */ |
108 |
|
for (i = 0; i < 3; i++) { |
109 |
|
d = colval(mcolor, i); |
110 |
|
d *= d; |
111 |
< |
colval(refl,i) = r1 * (1.0 + (1.0-2.0*r1)*d) / (1.0 - r1*r1*d); |
111 |
> |
colval(refl,i) = .5*r1e*(1.0+(1.0-2.0*r1e)*d)/(1.0-r1e*r1e*d); |
112 |
> |
colval(refl,i) += .5*r1m*(1.0+(1.0-2.0*r1m)*d)/(1.0-r1m*r1m*d); |
113 |
|
} |
114 |
|
/* reflected ray */ |
115 |
|
if (rayorigin(&p, r, REFLECTED, bright(refl)) == 0) { |
119 |
|
multcolor(p.rcol, refl); |
120 |
|
addcolor(r->rcol, p.rcol); |
121 |
|
} |
122 |
+ |
if (transtest > bright(r->rcol)) |
123 |
+ |
r->rt = transdist; |
124 |
|
} |