1 |
< |
/* Copyright (c) 1986 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1998 Silicon Graphics, Inc. */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
4 |
> |
static char SCCSid[] = "$SunId$ SGI"; |
5 |
|
#endif |
6 |
|
|
7 |
|
/* |
73 |
|
double cos1, cos2, nratio; |
74 |
|
COLOR ctrans; |
75 |
|
COLOR talb; |
76 |
< |
double mabsorp; |
76 |
> |
int hastexture; |
77 |
|
double refl, trans; |
78 |
|
FVECT dnorm; |
79 |
|
double d1, d2; |
85 |
|
|
86 |
|
raytexture(r, m->omod); /* get modifiers */ |
87 |
|
|
88 |
< |
cos1 = raynormal(dnorm, r); /* cosine of theta1 */ |
88 |
> |
if (hastexture = DOT(r->pert,r->pert) > FTINY*FTINY) |
89 |
> |
cos1 = raynormal(dnorm, r); /* perturb normal */ |
90 |
> |
else { |
91 |
> |
VCOPY(dnorm, r->ron); |
92 |
> |
cos1 = r->rod; |
93 |
> |
} |
94 |
|
/* index of refraction */ |
95 |
|
if (m->otype == MAT_DIELECTRIC) |
96 |
|
nratio = m->oargs.farg[3] + m->oargs.farg[4]/MLAMBDA; |
98 |
|
nratio = m->oargs.farg[3] / m->oargs.farg[7]; |
99 |
|
|
100 |
|
if (cos1 < 0.0) { /* inside */ |
101 |
+ |
hastexture = -hastexture; |
102 |
|
cos1 = -cos1; |
103 |
|
dnorm[0] = -dnorm[0]; |
104 |
|
dnorm[1] = -dnorm[1]; |
134 |
|
r->gecc = 0.; |
135 |
|
} |
136 |
|
} |
131 |
– |
/* estimate absorption */ |
132 |
– |
mabsorp = colval(r->cext,RED) < colval(r->cext,GRN) ? |
133 |
– |
colval(r->cext,RED) : colval(r->cext,GRN); |
134 |
– |
if (colval(r->cext,BLU) < mabsorp) mabsorp = colval(r->cext,BLU); |
135 |
– |
if (mabsorp > 0.) |
136 |
– |
mabsorp = exp(-mabsorp*r->rot); /* conservative */ |
137 |
– |
else |
138 |
– |
mabsorp = 1.0; |
137 |
|
|
138 |
|
d2 = 1.0 - nratio*nratio*(1.0 - cos1*cos1); /* compute cos theta2 */ |
139 |
|
|
157 |
|
refl *= 0.5; |
158 |
|
trans = 1.0 - refl; |
159 |
|
|
160 |
< |
if (rayorigin(&p, r, REFRACTED, mabsorp*trans) == 0) { |
160 |
> |
if (rayorigin(&p, r, REFRACTED, trans) == 0) { |
161 |
|
|
162 |
|
/* compute refracted ray */ |
163 |
|
d1 = nratio*cos1 - cos2; |
164 |
|
for (i = 0; i < 3; i++) |
165 |
|
p.rdir[i] = nratio*r->rdir[i] + d1*dnorm[i]; |
166 |
< |
|
166 |
> |
/* accidental reflection? */ |
167 |
> |
if (hastexture && |
168 |
> |
DOT(p.rdir,r->ron)*hastexture >= -FTINY) { |
169 |
> |
d1 *= (double)hastexture; |
170 |
> |
for (i = 0; i < 3; i++) /* ignore texture */ |
171 |
> |
p.rdir[i] = nratio*r->rdir[i] + |
172 |
> |
d1*r->ron[i]; |
173 |
> |
normalize(p.rdir); /* not exact */ |
174 |
> |
} |
175 |
|
#ifdef DISPERSE |
176 |
|
if (m->otype != MAT_DIELECTRIC |
177 |
|
|| r->rod > 0.0 |
194 |
|
} |
195 |
|
|
196 |
|
if (!(r->crtype & SHADOW) && |
197 |
< |
rayorigin(&p, r, REFLECTED, mabsorp*refl) == 0) { |
197 |
> |
rayorigin(&p, r, REFLECTED, refl) == 0) { |
198 |
|
|
199 |
|
/* compute reflected ray */ |
200 |
|
for (i = 0; i < 3; i++) |
201 |
|
p.rdir[i] = r->rdir[i] + 2.0*cos1*dnorm[i]; |
202 |
+ |
/* accidental penetration? */ |
203 |
+ |
if (hastexture && DOT(p.rdir,r->ron)*hastexture <= FTINY) |
204 |
+ |
for (i = 0; i < 3; i++) /* ignore texture */ |
205 |
+ |
p.rdir[i] = r->rdir[i] + 2.0*r->rod*r->ron[i]; |
206 |
|
|
207 |
|
rayvalue(&p); /* reflected ray value */ |
208 |
|
|