182 |
|
{ |
183 |
|
NORMDAT nd; |
184 |
|
double fest; |
185 |
– |
double transtest, transdist; |
186 |
– |
double mirtest, mirdist; |
185 |
|
int hastexture; |
186 |
|
double d; |
187 |
|
COLOR ctmp; |
188 |
|
int i; |
189 |
|
|
190 |
|
/* PMAP: skip transmitted shadow ray if accounted for in photon map */ |
191 |
< |
if (shadowRayInPmap(r)) |
192 |
< |
return(1); |
191 |
> |
/* No longer needed? |
192 |
> |
if (shadowRayInPmap(r) || ambRayInPmap(r)) |
193 |
> |
return(1); */ |
194 |
> |
|
195 |
|
/* easy shadow test */ |
196 |
|
if (r->crtype & SHADOW && m->otype != MAT_TRANS) |
197 |
|
return(1); |
231 |
|
if (nd.pdot < .001) |
232 |
|
nd.pdot = .001; /* non-zero for dirnorm() */ |
233 |
|
multcolor(nd.mcolor, r->pcol); /* modify material color */ |
234 |
– |
mirtest = transtest = 0; |
235 |
– |
mirdist = transdist = r->rot; |
234 |
|
nd.rspec = m->oargs.farg[3]; |
235 |
|
/* compute Fresnel approx. */ |
236 |
|
if (nd.specfl & SP_PURE && nd.rspec >= FRESTHRESH) { |
251 |
|
nd.specfl |= SP_TBLT; |
252 |
|
if (!hastexture || r->crtype & (SHADOW|AMBIENT)) { |
253 |
|
VCOPY(nd.prdir, r->rdir); |
256 |
– |
transtest = 2; |
254 |
|
} else { |
255 |
< |
for (i = 0; i < 3; i++) /* perturb */ |
256 |
< |
nd.prdir[i] = r->rdir[i] - r->pert[i]; |
255 |
> |
/* perturb */ |
256 |
> |
VSUB(nd.prdir, r->rdir, r->pert); |
257 |
|
if (DOT(nd.prdir, r->ron) < -FTINY) |
258 |
|
normalize(nd.prdir); /* OK */ |
259 |
|
else |
262 |
|
} |
263 |
|
} else |
264 |
|
nd.tdiff = nd.tspec = nd.trans = 0.0; |
265 |
+ |
/* diffuse reflection */ |
266 |
+ |
nd.rdiff = 1.0 - nd.trans - nd.rspec; |
267 |
|
/* transmitted ray */ |
269 |
– |
|
268 |
|
if ((nd.specfl&(SP_TRAN|SP_PURE|SP_TBLT)) == (SP_TRAN|SP_PURE)) { |
269 |
|
RAY lr; |
270 |
|
copycolor(lr.rcoef, nd.mcolor); /* modified by color */ |
274 |
|
rayvalue(&lr); |
275 |
|
multcolor(lr.rcol, lr.rcoef); |
276 |
|
addcolor(r->rcol, lr.rcol); |
277 |
< |
transtest *= bright(lr.rcol); |
278 |
< |
transdist = r->rot + lr.rt; |
277 |
> |
if (nd.tspec >= 1.0-FTINY) { |
278 |
> |
/* completely transparent */ |
279 |
> |
multcolor(lr.mcol, lr.rcoef); |
280 |
> |
copycolor(r->mcol, lr.mcol); |
281 |
> |
r->rmt = r->rot + lr.rmt; |
282 |
> |
r->rxt = r->rot + lr.rxt; |
283 |
> |
} else if (nd.tspec > nd.tdiff + nd.rdiff) |
284 |
> |
r->rxt = r->rot + raydistance(&lr); |
285 |
|
} |
286 |
< |
} else |
283 |
< |
transtest = 0; |
286 |
> |
} |
287 |
|
|
288 |
< |
if (r->crtype & SHADOW) { /* the rest is shadow */ |
286 |
< |
r->rt = transdist; |
288 |
> |
if (r->crtype & SHADOW) /* the rest is shadow */ |
289 |
|
return(1); |
288 |
– |
} |
290 |
|
/* get specular reflection */ |
291 |
|
if (nd.rspec > FTINY) { |
292 |
|
nd.specfl |= SP_REFL; |
319 |
|
VCOPY(lr.rdir, nd.vrefl); |
320 |
|
rayvalue(&lr); |
321 |
|
multcolor(lr.rcol, lr.rcoef); |
322 |
+ |
copycolor(r->mcol, lr.rcol); |
323 |
|
addcolor(r->rcol, lr.rcol); |
324 |
|
if (nd.specfl & SP_FLAT && |
325 |
< |
!hastexture | (r->crtype & AMBIENT)) { |
326 |
< |
mirtest = 2.*bright(lr.rcol); |
325 |
< |
mirdist = r->rot + lr.rt; |
326 |
< |
} |
325 |
> |
!hastexture | (r->crtype & AMBIENT)) |
326 |
> |
r->rmt = r->rot + raydistance(&lr); |
327 |
|
} |
328 |
|
} |
329 |
– |
/* diffuse reflection */ |
330 |
– |
nd.rdiff = 1.0 - nd.trans - nd.rspec; |
329 |
|
|
330 |
|
if (nd.specfl & SP_PURE && nd.rdiff <= FTINY && nd.tdiff <= FTINY) |
331 |
|
return(1); /* 100% pure specular */ |
361 |
|
} |
362 |
|
/* add direct component */ |
363 |
|
direct(r, dirnorm, &nd); |
366 |
– |
/* check distance */ |
367 |
– |
d = bright(r->rcol); |
368 |
– |
if (transtest > d) |
369 |
– |
r->rt = transdist; |
370 |
– |
else if (mirtest > d) |
371 |
– |
r->rt = mirdist; |
364 |
|
|
365 |
|
return(1); |
366 |
|
} |