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.7 by greg, Wed Jan 15 11:41:44 1992 UTC vs.
Revision 2.23 by greg, Fri Feb 12 10:41:02 1993 UTC

# Line 24 | Line 24 | extern double  specthresh;             /* specular sampling thres
24   extern double  specjitter;              /* specular sampling jitter */
25  
26   /*
27 < *      This routine uses portions of the reflection
28 < *  model described by Cook and Torrance.
29 < *      The computation of specular components has been simplified by
30 < *  numerous approximations and ommisions to improve speed.
27 > *      This routine implements the isotropic Gaussian
28 > *  model described by Ward in Siggraph `92 article.
29   *      We orient the surface towards the incoming ray, so a single
30   *  surface can be used to represent an infinitely thin object.
31   *
# Line 43 | Line 41 | extern double  specjitter;             /* specular sampling jitte
41                                  /* specularity flags */
42   #define  SP_REFL        01              /* has reflected specular component */
43   #define  SP_TRAN        02              /* has transmitted specular */
44 < #define  SP_PURE        010             /* purely specular (zero roughness) */
45 < #define  SP_FLAT        020             /* flat reflecting surface */
46 < #define  SP_RBLT        040             /* reflection below sample threshold */
47 < #define  SP_TBLT        0100            /* transmission below threshold */
44 > #define  SP_PURE        04              /* purely specular (zero roughness) */
45 > #define  SP_FLAT        010             /* flat reflecting surface */
46 > #define  SP_RBLT        020             /* reflection below sample threshold */
47 > #define  SP_TBLT        040             /* transmission below threshold */
48  
49   typedef struct {
50          OBJREC  *mp;            /* material pointer */
51 +        RAY  *rp;               /* ray pointer */
52          short  specfl;          /* specularity flags, defined above */
53          COLOR  mcolor;          /* color of this material */
54          COLOR  scolor;          /* color of specular component */
# Line 71 | Line 70 | FVECT  ldir;                   /* light source direction */
70   double  omega;                  /* light source size */
71   {
72          double  ldot;
73 <        double  dtmp;
74 <        int     i;
73 >        double  dtmp, d2;
74 >        FVECT  vtmp;
75          COLOR  ctmp;
76  
77          setcolor(cval, 0.0, 0.0, 0.0);
# Line 99 | Line 98 | double  omega;                 /* light source size */
98                   *  gaussian distribution model.
99                   */
100                                                  /* roughness */
101 <                dtmp = 2.0*np->alpha2;
101 >                dtmp = np->alpha2;
102                                                  /* + source if flat */
103                  if (np->specfl & SP_FLAT)
104 <                        dtmp += omega/(2.0*PI);
104 >                        dtmp += omega/(4.0*PI);
105 >                                                /* half vector */
106 >                vtmp[0] = ldir[0] - np->rp->rdir[0];
107 >                vtmp[1] = ldir[1] - np->rp->rdir[1];
108 >                vtmp[2] = ldir[2] - np->rp->rdir[2];
109 >                d2 = DOT(vtmp, np->pnorm);
110 >                d2 *= d2;
111 >                d2 = (DOT(vtmp,vtmp) - d2) / d2;
112                                                  /* gaussian */
113 <                dtmp = exp((DOT(np->vrefl,ldir)-1.)/dtmp)/(2.*PI)/dtmp;
113 >                dtmp = exp(-d2/dtmp)/(4.*PI*dtmp);
114                                                  /* worth using? */
115                  if (dtmp > FTINY) {
116                          copycolor(ctmp, np->scolor);
117 <                        dtmp *= omega / np->pdot;
117 >                        dtmp *= omega * sqrt(ldot/np->pdot);
118                          scalecolor(ctmp, dtmp);
119                          addcolor(cval, ctmp);
120                  }
# Line 128 | Line 134 | double  omega;                 /* light source size */
134                   *  is always modified by material color.
135                   */
136                                                  /* roughness + source */
137 <                dtmp = np->alpha2 + omega/(2.0*PI);
137 >                dtmp = np->alpha2 + omega/PI;
138                                                  /* gaussian */
139 <                dtmp = exp((DOT(np->prdir,ldir)-1.)/dtmp)/(2.*PI)/dtmp;
139 >                dtmp = exp((2.*DOT(np->prdir,ldir)-2.)/dtmp)/(PI*dtmp);
140                                                  /* worth using? */
141                  if (dtmp > FTINY) {
142                          copycolor(ctmp, np->mcolor);
143 <                        dtmp *= np->tspec * omega / np->pdot;
143 >                        dtmp *= np->tspec * omega * sqrt(-ldot/np->pdot);
144                          scalecolor(ctmp, dtmp);
145                          addcolor(cval, ctmp);
146                  }
# Line 158 | Line 164 | register RAY  *r;
164          if (m->oargs.nfargs != (m->otype == MAT_TRANS ? 7 : 5))
165                  objerror(m, USER, "bad number of arguments");
166          nd.mp = m;
167 +        nd.rp = r;
168                                                  /* get material color */
169          setcolor(nd.mcolor, m->oargs.farg[0],
170                             m->oargs.farg[1],
# Line 192 | Line 199 | register RAY  *r;
199                          colval(nd.scolor,i) += (1.0-colval(nd.scolor,i))*dtmp;
200                  nd.rspec += (1.0-nd.rspec)*dtmp;
201                                                  /* check threshold */
202 <                if (specthresh > FTINY &&
203 <                                ((specthresh >= 1.-FTINY ||
204 <                                specthresh + (.1 - .2*urand(8199+samplendx))
205 <                                        > nd.rspec)))
202 >                if (!(nd.specfl & SP_PURE) &&
203 >                                specthresh > FTINY &&
204 >                                (specthresh >= 1.-FTINY ||
205 >                                specthresh + .05 - .1*frandom() > nd.rspec))
206                          nd.specfl |= SP_RBLT;
207                                                  /* compute reflected ray */
208                  for (i = 0; i < 3; i++)
# Line 222 | Line 229 | register RAY  *r;
229                  if (nd.tspec > FTINY) {
230                          nd.specfl |= SP_TRAN;
231                                                          /* check threshold */
232 <                        if (specthresh > FTINY &&
233 <                                        ((specthresh >= 1.-FTINY ||
234 <                                        specthresh +
228 <                                            (.1 - .2*urand(7241+samplendx))
229 <                                                > nd.tspec)))
232 >                        if (!(nd.specfl & SP_PURE) && specthresh > FTINY &&
233 >                                        (specthresh >= 1.-FTINY ||
234 >                                specthresh + .05 - .1*frandom() > nd.tspec))
235                                  nd.specfl |= SP_TBLT;
236                          if (r->crtype & SHADOW ||
237                                          DOT(r->pert,r->pert) <= FTINY*FTINY) {
# Line 234 | Line 239 | register RAY  *r;
239                                  transtest = 2;
240                          } else {
241                                  for (i = 0; i < 3; i++)         /* perturb */
242 <                                        nd.prdir[i] = r->rdir[i] -
238 <                                                        .75*r->pert[i];
242 >                                        nd.prdir[i] = r->rdir[i] - r->pert[i];
243                                  if (DOT(nd.prdir, r->ron) < -FTINY)
244                                          normalize(nd.prdir);    /* OK */
245                                  else
# Line 256 | Line 260 | register RAY  *r;
260                          transtest *= bright(lr.rcol);
261                          transdist = r->rot + lr.rt;
262                  }
263 <        }
263 >        } else
264 >                transtest = 0;
265  
266          if (r->crtype & SHADOW)                 /* the rest is shadow */
267                  return;
# Line 266 | Line 271 | register RAY  *r;
271          if (nd.specfl & SP_PURE && nd.rdiff <= FTINY && nd.tdiff <= FTINY)
272                  return;                         /* 100% pure specular */
273  
274 <        if (r->ro->otype == OBJ_FACE || r->ro->otype == OBJ_RING)
274 >        if (r->ro != NULL && (r->ro->otype == OBJ_FACE ||
275 >                        r->ro->otype == OBJ_RING))
276                  nd.specfl |= SP_FLAT;
277  
278          if (nd.specfl & (SP_REFL|SP_TRAN) && !(nd.specfl & SP_PURE))
# Line 310 | Line 316 | register NORMDAT  *np;
316          double  rv[2];
317          double  d, sinp, cosp;
318          register int  i;
319 +                                        /* quick test */
320 +        if ((np->specfl & (SP_REFL|SP_RBLT)) != SP_REFL &&
321 +                        (np->specfl & (SP_TRAN|SP_TBLT)) != SP_TRAN)
322 +                return;
323                                          /* set up sample coordinates */
324          v[0] = v[1] = v[2] = 0.0;
325          for (i = 0; i < 3; i++)
# Line 346 | Line 356 | register NORMDAT  *np;
356                  ndims--;
357          }
358                                          /* compute transmission */
359 +        if ((np->specfl & (SP_TRAN|SP_TBLT)) == SP_TRAN &&
360 +                        rayorigin(&sr, r, SPECULAR, np->tspec) == 0) {
361 +                dimlist[ndims++] = (int)np->mp;
362 +                d = urand(ilhash(dimlist,ndims)+1823+samplendx);
363 +                multisamp(rv, 2, d);
364 +                d = 2.0*PI * rv[0];
365 +                cosp = cos(d);
366 +                sinp = sin(d);
367 +                rv[1] = 1.0 - specjitter*rv[1];
368 +                if (rv[1] <= FTINY)
369 +                        d = 1.0;
370 +                else
371 +                        d = sqrt( -log(rv[1]) * np->alpha2 );
372 +                for (i = 0; i < 3; i++)
373 +                        sr.rdir[i] = np->prdir[i] + d*(cosp*u[i] + sinp*v[i]);
374 +                if (DOT(sr.rdir, r->ron) < -FTINY)
375 +                        normalize(sr.rdir);             /* OK, normalize */
376 +                else
377 +                        VCOPY(sr.rdir, np->prdir);      /* else no jitter */
378 +                rayvalue(&sr);
379 +                scalecolor(sr.rcol, np->tspec);
380 +                multcolor(sr.rcol, np->mcolor);         /* modified by color */
381 +                addcolor(r->rcol, sr.rcol);
382 +                ndims--;
383 +        }
384   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines