209 |
|
int hitfront = 1; |
210 |
|
BRDFDAT nd; |
211 |
|
RAY sr; |
212 |
– |
double mirtest=0, mirdist=0; |
213 |
– |
double transtest, transdist; |
212 |
|
int hasrefl, hastrans; |
213 |
|
int hastexture; |
214 |
|
COLOR ctmp; |
259 |
|
multcolor(nd.tdiff, nd.mcolor); |
260 |
|
hasrefl = (bright(nd.rdiff) > FTINY); |
261 |
|
hastrans = (bright(nd.tdiff) > FTINY); |
264 |
– |
mirdist = transdist = r->rot; |
262 |
|
/* load cal file */ |
263 |
|
nd.dp = NULL; |
264 |
|
mf = getfunc(m, 9, 0x3f, 0); |
284 |
|
rayvalue(&sr); |
285 |
|
multcolor(sr.rcol, sr.rcoef); |
286 |
|
addcolor(r->rcol, sr.rcol); |
287 |
< |
if (!hastexture || r->crtype & (SHADOW|AMBIENT)) { |
288 |
< |
transtest = 2.0*bright(sr.rcol); |
292 |
< |
transdist = r->rot + sr.rt; |
293 |
< |
} |
287 |
> |
if (!hastexture || r->crtype & (SHADOW|AMBIENT)) |
288 |
> |
r->rxt = r->rot + raydistance(&sr); |
289 |
|
} |
290 |
< |
if (r->crtype & SHADOW) { /* the rest is shadow */ |
296 |
< |
r->rt = transdist; |
290 |
> |
if (r->crtype & SHADOW) /* the rest is shadow */ |
291 |
|
return(1); |
292 |
< |
} |
292 |
> |
|
293 |
|
/* compute reflected ray */ |
294 |
|
setbrdfunc(&nd); |
295 |
|
errno = 0; |
303 |
|
checknorm(sr.rdir); |
304 |
|
rayvalue(&sr); |
305 |
|
multcolor(sr.rcol, sr.rcoef); |
306 |
+ |
copycolor(r->mcol, sr.rcol); |
307 |
|
addcolor(r->rcol, sr.rcol); |
308 |
< |
if (!hastexture && r->ro != NULL && isflat(r->ro->otype)) { |
309 |
< |
mirtest = 2.0*bright(sr.rcol); |
310 |
< |
mirdist = r->rot + sr.rt; |
316 |
< |
} |
308 |
> |
if (r->ro != NULL && isflat(r->ro->otype) && |
309 |
> |
!hastexture | (r->crtype & AMBIENT)) |
310 |
> |
r->rmt = r->rot + raydistance(&sr); |
311 |
|
} |
312 |
|
/* compute ambient */ |
313 |
|
if (hasrefl) { |
334 |
|
if (hasrefl | hastrans || m->oargs.sarg[6][0] != '0') |
335 |
|
direct(r, dirbrdf, &nd); /* add direct component */ |
336 |
|
|
343 |
– |
d = bright(r->rcol); /* set effective distance */ |
344 |
– |
if (transtest > d) |
345 |
– |
r->rt = transdist; |
346 |
– |
else if (mirtest > d) |
347 |
– |
r->rt = mirdist; |
348 |
– |
|
337 |
|
return(1); |
338 |
|
} |
339 |
|
|
407 |
|
multambient(ctmp, r, nd.pnorm); |
408 |
|
addcolor(r->rcol, ctmp); /* add to returned color */ |
409 |
|
} |
410 |
< |
if (nd.trans > FTINY) { /* from other side */ |
410 |
> |
if (nd.trans > FTINY) { /* from other side */ |
411 |
|
flipsurface(r); |
412 |
|
vtmp[0] = -nd.pnorm[0]; |
413 |
|
vtmp[1] = -nd.pnorm[1]; |
436 |
|
return(0); /* it's OK, setfunc says we're done */ |
437 |
|
/* else (re)assign special variables */ |
438 |
|
multv3(vec, np->pnorm, funcxf.xfm); |
439 |
< |
varset("NxP", '=', vec[0]/funcxf.sca); |
440 |
< |
varset("NyP", '=', vec[1]/funcxf.sca); |
441 |
< |
varset("NzP", '=', vec[2]/funcxf.sca); |
442 |
< |
varset("RdotP", '=', np->pdot <= -1.0 ? -1.0 : |
439 |
> |
varset("NxP`", '=', vec[0]/funcxf.sca); |
440 |
> |
varset("NyP`", '=', vec[1]/funcxf.sca); |
441 |
> |
varset("NzP`", '=', vec[2]/funcxf.sca); |
442 |
> |
varset("RdotP`", '=', np->pdot <= -1.0 ? -1.0 : |
443 |
|
np->pdot >= 1.0 ? 1.0 : np->pdot); |
444 |
|
varset("CrP", '=', colval(np->mcolor,RED)); |
445 |
|
varset("CgP", '=', colval(np->mcolor,GRN)); |