19 |
|
#include "otypes.h" |
20 |
|
#include "rtotypes.h" |
21 |
|
#include "random.h" |
22 |
+ |
#include "pmapmat.h" |
23 |
|
|
24 |
|
#ifndef MAXITER |
25 |
|
#define MAXITER 10 /* maximum # specular ray attempts */ |
66 |
|
double pdot; /* perturbed dot product */ |
67 |
|
} NORMDAT; /* normal material data */ |
68 |
|
|
69 |
< |
static void gaussamp(RAY *r, NORMDAT *np); |
69 |
> |
static void gaussamp(NORMDAT *np); |
70 |
|
|
71 |
|
|
72 |
|
static void |
112 |
|
scalecolor(ctmp, dtmp); |
113 |
|
addcolor(cval, ctmp); |
114 |
|
} |
115 |
+ |
|
116 |
+ |
if (ldot < -FTINY && ltdiff > FTINY) { |
117 |
+ |
/* |
118 |
+ |
* Compute diffuse transmission. |
119 |
+ |
*/ |
120 |
+ |
copycolor(ctmp, np->mcolor); |
121 |
+ |
dtmp = -ldot * omega * ltdiff * (1.0/PI); |
122 |
+ |
scalecolor(ctmp, dtmp); |
123 |
+ |
addcolor(cval, ctmp); |
124 |
+ |
} |
125 |
+ |
|
126 |
+ |
if (ambRayInPmap(np->rp)) |
127 |
+ |
return; /* specular already in photon map */ |
128 |
+ |
|
129 |
|
if (ldot > FTINY && (np->specfl&(SP_REFL|SP_PURE)) == SP_REFL) { |
130 |
|
/* |
131 |
|
* Compute specular reflection coefficient using |
152 |
|
addcolor(cval, ctmp); |
153 |
|
} |
154 |
|
} |
155 |
< |
if (ldot < -FTINY && ltdiff > FTINY) { |
156 |
< |
/* |
142 |
< |
* Compute diffuse transmission. |
143 |
< |
*/ |
144 |
< |
copycolor(ctmp, np->mcolor); |
145 |
< |
dtmp = -ldot * omega * ltdiff * (1.0/PI); |
146 |
< |
scalecolor(ctmp, dtmp); |
147 |
< |
addcolor(cval, ctmp); |
148 |
< |
} |
155 |
> |
|
156 |
> |
|
157 |
|
if (ldot < -FTINY && (np->specfl&(SP_TRAN|SP_PURE)) == SP_TRAN) { |
158 |
|
/* |
159 |
|
* Compute specular transmission. Specular transmission |
188 |
|
double d; |
189 |
|
COLOR ctmp; |
190 |
|
int i; |
191 |
+ |
|
192 |
+ |
/* PMAP: skip transmitted shadow ray if accounted for in photon map */ |
193 |
+ |
/* No longer needed? |
194 |
+ |
if (shadowRayInPmap(r) || ambRayInPmap(r)) |
195 |
+ |
return(1); */ |
196 |
+ |
|
197 |
|
/* easy shadow test */ |
198 |
|
if (r->crtype & SHADOW && m->otype != MAT_TRANS) |
199 |
|
return(1); |
202 |
|
objerror(m, USER, "bad number of arguments"); |
203 |
|
/* check for back side */ |
204 |
|
if (r->rod < 0.0) { |
205 |
< |
if (!backvis && m->otype != MAT_TRANS) { |
205 |
> |
if (!backvis) { |
206 |
|
raytrans(r); |
207 |
|
return(1); |
208 |
|
} |
253 |
|
if (!(nd.specfl & SP_PURE) && |
254 |
|
specthresh >= nd.tspec-FTINY) |
255 |
|
nd.specfl |= SP_TBLT; |
256 |
< |
if (!hastexture || r->crtype & SHADOW) { |
256 |
> |
if (!hastexture || r->crtype & (SHADOW|AMBIENT)) { |
257 |
|
VCOPY(nd.prdir, r->rdir); |
258 |
|
transtest = 2; |
259 |
|
} else { |
260 |
< |
for (i = 0; i < 3; i++) /* perturb */ |
261 |
< |
nd.prdir[i] = r->rdir[i] - r->pert[i]; |
260 |
> |
/* perturb */ |
261 |
> |
VSUB(nd.prdir, r->rdir, r->pert); |
262 |
|
if (DOT(nd.prdir, r->ron) < -FTINY) |
263 |
|
normalize(nd.prdir); /* OK */ |
264 |
|
else |
268 |
|
} else |
269 |
|
nd.tdiff = nd.tspec = nd.trans = 0.0; |
270 |
|
/* transmitted ray */ |
271 |
+ |
|
272 |
|
if ((nd.specfl&(SP_TRAN|SP_PURE|SP_TBLT)) == (SP_TRAN|SP_PURE)) { |
273 |
|
RAY lr; |
274 |
|
copycolor(lr.rcoef, nd.mcolor); /* modified by color */ |
295 |
|
if (m->otype != MAT_METAL) { |
296 |
|
setcolor(nd.scolor, nd.rspec, nd.rspec, nd.rspec); |
297 |
|
} else if (fest > FTINY) { |
298 |
< |
d = nd.rspec*(1. - fest); |
298 |
> |
d = m->oargs.farg[3]*(1. - fest); |
299 |
|
for (i = 0; i < 3; i++) |
300 |
< |
nd.scolor[i] = fest + nd.mcolor[i]*d; |
300 |
> |
colval(nd.scolor,i) = fest + |
301 |
> |
colval(nd.mcolor,i)*d; |
302 |
|
} else { |
303 |
|
copycolor(nd.scolor, nd.mcolor); |
304 |
|
scalecolor(nd.scolor, nd.rspec); |
321 |
|
rayvalue(&lr); |
322 |
|
multcolor(lr.rcol, lr.rcoef); |
323 |
|
addcolor(r->rcol, lr.rcol); |
324 |
< |
if (!hastexture && nd.specfl & SP_FLAT) { |
324 |
> |
if (nd.specfl & SP_FLAT && |
325 |
> |
!hastexture | (r->crtype & AMBIENT)) { |
326 |
|
mirtest = 2.*bright(lr.rcol); |
327 |
|
mirdist = r->rot + lr.rt; |
328 |
|
} |
331 |
|
/* diffuse reflection */ |
332 |
|
nd.rdiff = 1.0 - nd.trans - nd.rspec; |
333 |
|
|
334 |
< |
if (nd.specfl & SP_PURE && nd.rdiff <= FTINY && nd.tdiff <= FTINY) |
334 |
> |
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; |
339 |
|
return(1); /* 100% pure specular */ |
340 |
< |
|
340 |
> |
} |
341 |
|
if (!(nd.specfl & SP_PURE)) |
342 |
< |
gaussamp(r, &nd); /* checks *BLT flags */ |
342 |
> |
gaussamp(&nd); /* checks *BLT flags */ |
343 |
|
|
344 |
|
if (nd.rdiff > FTINY) { /* ambient from this side */ |
345 |
|
copycolor(ctmp, nd.mcolor); /* modified by material color */ |
382 |
|
|
383 |
|
static void |
384 |
|
gaussamp( /* sample Gaussian specular */ |
364 |
– |
RAY *r, |
385 |
|
NORMDAT *np |
386 |
|
) |
387 |
|
{ |
397 |
|
(np->specfl & (SP_TRAN|SP_TBLT)) != SP_TRAN) |
398 |
|
return; |
399 |
|
/* set up sample coordinates */ |
400 |
< |
v[0] = v[1] = v[2] = 0.0; |
381 |
< |
for (i = 0; i < 3; i++) |
382 |
< |
if (np->pnorm[i] < 0.6 && np->pnorm[i] > -0.6) |
383 |
< |
break; |
384 |
< |
v[i] = 1.0; |
385 |
< |
fcross(u, v, np->pnorm); |
386 |
< |
normalize(u); |
400 |
> |
getperpendicular(u, np->pnorm, rand_samp); |
401 |
|
fcross(v, np->pnorm, u); |
402 |
|
/* compute reflection */ |
403 |
|
if ((np->specfl & (SP_REFL|SP_RBLT)) == SP_REFL && |
404 |
< |
rayorigin(&sr, SPECULAR, r, np->scolor) == 0) { |
404 |
> |
rayorigin(&sr, SPECULAR, np->rp, np->scolor) == 0) { |
405 |
|
nstarget = 1; |
406 |
|
if (specjitter > 1.5) { /* multiple samples? */ |
407 |
< |
nstarget = specjitter*r->rweight + .5; |
407 |
> |
nstarget = specjitter*np->rp->rweight + .5; |
408 |
|
if (sr.rweight <= minweight*nstarget) |
409 |
|
nstarget = sr.rweight/minweight; |
410 |
|
if (nstarget > 1) { |
435 |
|
d = sqrt( np->alpha2 * -log(rv[1]) ); |
436 |
|
for (i = 0; i < 3; i++) |
437 |
|
h[i] = np->pnorm[i] + d*(cosp*u[i] + sinp*v[i]); |
438 |
< |
d = -2.0 * DOT(h, r->rdir) / (1.0 + d*d); |
439 |
< |
VSUM(sr.rdir, r->rdir, h, d); |
438 |
> |
d = -2.0 * DOT(h, np->rp->rdir) / (1.0 + d*d); |
439 |
> |
VSUM(sr.rdir, np->rp->rdir, h, d); |
440 |
|
/* sample rejection test */ |
441 |
< |
if ((d = DOT(sr.rdir, r->ron)) <= FTINY) |
441 |
> |
if ((d = DOT(sr.rdir, np->rp->ron)) <= FTINY) |
442 |
|
continue; |
443 |
|
checknorm(sr.rdir); |
444 |
|
if (nstarget > 1) { /* W-G-M-D adjustment */ |
445 |
|
if (nstaken) rayclear(&sr); |
446 |
|
rayvalue(&sr); |
447 |
< |
d = 2./(1. + r->rod/d); |
447 |
> |
d = 2./(1. + np->rp->rod/d); |
448 |
|
scalecolor(sr.rcol, d); |
449 |
|
addcolor(scol, sr.rcol); |
450 |
|
} else { |
451 |
|
rayvalue(&sr); |
452 |
|
multcolor(sr.rcol, sr.rcoef); |
453 |
< |
addcolor(r->rcol, sr.rcol); |
453 |
> |
addcolor(np->rp->rcol, sr.rcol); |
454 |
|
} |
455 |
|
++nstaken; |
456 |
|
} |
458 |
|
multcolor(scol, sr.rcoef); |
459 |
|
d = (double)nstarget/ntrials; |
460 |
|
scalecolor(scol, d); |
461 |
< |
addcolor(r->rcol, scol); |
461 |
> |
addcolor(np->rp->rcol, scol); |
462 |
|
} |
463 |
|
ndims--; |
464 |
|
} |
466 |
|
copycolor(sr.rcoef, np->mcolor); /* modified by color */ |
467 |
|
scalecolor(sr.rcoef, np->tspec); |
468 |
|
if ((np->specfl & (SP_TRAN|SP_TBLT)) == SP_TRAN && |
469 |
< |
rayorigin(&sr, SPECULAR, r, sr.rcoef) == 0) { |
469 |
> |
rayorigin(&sr, SPECULAR, np->rp, sr.rcoef) == 0) { |
470 |
|
nstarget = 1; |
471 |
|
if (specjitter > 1.5) { /* multiple samples? */ |
472 |
< |
nstarget = specjitter*r->rweight + .5; |
472 |
> |
nstarget = specjitter*np->rp->rweight + .5; |
473 |
|
if (sr.rweight <= minweight*nstarget) |
474 |
|
nstarget = sr.rweight/minweight; |
475 |
|
if (nstarget > 1) { |
500 |
|
for (i = 0; i < 3; i++) |
501 |
|
sr.rdir[i] = np->prdir[i] + d*(cosp*u[i] + sinp*v[i]); |
502 |
|
/* sample rejection test */ |
503 |
< |
if (DOT(sr.rdir, r->ron) >= -FTINY) |
503 |
> |
if (DOT(sr.rdir, np->rp->ron) >= -FTINY) |
504 |
|
continue; |
505 |
|
normalize(sr.rdir); /* OK, normalize */ |
506 |
|
if (nstaken) /* multi-sampling */ |
507 |
|
rayclear(&sr); |
508 |
|
rayvalue(&sr); |
509 |
|
multcolor(sr.rcol, sr.rcoef); |
510 |
< |
addcolor(r->rcol, sr.rcol); |
510 |
> |
addcolor(np->rp->rcol, sr.rcol); |
511 |
|
++nstaken; |
512 |
|
} |
513 |
|
ndims--; |