129 |
|
addcolor(cval, ctmp); |
130 |
|
} |
131 |
|
if (ldot > 0.0 ? np->rspec <= FTINY : np->tspec <= FTINY) |
132 |
< |
return; /* no specular component */ |
132 |
> |
return; /* diffuse only */ |
133 |
|
/* set up function */ |
134 |
|
setbrdfunc(np); |
135 |
|
sa = np->mp->oargs.sarg; |
145 |
|
colval(ctmp,RED) = 0.0; |
146 |
|
else |
147 |
|
colval(ctmp,RED) = funvalue(sa[6], 4, lddx); |
148 |
< |
if (!strcmp(sa[7],sa[6])) |
148 |
> |
if (sa[7][0] == '0') |
149 |
> |
colval(ctmp,GRN) = 0.0; |
150 |
> |
else if (!strcmp(sa[7],sa[6])) |
151 |
|
colval(ctmp,GRN) = colval(ctmp,RED); |
152 |
|
else |
153 |
|
colval(ctmp,GRN) = funvalue(sa[7], 4, lddx); |
168 |
|
dtmp = funvalue(sa[0], 5, vldx); |
169 |
|
setcolor(ctmp, dtmp, dtmp, dtmp); |
170 |
|
} |
171 |
< |
if (errno == EDOM || errno == ERANGE) { |
171 |
> |
if ((errno == EDOM) | (errno == ERANGE)) { |
172 |
|
objerror(np->mp, WARNING, "compute error"); |
173 |
|
return; |
174 |
|
} |
206 |
|
int hitfront = 1; |
207 |
|
BRDFDAT nd; |
208 |
|
RAY sr; |
209 |
+ |
double mirtest=0, mirdist=0; |
210 |
|
double transtest, transdist; |
211 |
|
int hasrefl, hastrans; |
212 |
+ |
int hastexture; |
213 |
|
COLOR ctmp; |
214 |
|
FVECT vtmp; |
215 |
+ |
double d; |
216 |
|
register MFUNC *mf; |
217 |
|
register int i; |
218 |
|
/* check arguments */ |
238 |
|
m->oargs.farg[8]); |
239 |
|
/* get modifiers */ |
240 |
|
raytexture(r, m->omod); |
241 |
< |
nd.pdot = raynormal(nd.pnorm, r); /* perturb normal */ |
241 |
> |
hastexture = DOT(r->pert,r->pert) > FTINY*FTINY; |
242 |
> |
if (hastexture) { /* perturb normal */ |
243 |
> |
nd.pdot = raynormal(nd.pnorm, r); |
244 |
> |
} else { |
245 |
> |
VCOPY(nd.pnorm, r->ron); |
246 |
> |
nd.pdot = r->rod; |
247 |
> |
} |
248 |
|
if (r->rod < 0.0) { /* orient perturbed values */ |
249 |
|
nd.pdot = -nd.pdot; |
250 |
|
for (i = 0; i < 3; i++) { |
263 |
|
mf = getfunc(m, 9, 0x3f, 0); |
264 |
|
/* compute transmitted ray */ |
265 |
|
setbrdfunc(&nd); |
255 |
– |
transtest = 0; |
256 |
– |
transdist = r->rot; |
266 |
|
errno = 0; |
267 |
|
setcolor(ctmp, evalue(mf->ep[3]), |
268 |
|
evalue(mf->ep[4]), |
269 |
|
evalue(mf->ep[5])); |
270 |
< |
if (errno == EDOM || errno == ERANGE) |
270 |
> |
if ((errno == EDOM) | (errno == ERANGE)) |
271 |
|
objerror(m, WARNING, "compute error"); |
272 |
< |
else if (rayorigin(&sr, r, TRANS, bright(ctmp)) == 0) { |
273 |
< |
if (!(r->crtype & SHADOW) && |
265 |
< |
DOT(r->pert,r->pert) > FTINY*FTINY) { |
272 |
> |
else if (rayorigin(&sr, TRANS, r, ctmp) == 0) { |
273 |
> |
if (!(r->crtype & SHADOW) && hastexture) { |
274 |
|
for (i = 0; i < 3; i++) /* perturb direction */ |
275 |
|
sr.rdir[i] = r->rdir[i] - .75*r->pert[i]; |
276 |
|
if (normalize(sr.rdir) == 0.0) { |
279 |
|
} |
280 |
|
} else { |
281 |
|
VCOPY(sr.rdir, r->rdir); |
274 |
– |
transtest = 2; |
282 |
|
} |
283 |
|
rayvalue(&sr); |
284 |
< |
multcolor(sr.rcol, ctmp); |
284 |
> |
multcolor(sr.rcol, sr.rcoef); |
285 |
|
addcolor(r->rcol, sr.rcol); |
286 |
< |
transtest *= bright(sr.rcol); |
287 |
< |
transdist = r->rot + sr.rt; |
286 |
> |
if (!hastexture) { |
287 |
> |
transtest = 2.0*bright(sr.rcol); |
288 |
> |
transdist = r->rot + sr.rt; |
289 |
> |
} |
290 |
|
} |
291 |
|
if (r->crtype & SHADOW) /* the rest is shadow */ |
292 |
|
return(1); |
296 |
|
setcolor(ctmp, evalue(mf->ep[0]), |
297 |
|
evalue(mf->ep[1]), |
298 |
|
evalue(mf->ep[2])); |
299 |
< |
if (errno == EDOM || errno == ERANGE) |
299 |
> |
if ((errno == EDOM) | (errno == ERANGE)) |
300 |
|
objerror(m, WARNING, "compute error"); |
301 |
< |
else if (rayorigin(&sr, r, REFLECTED, bright(ctmp)) == 0) { |
301 |
> |
else if (rayorigin(&sr, REFLECTED, r, ctmp) == 0) { |
302 |
|
for (i = 0; i < 3; i++) |
303 |
|
sr.rdir[i] = r->rdir[i] + 2.0*nd.pdot*nd.pnorm[i]; |
304 |
+ |
checknorm(sr.rdir); |
305 |
|
rayvalue(&sr); |
306 |
< |
multcolor(sr.rcol, ctmp); |
306 |
> |
multcolor(sr.rcol, sr.rcoef); |
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; |
311 |
+ |
} |
312 |
|
} |
313 |
|
/* compute ambient */ |
314 |
|
if (hasrefl) { |
315 |
|
if (!hitfront) |
316 |
|
flipsurface(r); |
317 |
< |
ambient(ctmp, r, nd.pnorm); |
318 |
< |
multcolor(ctmp, nd.rdiff); |
317 |
> |
copycolor(ctmp, nd.rdiff); |
318 |
> |
multambient(ctmp, r, nd.pnorm); |
319 |
|
addcolor(r->rcol, ctmp); /* add to returned color */ |
320 |
|
if (!hitfront) |
321 |
|
flipsurface(r); |
326 |
|
vtmp[0] = -nd.pnorm[0]; |
327 |
|
vtmp[1] = -nd.pnorm[1]; |
328 |
|
vtmp[2] = -nd.pnorm[2]; |
329 |
< |
ambient(ctmp, r, vtmp); |
330 |
< |
multcolor(ctmp, nd.tdiff); |
329 |
> |
copycolor(ctmp, nd.tdiff); |
330 |
> |
multambient(ctmp, r, vtmp); |
331 |
|
addcolor(r->rcol, ctmp); |
332 |
|
if (hitfront) |
333 |
|
flipsurface(r); |
334 |
|
} |
335 |
|
if (hasrefl | hastrans || m->oargs.sarg[6][0] != '0') |
336 |
|
direct(r, dirbrdf, &nd); /* add direct component */ |
337 |
< |
/* check distance */ |
338 |
< |
if (transtest > bright(r->rcol)) |
337 |
> |
|
338 |
> |
d = bright(r->rcol); /* set effective distance */ |
339 |
> |
if (transtest > d) |
340 |
|
r->rt = transdist; |
341 |
+ |
else if (mirtest > d) |
342 |
+ |
r->rt = mirdist; |
343 |
|
|
344 |
|
return(1); |
345 |
|
} |
410 |
|
} |
411 |
|
/* compute ambient */ |
412 |
|
if (nd.trans < 1.0-FTINY) { |
413 |
< |
ambient(ctmp, r, nd.pnorm); |
413 |
> |
copycolor(ctmp, nd.mcolor); /* modified by material color */ |
414 |
|
scalecolor(ctmp, 1.0-nd.trans); |
415 |
< |
multcolor(ctmp, nd.mcolor); /* modified by material color */ |
415 |
> |
multambient(ctmp, r, nd.pnorm); |
416 |
|
addcolor(r->rcol, ctmp); /* add to returned color */ |
417 |
|
} |
418 |
|
if (nd.trans > FTINY) { /* from other side */ |
420 |
|
vtmp[0] = -nd.pnorm[0]; |
421 |
|
vtmp[1] = -nd.pnorm[1]; |
422 |
|
vtmp[2] = -nd.pnorm[2]; |
423 |
< |
ambient(ctmp, r, vtmp); |
423 |
> |
copycolor(ctmp, nd.mcolor); |
424 |
|
scalecolor(ctmp, nd.trans); |
425 |
< |
multcolor(ctmp, nd.mcolor); |
425 |
> |
multambient(ctmp, r, vtmp); |
426 |
|
addcolor(r->rcol, ctmp); |
427 |
|
flipsurface(r); |
428 |
|
} |