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.9 by greg, Thu Jan 16 12:05:29 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 123 | Line 128 | double  omega;                 /* light source size */
128                   *  is always modified by material color.
129                   */
130                                                  /* roughness + source */
131 <                dtmp = np->alpha2 + omega/(2.0*PI);
131 >                dtmp = np->alpha2/2.0 + omega/(2.0*PI);
132                                                  /* gaussian */
133                  dtmp = exp((DOT(np->prdir,ldir)-1.)/dtmp)/(2.*PI)/dtmp;
134                                                  /* worth using? */
# 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 (specthresh > FTINY &&
196 +                                ((specthresh >= 1.-FTINY ||
197 +                                specthresh + (.05 - .1*urand(8199+samplendx))
198 +                                        > nd.rspec)))
199 +                        nd.specfl |= SP_RBLT;
200                                                  /* compute reflected ray */
201                  for (i = 0; i < 3; i++)
202                          nd.vrefl[i] = r->rdir[i] + 2.0*nd.pdot*nd.pnorm[i];
203 +                if (DOT(nd.vrefl, r->ron) <= FTINY)     /* penetration? */
204 +                        for (i = 0; i < 3; i++)         /* safety measure */
205 +                                nd.vrefl[i] = r->rdir[i] + 2.*r->rod*r->ron[i];
206  
207                  if (!(r->crtype & SHADOW) && nd.specfl & SP_PURE) {
208                          RAY  lr;
# Line 207 | Line 221 | register RAY  *r;
221                  nd.tdiff = nd.trans - nd.tspec;
222                  if (nd.tspec > FTINY) {
223                          nd.specfl |= SP_TRAN;
224 +                                                        /* check threshold */
225 +                        if (specthresh > FTINY &&
226 +                                        ((specthresh >= 1.-FTINY ||
227 +                                        specthresh +
228 +                                            (.05 - .1*urand(7241+samplendx))
229 +                                                > nd.tspec)))
230 +                                nd.specfl |= SP_TBLT;
231                          if (r->crtype & SHADOW ||
232                                          DOT(r->pert,r->pert) <= FTINY*FTINY) {
233                                  VCOPY(nd.prdir, r->rdir);
# Line 214 | Line 235 | register RAY  *r;
235                          } else {
236                                  for (i = 0; i < 3; i++)         /* perturb */
237                                          nd.prdir[i] = r->rdir[i] -
238 <                                                        .75*r->pert[i];
239 <                                normalize(nd.prdir);
238 >                                                        0.5*r->pert[i];
239 >                                if (DOT(nd.prdir, r->ron) < -FTINY)
240 >                                        normalize(nd.prdir);    /* OK */
241 >                                else
242 >                                        VCOPY(nd.prdir, r->rdir);
243                          }
244                  }
245          } else
# Line 250 | Line 274 | register RAY  *r;
274  
275          if (nd.rdiff > FTINY) {         /* ambient from this side */
276                  ambient(ctmp, r);
277 <                scalecolor(ctmp, nd.rdiff);
277 >                if (nd.specfl & SP_RBLT)
278 >                        scalecolor(ctmp, 1.0-nd.trans);
279 >                else
280 >                        scalecolor(ctmp, nd.rdiff);
281                  multcolor(ctmp, nd.mcolor);     /* modified by material color */
282                  addcolor(r->rcol, ctmp);        /* add to returned color */
283          }
284          if (nd.tdiff > FTINY) {         /* ambient from other side */
285                  flipsurface(r);
286                  ambient(ctmp, r);
287 <                scalecolor(ctmp, nd.tdiff);
287 >                if (nd.specfl & SP_TBLT)
288 >                        scalecolor(ctmp, nd.trans);
289 >                else
290 >                        scalecolor(ctmp, nd.tdiff);
291                  multcolor(ctmp, nd.mcolor);     /* modified by color */
292                  addcolor(r->rcol, ctmp);
293                  flipsurface(r);
# Line 279 | Line 309 | register NORMDAT  *np;
309          FVECT  u, v, h;
310          double  rv[2];
311          double  d, sinp, cosp;
282        int  confuse;
312          register int  i;
313                                          /* set up sample coordinates */
314          v[0] = v[1] = v[2] = 0.0;
# Line 291 | Line 320 | register NORMDAT  *np;
320          normalize(u);
321          fcross(v, np->pnorm, u);
322                                          /* compute reflection */
323 <        if (np->specfl & SP_REFL &&
323 >        if ((np->specfl & (SP_REFL|SP_RBLT)) == SP_REFL &&
324                          rayorigin(&sr, r, SPECULAR, np->rspec) == 0) {
296                confuse = 0;
325                  dimlist[ndims++] = (int)np->mp;
326 <        refagain:
299 <                dimlist[ndims] = confuse += 3601;
300 <                d = urand(ilhash(dimlist,ndims+1)+samplendx);
326 >                d = urand(ilhash(dimlist,ndims)+samplendx);
327                  multisamp(rv, 2, d);
328                  d = 2.0*PI * rv[0];
329                  cosp = cos(d);
330                  sinp = sin(d);
331 +                rv[1] = 1.0 - specjitter*rv[1];
332                  if (rv[1] <= FTINY)
333                          d = 1.0;
334                  else
# Line 311 | Line 338 | register NORMDAT  *np;
338                  d = -2.0 * DOT(h, r->rdir) / (1.0 + d*d);
339                  for (i = 0; i < 3; i++)
340                          sr.rdir[i] = r->rdir[i] + d*h[i];
341 <                if (DOT(sr.rdir, r->ron) <= FTINY)      /* oops! */
342 <                        goto refagain;
341 >                if (DOT(sr.rdir, r->ron) <= FTINY)
342 >                        VCOPY(sr.rdir, np->vrefl);      /* jitter no good */
343                  rayvalue(&sr);
344                  multcolor(sr.rcol, np->scolor);
345                  addcolor(r->rcol, sr.rcol);
346                  ndims--;
347          }
348                                          /* compute transmission */
349 +        if ((np->specfl & (SP_TRAN|SP_TBLT)) == SP_TRAN &&
350 +                        rayorigin(&sr, r, SPECULAR, np->tspec) == 0) {
351 +                dimlist[ndims++] = (int)np->mp;
352 +                d = urand(ilhash(dimlist,ndims)+1823+samplendx);
353 +                multisamp(rv, 2, d);
354 +                d = 2.0*PI * rv[0];
355 +                cosp = cos(d);
356 +                sinp = sin(d);
357 +                rv[1] = 1.0 - specjitter*rv[1];
358 +                if (rv[1] <= FTINY)
359 +                        d = 1.0;
360 +                else
361 +                        d = sqrt( np->alpha2/4.0 * -log(rv[1]) );
362 +                for (i = 0; i < 3; i++)
363 +                        sr.rdir[i] = np->prdir[i] + d*(cosp*u[i] + sinp*v[i]);
364 +                if (DOT(sr.rdir, r->ron) < -FTINY)
365 +                        normalize(sr.rdir);             /* OK, normalize */
366 +                else
367 +                        VCOPY(sr.rdir, np->prdir);      /* else no jitter */
368 +                rayvalue(&sr);
369 +                multcolor(sr.rcol, np->scolor);
370 +                addcolor(r->rcol, sr.rcol);
371 +                ndims--;
372 +        }
373   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines