277 |
|
|
278 |
|
if (nd.rdiff > FTINY) { /* ambient from this side */ |
279 |
|
copycolor(ctmp, nd.mcolor); /* modified by material color */ |
280 |
< |
if (nd.specfl & SP_RBLT) |
281 |
< |
scalecolor(ctmp, 1.0-nd.trans); |
282 |
< |
else |
283 |
< |
scalecolor(ctmp, nd.rdiff); |
280 |
> |
scalecolor(ctmp, nd.rdiff); |
281 |
> |
if (nd.specfl & SP_RBLT) /* add in specular as well? */ |
282 |
> |
addcolor(ctmp, nd.scolor); |
283 |
|
multambient(ctmp, r, nd.pnorm); |
284 |
|
addcolor(r->rcol, ctmp); /* add to returned color */ |
285 |
|
} |
325 |
|
np->specfl |= SP_BADU; |
326 |
|
return; |
327 |
|
} |
328 |
< |
if (mf->f != &unitxf) |
329 |
< |
multv3(np->u, np->u, mf->f->xfm); |
328 |
> |
if (mf->fxp != &unitxf) |
329 |
> |
multv3(np->u, np->u, mf->fxp->xfm); |
330 |
|
fcross(np->v, np->pnorm, np->u); |
331 |
|
if (normalize(np->v) == 0.0) { |
332 |
|
objerror(np->mp, WARNING, "illegal orientation vector"); |
348 |
|
double rv[2]; |
349 |
|
double d, sinp, cosp; |
350 |
|
COLOR scol; |
351 |
< |
int niter, ns2go; |
351 |
> |
int maxiter, ntrials, nstarget, nstaken; |
352 |
|
register int i; |
353 |
|
/* compute reflection */ |
354 |
|
if ((np->specfl & (SP_REFL|SP_RBLT)) == SP_REFL && |
355 |
|
rayorigin(&sr, SPECULAR, r, np->scolor) == 0) { |
356 |
< |
copycolor(scol, np->scolor); |
358 |
< |
ns2go = 1; |
356 |
> |
nstarget = 1; |
357 |
|
if (specjitter > 1.5) { /* multiple samples? */ |
358 |
< |
ns2go = specjitter*r->rweight + .5; |
359 |
< |
if (sr.rweight <= minweight*ns2go) |
360 |
< |
ns2go = sr.rweight/minweight; |
361 |
< |
if (ns2go > 1) { |
362 |
< |
d = 1./ns2go; |
363 |
< |
scalecolor(scol, d); |
358 |
> |
nstarget = specjitter*r->rweight + .5; |
359 |
> |
if (sr.rweight <= minweight*nstarget) |
360 |
> |
nstarget = sr.rweight/minweight; |
361 |
> |
if (nstarget > 1) { |
362 |
> |
d = 1./nstarget; |
363 |
> |
scalecolor(sr.rcoef, d); |
364 |
|
sr.rweight *= d; |
365 |
|
} else |
366 |
< |
ns2go = 1; |
366 |
> |
nstarget = 1; |
367 |
|
} |
368 |
< |
dimlist[ndims++] = (int)np->mp; |
369 |
< |
for (niter = ns2go*MAXITER; (ns2go > 0) & (niter > 0); niter--) { |
370 |
< |
if (specjitter > 1.5) |
368 |
> |
setcolor(scol, 0., 0., 0.); |
369 |
> |
dimlist[ndims++] = (int)(size_t)np->mp; |
370 |
> |
maxiter = MAXITER*nstarget; |
371 |
> |
for (nstaken = ntrials = 0; nstaken < nstarget && |
372 |
> |
ntrials < maxiter; ntrials++) { |
373 |
> |
if (ntrials) |
374 |
|
d = frandom(); |
375 |
|
else |
376 |
|
d = urand(ilhash(dimlist,ndims)+samplendx); |
393 |
|
h[i] = np->pnorm[i] + |
394 |
|
d*(cosp*np->u[i] + sinp*np->v[i]); |
395 |
|
d = -2.0 * DOT(h, r->rdir) / (1.0 + d*d); |
395 |
– |
if (d <= np->pdot + FTINY) |
396 |
– |
continue; |
396 |
|
VSUM(sr.rdir, r->rdir, h, d); |
397 |
< |
if (DOT(sr.rdir, r->ron) <= FTINY) |
397 |
> |
/* sample rejection test */ |
398 |
> |
if ((d = DOT(sr.rdir, r->ron)) <= FTINY) |
399 |
|
continue; |
400 |
|
checknorm(sr.rdir); |
401 |
< |
if (specjitter > 1.5) { /* adjusted W-G-M-D weight */ |
402 |
< |
d = 2.*(1. - np->pdot/d); |
403 |
< |
copycolor(sr.rcoef, scol); |
404 |
< |
scalecolor(sr.rcoef, d); |
405 |
< |
rayclear(&sr); |
401 |
> |
if (nstarget > 1) { /* W-G-M-D adjustment */ |
402 |
> |
if (nstaken) rayclear(&sr); |
403 |
> |
rayvalue(&sr); |
404 |
> |
d = 2./(1. + r->rod/d); |
405 |
> |
scalecolor(sr.rcol, d); |
406 |
> |
addcolor(scol, sr.rcol); |
407 |
> |
} else { |
408 |
> |
rayvalue(&sr); |
409 |
> |
multcolor(sr.rcol, sr.rcoef); |
410 |
> |
addcolor(r->rcol, sr.rcol); |
411 |
|
} |
412 |
< |
rayvalue(&sr); |
408 |
< |
multcolor(sr.rcol, sr.rcoef); |
409 |
< |
addcolor(r->rcol, sr.rcol); |
410 |
< |
--ns2go; |
412 |
> |
++nstaken; |
413 |
|
} |
414 |
+ |
if (nstarget > 1) { /* final W-G-M-D weighting */ |
415 |
+ |
multcolor(scol, sr.rcoef); |
416 |
+ |
d = (double)nstarget/ntrials; |
417 |
+ |
scalecolor(scol, d); |
418 |
+ |
addcolor(r->rcol, scol); |
419 |
+ |
} |
420 |
|
ndims--; |
421 |
|
} |
422 |
|
/* compute transmission */ |
424 |
|
scalecolor(sr.rcoef, np->tspec); |
425 |
|
if ((np->specfl & (SP_TRAN|SP_TBLT)) == SP_TRAN && |
426 |
|
rayorigin(&sr, SPECULAR, r, sr.rcoef) == 0) { |
427 |
< |
ns2go = 1; |
427 |
> |
nstarget = 1; |
428 |
|
if (specjitter > 1.5) { /* multiple samples? */ |
429 |
< |
ns2go = specjitter*r->rweight + .5; |
430 |
< |
if (sr.rweight <= minweight*ns2go) |
431 |
< |
ns2go = sr.rweight/minweight; |
432 |
< |
if (ns2go > 1) { |
433 |
< |
d = 1./ns2go; |
429 |
> |
nstarget = specjitter*r->rweight + .5; |
430 |
> |
if (sr.rweight <= minweight*nstarget) |
431 |
> |
nstarget = sr.rweight/minweight; |
432 |
> |
if (nstarget > 1) { |
433 |
> |
d = 1./nstarget; |
434 |
|
scalecolor(sr.rcoef, d); |
435 |
|
sr.rweight *= d; |
436 |
|
} else |
437 |
< |
ns2go = 1; |
437 |
> |
nstarget = 1; |
438 |
|
} |
439 |
< |
dimlist[ndims++] = (int)np->mp; |
440 |
< |
for (niter = ns2go*MAXITER; (ns2go > 0) & (niter > 0); niter--) { |
441 |
< |
if (specjitter > 1.5) |
439 |
> |
dimlist[ndims++] = (int)(size_t)np->mp; |
440 |
> |
maxiter = MAXITER*nstarget; |
441 |
> |
for (nstaken = ntrials = 0; nstaken < nstarget && |
442 |
> |
ntrials < maxiter; ntrials++) { |
443 |
> |
if (ntrials) |
444 |
|
d = frandom(); |
445 |
|
else |
446 |
|
d = urand(ilhash(dimlist,ndims)+1823+samplendx); |
465 |
|
if (DOT(sr.rdir, r->ron) >= -FTINY) |
466 |
|
continue; |
467 |
|
normalize(sr.rdir); /* OK, normalize */ |
468 |
< |
if (specjitter > 1.5) /* multi-sampling */ |
468 |
> |
if (nstaken) /* multi-sampling */ |
469 |
|
rayclear(&sr); |
470 |
|
rayvalue(&sr); |
471 |
|
multcolor(sr.rcol, sr.rcoef); |
472 |
|
addcolor(r->rcol, sr.rcol); |
473 |
< |
--ns2go; |
473 |
> |
++nstaken; |
474 |
|
} |
475 |
|
ndims--; |
476 |
|
} |