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.33 by greg, Wed Jan 3 11:33:56 1996 UTC vs.
Revision 2.34 by greg, Wed Apr 24 15:47:27 1996 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1995 Regents of the University of California */
1 > /* Copyright (c) 1996 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 25 | Line 25 | extern double  specjitter;             /* specular sampling jitte
25  
26   extern int  backvis;                    /* back faces visible? */
27  
28 + #ifndef  MAXITER
29 + #define  MAXITER        10              /* maximum # specular ray attempts */
30 + #endif
31 +
32   static  gaussamp();
33  
34   /*
# Line 338 | Line 342 | register NORMDAT  *np;
342          FVECT  u, v, h;
343          double  rv[2];
344          double  d, sinp, cosp;
345 +        int  niter;
346          register int  i;
347                                          /* quick test */
348          if ((np->specfl & (SP_REFL|SP_RBLT)) != SP_REFL &&
# Line 356 | Line 361 | register NORMDAT  *np;
361          if ((np->specfl & (SP_REFL|SP_RBLT)) == SP_REFL &&
362                          rayorigin(&sr, r, SPECULAR, np->rspec) == 0) {
363                  dimlist[ndims++] = (int)np->mp;
364 <                d = urand(ilhash(dimlist,ndims)+samplendx);
365 <                multisamp(rv, 2, d);
366 <                d = 2.0*PI * rv[0];
367 <                cosp = cos(d);
368 <                sinp = sin(d);
369 <                rv[1] = 1.0 - specjitter*rv[1];
370 <                if (rv[1] <= FTINY)
371 <                        d = 1.0;
372 <                else
373 <                        d = sqrt( np->alpha2 * -log(rv[1]) );
374 <                for (i = 0; i < 3; i++)
375 <                        h[i] = np->pnorm[i] + d*(cosp*u[i] + sinp*v[i]);
376 <                d = -2.0 * DOT(h, r->rdir) / (1.0 + d*d);
377 <                for (i = 0; i < 3; i++)
378 <                        sr.rdir[i] = r->rdir[i] + d*h[i];
379 <                if (DOT(sr.rdir, r->ron) <= FTINY)
380 <                        VCOPY(sr.rdir, np->vrefl);      /* jitter no good */
381 <                rayvalue(&sr);
382 <                multcolor(sr.rcol, np->scolor);
383 <                addcolor(r->rcol, sr.rcol);
364 >                for (niter = 0; niter < MAXITER; niter++) {
365 >                        if (niter)
366 >                                d = frandom();
367 >                        else
368 >                                d = urand(ilhash(dimlist,ndims)+samplendx);
369 >                        multisamp(rv, 2, d);
370 >                        d = 2.0*PI * rv[0];
371 >                        cosp = cos(d);
372 >                        sinp = sin(d);
373 >                        rv[1] = 1.0 - specjitter*rv[1];
374 >                        if (rv[1] <= FTINY)
375 >                                d = 1.0;
376 >                        else
377 >                                d = sqrt( np->alpha2 * -log(rv[1]) );
378 >                        for (i = 0; i < 3; i++)
379 >                                h[i] = np->pnorm[i] + d*(cosp*u[i] + sinp*v[i]);
380 >                        d = -2.0 * DOT(h, r->rdir) / (1.0 + d*d);
381 >                        for (i = 0; i < 3; i++)
382 >                                sr.rdir[i] = r->rdir[i] + d*h[i];
383 >                        if (DOT(sr.rdir, r->ron) > FTINY) {
384 >                                rayvalue(&sr);
385 >                                multcolor(sr.rcol, np->scolor);
386 >                                addcolor(r->rcol, sr.rcol);
387 >                                break;
388 >                        }
389 >                }
390                  ndims--;
391          }
392                                          /* compute transmission */
393          if ((np->specfl & (SP_TRAN|SP_TBLT)) == SP_TRAN &&
394                          rayorigin(&sr, r, SPECULAR, np->tspec) == 0) {
395                  dimlist[ndims++] = (int)np->mp;
396 <                d = urand(ilhash(dimlist,ndims)+1823+samplendx);
397 <                multisamp(rv, 2, d);
398 <                d = 2.0*PI * rv[0];
399 <                cosp = cos(d);
400 <                sinp = sin(d);
401 <                rv[1] = 1.0 - specjitter*rv[1];
402 <                if (rv[1] <= FTINY)
403 <                        d = 1.0;
404 <                else
405 <                        d = sqrt( -log(rv[1]) * np->alpha2 );
406 <                for (i = 0; i < 3; i++)
407 <                        sr.rdir[i] = np->prdir[i] + d*(cosp*u[i] + sinp*v[i]);
408 <                if (DOT(sr.rdir, r->ron) < -FTINY)
409 <                        normalize(sr.rdir);             /* OK, normalize */
410 <                else
411 <                        VCOPY(sr.rdir, np->prdir);      /* else no jitter */
412 <                rayvalue(&sr);
413 <                scalecolor(sr.rcol, np->tspec);
414 <                multcolor(sr.rcol, np->mcolor);         /* modified by color */
415 <                addcolor(r->rcol, sr.rcol);
396 >                for (niter = 0; niter < MAXITER; niter++) {
397 >                        if (niter)
398 >                                d = frandom();
399 >                        else
400 >                                d = urand(ilhash(dimlist,ndims)+1823+samplendx);
401 >                        multisamp(rv, 2, d);
402 >                        d = 2.0*PI * rv[0];
403 >                        cosp = cos(d);
404 >                        sinp = sin(d);
405 >                        rv[1] = 1.0 - specjitter*rv[1];
406 >                        if (rv[1] <= FTINY)
407 >                                d = 1.0;
408 >                        else
409 >                                d = sqrt( -log(rv[1]) * np->alpha2 );
410 >                        for (i = 0; i < 3; i++)
411 >                                sr.rdir[i] = np->prdir[i] + d*(cosp*u[i] + sinp*v[i]);
412 >                        if (DOT(sr.rdir, r->ron) < -FTINY) {
413 >                                normalize(sr.rdir);     /* OK, normalize */
414 >                                rayvalue(&sr);
415 >                                scalecolor(sr.rcol, np->tspec);
416 >                                multcolor(sr.rcol, np->mcolor); /* modified */
417 >                                addcolor(r->rcol, sr.rcol);
418 >                                break;
419 >                        }
420 >                }
421                  ndims--;
422          }
423   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines