182 |
|
{ |
183 |
|
NORMDAT nd; |
184 |
|
double fest; |
185 |
– |
double transtest, transdist; |
186 |
– |
double mirtest, mirdist; |
185 |
|
int hastexture; |
186 |
|
double d; |
187 |
|
COLOR ctmp; |
231 |
|
if (nd.pdot < .001) |
232 |
|
nd.pdot = .001; /* non-zero for dirnorm() */ |
233 |
|
multcolor(nd.mcolor, r->pcol); /* modify material color */ |
236 |
– |
mirtest = transtest = 0; |
237 |
– |
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); |
258 |
– |
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 |
273 |
|
rayvalue(&lr); |
274 |
|
multcolor(lr.rcol, lr.rcoef); |
275 |
|
addcolor(r->rcol, lr.rcol); |
276 |
< |
transtest *= bright(lr.rcol); |
277 |
< |
transdist = r->rot + lr.rt; |
276 |
> |
if (nd.tspec >= 1.0-FTINY) { |
277 |
> |
/* completely transparent */ |
278 |
> |
multcolor(lr.mcol, lr.rcoef); |
279 |
> |
copycolor(r->mcol, lr.mcol); |
280 |
> |
r->rmt = r->rot + lr.rmt; |
281 |
> |
r->rxt = r->rot + lr.rxt; |
282 |
> |
} else |
283 |
> |
r->rxt = r->rot + raydistance(&lr); |
284 |
|
} |
285 |
< |
} else |
285 |
< |
transtest = 0; |
285 |
> |
} |
286 |
|
|
287 |
< |
if (r->crtype & SHADOW) { /* the rest is shadow */ |
288 |
< |
r->rt = transdist; |
287 |
> |
if (r->crtype & SHADOW) /* the rest is shadow */ |
288 |
|
return(1); |
290 |
– |
} |
289 |
|
/* get specular reflection */ |
290 |
|
if (nd.rspec > FTINY) { |
291 |
|
nd.specfl |= SP_REFL; |
318 |
|
VCOPY(lr.rdir, nd.vrefl); |
319 |
|
rayvalue(&lr); |
320 |
|
multcolor(lr.rcol, lr.rcoef); |
321 |
+ |
copycolor(r->mcol, lr.rcol); |
322 |
|
addcolor(r->rcol, lr.rcol); |
323 |
|
if (nd.specfl & SP_FLAT && |
324 |
< |
!hastexture | (r->crtype & AMBIENT)) { |
325 |
< |
mirtest = 2.*bright(lr.rcol); |
327 |
< |
mirdist = r->rot + lr.rt; |
328 |
< |
} |
324 |
> |
!hastexture | (r->crtype & AMBIENT)) |
325 |
> |
r->rmt = r->rot + raydistance(&lr); |
326 |
|
} |
327 |
|
} |
328 |
|
/* diffuse reflection */ |
329 |
|
nd.rdiff = 1.0 - nd.trans - nd.rspec; |
330 |
|
|
331 |
< |
if (nd.specfl & SP_PURE && nd.rdiff <= FTINY && nd.tdiff <= FTINY) { |
335 |
< |
if (mirtest > transtest+FTINY) |
336 |
< |
r->rt = mirdist; |
337 |
< |
else if (transtest > FTINY) |
338 |
< |
r->rt = transdist; |
331 |
> |
if (nd.specfl & SP_PURE && nd.rdiff <= FTINY && nd.tdiff <= FTINY) |
332 |
|
return(1); /* 100% pure specular */ |
333 |
< |
} |
333 |
> |
|
334 |
|
if (!(nd.specfl & SP_PURE)) |
335 |
|
gaussamp(&nd); /* checks *BLT flags */ |
336 |
|
|
362 |
|
} |
363 |
|
/* add direct component */ |
364 |
|
direct(r, dirnorm, &nd); |
372 |
– |
/* check distance */ |
373 |
– |
d = bright(r->rcol); |
374 |
– |
if (transtest > d) |
375 |
– |
r->rt = transdist; |
376 |
– |
else if (mirtest > d) |
377 |
– |
r->rt = mirdist; |
365 |
|
|
366 |
|
return(1); |
367 |
|
} |