236 |
|
if (specthresh >= nd.rspec-FTINY) |
237 |
|
nd.specfl |= SP_RBLT; |
238 |
|
/* compute refl. direction */ |
239 |
< |
for (i = 0; i < 3; i++) |
240 |
< |
nd.vrefl[i] = r->rdir[i] + 2.0*nd.pdot*nd.pnorm[i]; |
239 |
> |
VSUM(nd.vrefl, r->rdir, nd.pnorm, 2.0*nd.pdot); |
240 |
|
if (DOT(nd.vrefl, r->ron) <= FTINY) /* penetration? */ |
241 |
< |
for (i = 0; i < 3; i++) /* safety measure */ |
243 |
< |
nd.vrefl[i] = r->rdir[i] + 2.*r->rod*r->ron[i]; |
241 |
> |
VSUM(nd.vrefl, r->rdir, r->ron, 2.0*r->rod); |
242 |
|
} |
243 |
|
/* compute transmission */ |
244 |
|
if (m->otype == MAT_TRANS2) { |
348 |
|
FVECT h; |
349 |
|
double rv[2]; |
350 |
|
double d, sinp, cosp; |
351 |
< |
int niter; |
351 |
> |
COLOR scol; |
352 |
> |
int niter, ns2go; |
353 |
|
register int i; |
354 |
|
/* compute reflection */ |
355 |
|
if ((np->specfl & (SP_REFL|SP_RBLT)) == SP_REFL && |
356 |
|
rayorigin(&sr, SPECULAR, r, np->scolor) == 0) { |
357 |
+ |
copycolor(scol, np->scolor); |
358 |
+ |
ns2go = 1; |
359 |
+ |
if (specjitter > 1.5) { /* multiple samples? */ |
360 |
+ |
ns2go = specjitter*r->rweight + .5; |
361 |
+ |
if ((d = bright(scol)) <= minweight*ns2go) |
362 |
+ |
ns2go = d/minweight; |
363 |
+ |
if (ns2go > 1) { |
364 |
+ |
d = 1./ns2go; |
365 |
+ |
scalecolor(scol, d); |
366 |
+ |
} else |
367 |
+ |
ns2go = 1; |
368 |
+ |
} |
369 |
|
dimlist[ndims++] = (int)np->mp; |
370 |
< |
for (niter = 0; niter < MAXITER; niter++) { |
371 |
< |
if (niter) |
370 |
> |
for (niter = ns2go*MAXITER; (ns2go > 0) & (niter > 0); niter--) { |
371 |
> |
if (specjitter > 1.5) |
372 |
|
d = frandom(); |
373 |
|
else |
374 |
|
d = urand(ilhash(dimlist,ndims)+samplendx); |
376 |
|
d = 2.0*PI * rv[0]; |
377 |
|
cosp = tcos(d) * np->u_alpha; |
378 |
|
sinp = tsin(d) * np->v_alpha; |
379 |
< |
d = sqrt(cosp*cosp + sinp*sinp); |
380 |
< |
cosp /= d; |
381 |
< |
sinp /= d; |
382 |
< |
rv[1] = 1.0 - specjitter*rv[1]; |
379 |
> |
d = 1./sqrt(cosp*cosp + sinp*sinp); |
380 |
> |
cosp *= d; |
381 |
> |
sinp *= d; |
382 |
> |
if ((0. <= specjitter) & (specjitter < 1.)) |
383 |
> |
rv[1] = 1.0 - specjitter*rv[1]; |
384 |
|
if (rv[1] <= FTINY) |
385 |
|
d = 1.0; |
386 |
|
else |
391 |
|
h[i] = np->pnorm[i] + |
392 |
|
d*(cosp*np->u[i] + sinp*np->v[i]); |
393 |
|
d = -2.0 * DOT(h, r->rdir) / (1.0 + d*d); |
394 |
< |
for (i = 0; i < 3; i++) |
395 |
< |
sr.rdir[i] = r->rdir[i] + d*h[i]; |
396 |
< |
if (DOT(sr.rdir, r->ron) > FTINY) { |
397 |
< |
checknorm(sr.rdir); |
398 |
< |
rayvalue(&sr); |
399 |
< |
multcolor(sr.rcol, sr.rcoef); |
400 |
< |
addcolor(r->rcol, sr.rcol); |
401 |
< |
break; |
394 |
> |
if (d <= np->pdot + FTINY) |
395 |
> |
continue; |
396 |
> |
VSUM(sr.rdir, r->rdir, h, d); |
397 |
> |
if (DOT(sr.rdir, r->ron) <= FTINY) |
398 |
> |
continue; |
399 |
> |
checknorm(sr.rdir); |
400 |
> |
if (specjitter > 1.5) { /* adjusted W-G-M-D weight */ |
401 |
> |
copycolor(sr.rcoef, scol); |
402 |
> |
d = 2.*(1. - np->pdot/d); |
403 |
> |
scalecolor(sr.rcoef, d); |
404 |
> |
rayclear(&sr); |
405 |
|
} |
406 |
+ |
rayvalue(&sr); |
407 |
+ |
multcolor(sr.rcol, sr.rcoef); |
408 |
+ |
addcolor(r->rcol, sr.rcol); |
409 |
+ |
--ns2go; |
410 |
|
} |
411 |
|
ndims--; |
412 |
|
} |
415 |
|
scalecolor(sr.rcoef, np->tspec); |
416 |
|
if ((np->specfl & (SP_TRAN|SP_TBLT)) == SP_TRAN && |
417 |
|
rayorigin(&sr, SPECULAR, r, sr.rcoef) == 0) { |
418 |
+ |
copycolor(scol, sr.rcoef); |
419 |
+ |
ns2go = 1; |
420 |
+ |
if (specjitter > 1.5) { /* multiple samples? */ |
421 |
+ |
ns2go = specjitter*r->rweight + .5; |
422 |
+ |
if ((d = bright(scol)) <= minweight*ns2go) |
423 |
+ |
ns2go = d/minweight; |
424 |
+ |
if (ns2go > 1) { |
425 |
+ |
d = 1./ns2go; |
426 |
+ |
scalecolor(scol, d); |
427 |
+ |
} else |
428 |
+ |
ns2go = 1; |
429 |
+ |
} |
430 |
|
dimlist[ndims++] = (int)np->mp; |
431 |
< |
for (niter = 0; niter < MAXITER; niter++) { |
432 |
< |
if (niter) |
431 |
> |
for (niter = ns2go*MAXITER; (ns2go > 0) & (niter > 0); niter--) { |
432 |
> |
if (specjitter > 1.5) |
433 |
|
d = frandom(); |
434 |
|
else |
435 |
|
d = urand(ilhash(dimlist,ndims)+1823+samplendx); |
437 |
|
d = 2.0*PI * rv[0]; |
438 |
|
cosp = tcos(d) * np->u_alpha; |
439 |
|
sinp = tsin(d) * np->v_alpha; |
440 |
< |
d = sqrt(cosp*cosp + sinp*sinp); |
441 |
< |
cosp /= d; |
442 |
< |
sinp /= d; |
443 |
< |
rv[1] = 1.0 - specjitter*rv[1]; |
440 |
> |
d = 1./sqrt(cosp*cosp + sinp*sinp); |
441 |
> |
cosp *= d; |
442 |
> |
sinp *= d; |
443 |
> |
if ((0. <= specjitter) & (specjitter < 1.)) |
444 |
> |
rv[1] = 1.0 - specjitter*rv[1]; |
445 |
|
if (rv[1] <= FTINY) |
446 |
|
d = 1.0; |
447 |
|
else |
451 |
|
for (i = 0; i < 3; i++) |
452 |
|
sr.rdir[i] = np->prdir[i] + |
453 |
|
d*(cosp*np->u[i] + sinp*np->v[i]); |
454 |
< |
if (DOT(sr.rdir, r->ron) < -FTINY) { |
455 |
< |
normalize(sr.rdir); /* OK, normalize */ |
456 |
< |
rayvalue(&sr); |
457 |
< |
multcolor(sr.rcol, sr.rcoef); |
458 |
< |
addcolor(r->rcol, sr.rcol); |
459 |
< |
break; |
454 |
> |
if (DOT(sr.rdir, r->ron) >= -FTINY) |
455 |
> |
continue; |
456 |
> |
normalize(sr.rdir); /* OK, normalize */ |
457 |
> |
if (specjitter > 1.5) { /* multi-sampling */ |
458 |
> |
copycolor(sr.rcoef, scol); |
459 |
> |
rayclear(&sr); |
460 |
|
} |
461 |
+ |
rayvalue(&sr); |
462 |
+ |
multcolor(sr.rcol, sr.rcoef); |
463 |
+ |
addcolor(r->rcol, sr.rcol); |
464 |
+ |
--ns2go; |
465 |
|
} |
466 |
|
ndims--; |
467 |
|
} |