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.3 by greg, Sat Jan 4 23:36:42 1992 UTC vs.
Revision 2.5 by greg, Tue Jan 14 16:16:45 1992 UTC

# Line 20 | Line 20 | static char SCCSid[] = "$SunId$ LBL";
20  
21   #include  "random.h"
22  
23 + extern double  specthresh;              /* specular sampling threshold */
24 + extern double  specjitter;              /* specular sampling jitter */
25 +
26   /*
27   *      This routine uses portions of the reflection
28   *  model described by Cook and Torrance.
# Line 42 | Line 45 | static char SCCSid[] = "$SunId$ LBL";
45   #define  SP_TRAN        02              /* has transmitted specular */
46   #define  SP_PURE        010             /* purely specular (zero roughness) */
47   #define  SP_FLAT        020             /* flat reflecting surface */
48 + #define  SP_RBLT        040             /* reflection below sample threshold */
49 + #define  SP_TBLT        0100            /* transmission below threshold */
50  
51   typedef struct {
52          OBJREC  *mp;            /* material pointer */
# Line 186 | Line 191 | register RAY  *r;
191                  for (i = 0; i < 3; i++)
192                          colval(nd.scolor,i) += (1.0-colval(nd.scolor,i))*dtmp;
193                  nd.rspec += (1.0-nd.rspec)*dtmp;
194 +                                                /* check threshold */
195 +                if (nd.rspec <= specthresh+FTINY)
196 +                        nd.specfl |= SP_RBLT;
197                                                  /* compute reflected ray */
198                  for (i = 0; i < 3; i++)
199                          nd.vrefl[i] = r->rdir[i] + 2.0*nd.pdot*nd.pnorm[i];
# Line 207 | Line 215 | register RAY  *r;
215                  nd.tdiff = nd.trans - nd.tspec;
216                  if (nd.tspec > FTINY) {
217                          nd.specfl |= SP_TRAN;
218 +                                                        /* check threshold */
219 +                        if (nd.tspec <= specthresh+FTINY)
220 +                                nd.specfl |= SP_TBLT;
221                          if (r->crtype & SHADOW ||
222                                          DOT(r->pert,r->pert) <= FTINY*FTINY) {
223                                  VCOPY(nd.prdir, r->rdir);
# Line 250 | Line 261 | register RAY  *r;
261  
262          if (nd.rdiff > FTINY) {         /* ambient from this side */
263                  ambient(ctmp, r);
264 <                scalecolor(ctmp, nd.rdiff);
264 >                if (nd.specfl & SP_RBLT)
265 >                        scalecolor(ctmp, 1.0-nd.trans);
266 >                else
267 >                        scalecolor(ctmp, nd.rdiff);
268                  multcolor(ctmp, nd.mcolor);     /* modified by material color */
269                  addcolor(r->rcol, ctmp);        /* add to returned color */
270          }
271          if (nd.tdiff > FTINY) {         /* ambient from other side */
272                  flipsurface(r);
273                  ambient(ctmp, r);
274 <                scalecolor(ctmp, nd.tdiff);
274 >                if (nd.specfl & SP_TBLT)
275 >                        scalecolor(ctmp, nd.trans);
276 >                else
277 >                        scalecolor(ctmp, nd.tdiff);
278                  multcolor(ctmp, nd.mcolor);     /* modified by color */
279                  addcolor(r->rcol, ctmp);
280                  flipsurface(r);
# Line 279 | Line 296 | register NORMDAT  *np;
296          FVECT  u, v, h;
297          double  rv[2];
298          double  d, sinp, cosp;
299 <        int  confuse;
299 >        int  ntries;
300          register int  i;
301                                          /* set up sample coordinates */
302          v[0] = v[1] = v[2] = 0.0;
# Line 291 | Line 308 | register NORMDAT  *np;
308          normalize(u);
309          fcross(v, np->pnorm, u);
310                                          /* compute reflection */
311 <        if (np->specfl & SP_REFL &&
311 >        if ((np->specfl & (SP_REFL|SP_RBLT)) == SP_REFL &&
312                          rayorigin(&sr, r, SPECULAR, np->rspec) == 0) {
296                confuse = 0;
313                  dimlist[ndims++] = (int)np->mp;
314 <        refagain:
315 <                dimlist[ndims] = confuse += 3601;
316 <                d = urand(ilhash(dimlist,ndims+1)+samplendx);
317 <                multisamp(rv, 2, d);
318 <                d = 2.0*PI * rv[0];
319 <                cosp = cos(d);
320 <                sinp = sin(d);
321 <                if (rv[1] <= FTINY)
322 <                        d = 1.0;
323 <                else
324 <                        d = sqrt( np->alpha2 * -log(rv[1]) );
325 <                for (i = 0; i < 3; i++)
326 <                        h[i] = np->pnorm[i] + d*(cosp*u[i] + sinp*v[i]);
327 <                d = -2.0 * DOT(h, r->rdir) / (1.0 + d*d);
328 <                for (i = 0; i < 3; i++)
329 <                        sr.rdir[i] = r->rdir[i] + d*h[i];
330 <                if (DOT(sr.rdir, r->ron) <= FTINY)      /* oops! */
331 <                        goto refagain;
332 <                rayvalue(&sr);
333 <                multcolor(sr.rcol, np->scolor);
334 <                addcolor(r->rcol, sr.rcol);
314 >                for (ntries = 0; ntries < 10; ntries++) {
315 >                        dimlist[ndims] = ntries * 8912;
316 >                        d = urand(ilhash(dimlist,ndims+1)+samplendx);
317 >                        multisamp(rv, 2, d);
318 >                        d = 2.0*PI * rv[0];
319 >                        cosp = cos(d);
320 >                        sinp = sin(d);
321 >                        rv[1] = 1.0 - specjitter*rv[1];
322 >                        if (rv[1] <= FTINY)
323 >                                d = 1.0;
324 >                        else
325 >                                d = sqrt( np->alpha2 * -log(rv[1]) );
326 >                        for (i = 0; i < 3; i++)
327 >                                h[i] = np->pnorm[i] + d*(cosp*u[i] + sinp*v[i]);
328 >                        d = -2.0 * DOT(h, r->rdir) / (1.0 + d*d);
329 >                        for (i = 0; i < 3; i++)
330 >                                sr.rdir[i] = r->rdir[i] + d*h[i];
331 >                        if (DOT(sr.rdir, r->ron) > FTINY) {
332 >                                rayvalue(&sr);
333 >                                multcolor(sr.rcol, np->scolor);
334 >                                addcolor(r->rcol, sr.rcol);
335 >                                break;
336 >                        }
337 >                }
338                  ndims--;
339          }
340                                          /* compute transmission */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines