ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/normal.c
(Generate patch)

Comparing ray/src/rt/normal.c (file contents):
Revision 2.57 by greg, Sun Oct 10 22:31:46 2010 UTC vs.
Revision 2.61 by greg, Wed Oct 26 03:44:56 2011 UTC

# Line 325 | Line 325 | m_normal(                      /* color a ray that hit something normal *
325  
326          if (nd.rdiff > FTINY) {         /* ambient from this side */
327                  copycolor(ctmp, nd.mcolor);     /* modified by material color */
328 <                if (nd.specfl & SP_RBLT)
329 <                        scalecolor(ctmp, 1.0-nd.trans);
330 <                else
331 <                        scalecolor(ctmp, nd.rdiff);
328 >                scalecolor(ctmp, nd.rdiff);
329 >                if (nd.specfl & SP_RBLT)        /* add in specular as well? */
330 >                        addcolor(ctmp, nd.scolor);
331                  multambient(ctmp, r, hastexture ? nd.pnorm : r->ron);
332                  addcolor(r->rcol, ctmp);        /* add to returned color */
333          }
# Line 374 | Line 373 | gaussamp(                      /* sample Gaussian specular */
373          double  rv[2];
374          double  d, sinp, cosp;
375          COLOR   scol;
376 <        int  niter, ns2go;
376 >        int  maxiter, ntrials, nstarget, nstaken;
377          register int  i;
378                                          /* quick test */
379          if ((np->specfl & (SP_REFL|SP_RBLT)) != SP_REFL &&
# Line 392 | Line 391 | gaussamp(                      /* sample Gaussian specular */
391                                          /* compute reflection */
392          if ((np->specfl & (SP_REFL|SP_RBLT)) == SP_REFL &&
393                          rayorigin(&sr, SPECULAR, r, np->scolor) == 0) {
394 <                copycolor(scol, np->scolor);
396 <                ns2go = 1;
394 >                nstarget = 1;
395                  if (specjitter > 1.5) { /* multiple samples? */
396 <                        ns2go = specjitter*r->rweight + .5;
397 <                        if (sr.rweight <= minweight*ns2go)
398 <                                ns2go = sr.rweight/minweight;
399 <                        if (ns2go > 1) {
400 <                                d = 1./ns2go;
401 <                                scalecolor(scol, d);
396 >                        nstarget = specjitter*r->rweight + .5;
397 >                        if (sr.rweight <= minweight*nstarget)
398 >                                nstarget = sr.rweight/minweight;
399 >                        if (nstarget > 1) {
400 >                                d = 1./nstarget;
401 >                                scalecolor(sr.rcoef, d);
402                                  sr.rweight *= d;
403                          } else
404 <                                ns2go = 1;
404 >                                nstarget = 1;
405                  }
406 <                dimlist[ndims++] = (int)np->mp;
407 <                for (niter = ns2go*MAXITER; (ns2go > 0) & (niter > 0); niter--) {
408 <                        if (specjitter > 1.5)
406 >                setcolor(scol, 0., 0., 0.);
407 >                dimlist[ndims++] = (int)(size_t)np->mp;
408 >                maxiter = MAXITER*nstarget;
409 >                for (nstaken = ntrials = 0; nstaken < nstarget &&
410 >                                                ntrials < maxiter; ntrials++) {
411 >                        if (ntrials)
412                                  d = frandom();
413                          else
414                                  d = urand(ilhash(dimlist,ndims)+samplendx);
# Line 424 | Line 425 | gaussamp(                      /* sample Gaussian specular */
425                          for (i = 0; i < 3; i++)
426                                  h[i] = np->pnorm[i] + d*(cosp*u[i] + sinp*v[i]);
427                          d = -2.0 * DOT(h, r->rdir) / (1.0 + d*d);
427                        if (d <= np->pdot + FTINY)
428                                continue;
428                          VSUM(sr.rdir, r->rdir, h, d);
429 <                        if (DOT(sr.rdir, r->ron) <= FTINY)
429 >                                                /* sample rejection test */
430 >                        if ((d = DOT(sr.rdir, r->ron)) <= FTINY)
431                                  continue;
432                          checknorm(sr.rdir);
433 <                        if (specjitter > 1.5) { /* adjusted W-G-M-D weight */
434 <                                d = 2.*(1. - np->pdot/d);
435 <                                copycolor(sr.rcoef, scol);
436 <                                scalecolor(sr.rcoef, d);
437 <                                rayclear(&sr);
433 >                        if (nstarget > 1) {     /* W-G-M-D adjustment */
434 >                                if (nstaken) rayclear(&sr);
435 >                                rayvalue(&sr);
436 >                                d = 2./(1. + r->rod/d);
437 >                                scalecolor(sr.rcol, d);
438 >                                addcolor(scol, sr.rcol);
439 >                        } else {
440 >                                rayvalue(&sr);
441 >                                multcolor(sr.rcol, sr.rcoef);
442 >                                addcolor(r->rcol, sr.rcol);
443                          }
444 <                        rayvalue(&sr);
440 <                        multcolor(sr.rcol, sr.rcoef);
441 <                        addcolor(r->rcol, sr.rcol);
442 <                        --ns2go;
444 >                        ++nstaken;
445                  }
446 +                if (nstarget > 1) {             /* final W-G-M-D weighting */
447 +                        multcolor(scol, sr.rcoef);
448 +                        d = (double)nstarget/ntrials;
449 +                        scalecolor(scol, d);
450 +                        addcolor(r->rcol, scol);
451 +                }
452                  ndims--;
453          }
454                                          /* compute transmission */
# Line 448 | Line 456 | gaussamp(                      /* sample Gaussian specular */
456          scalecolor(sr.rcoef, np->tspec);
457          if ((np->specfl & (SP_TRAN|SP_TBLT)) == SP_TRAN &&
458                          rayorigin(&sr, SPECULAR, r, sr.rcoef) == 0) {
459 <                ns2go = 1;
459 >                nstarget = 1;
460                  if (specjitter > 1.5) { /* multiple samples? */
461 <                        ns2go = specjitter*r->rweight + .5;
462 <                        if (sr.rweight <= minweight*ns2go)
463 <                                ns2go = sr.rweight/minweight;
464 <                        if (ns2go > 1) {
465 <                                d = 1./ns2go;
461 >                        nstarget = specjitter*r->rweight + .5;
462 >                        if (sr.rweight <= minweight*nstarget)
463 >                                nstarget = sr.rweight/minweight;
464 >                        if (nstarget > 1) {
465 >                                d = 1./nstarget;
466                                  scalecolor(sr.rcoef, d);
467                                  sr.rweight *= d;
468                          } else
469 <                                ns2go = 1;
469 >                                nstarget = 1;
470                  }
471 <                dimlist[ndims++] = (int)np->mp;
472 <                for (niter = ns2go*MAXITER; (ns2go > 0) & (niter > 0); niter--) {
473 <                        if (specjitter > 1.5)
471 >                dimlist[ndims++] = (int)(size_t)np->mp;
472 >                maxiter = MAXITER*nstarget;
473 >                for (nstaken = ntrials = 0; nstaken < nstarget &&
474 >                                                ntrials < maxiter; ntrials++) {
475 >                        if (ntrials)
476                                  d = frandom();
477                          else
478 <                                d = urand(ilhash(dimlist,ndims)+1823+samplendx);
478 >                                d = urand(ilhash(dimlist,ndims)+samplendx);
479                          multisamp(rv, 2, d);
480                          d = 2.0*PI * rv[0];
481                          cosp = tcos(d);
# Line 478 | Line 488 | gaussamp(                      /* sample Gaussian specular */
488                                  d = sqrt( np->alpha2 * -log(rv[1]) );
489                          for (i = 0; i < 3; i++)
490                                  sr.rdir[i] = np->prdir[i] + d*(cosp*u[i] + sinp*v[i]);
491 +                                                /* sample rejection test */
492                          if (DOT(sr.rdir, r->ron) >= -FTINY)
493                                  continue;
494                          normalize(sr.rdir);     /* OK, normalize */
495 <                        if (specjitter > 1.5)   /* multi-sampling */
495 >                        if (nstaken)            /* multi-sampling */
496                                  rayclear(&sr);
497                          rayvalue(&sr);
498                          multcolor(sr.rcol, sr.rcoef);
499                          addcolor(r->rcol, sr.rcol);
500 <                        --ns2go;
500 >                        ++nstaken;
501                  }
502                  ndims--;
503          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines