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.15 by greg, Wed Apr 22 09:05:30 1992 UTC vs.
Revision 2.22 by greg, Fri Oct 16 10:20:29 1992 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 50 | Line 48 | extern double  specjitter;             /* specular sampling jitte
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 >                                                /* delta */
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 = 2.0 - 2.0*d2/sqrt(DOT(vtmp,vtmp));
111                                                  /* gaussian */
112 <                dtmp = exp((DOT(np->vrefl,ldir)-1.)/dtmp)/(2.*PI)/dtmp;
112 >                dtmp = exp(-d2/dtmp)/(4.*PI*dtmp);
113                                                  /* worth using? */
114                  if (dtmp > FTINY) {
115                          copycolor(ctmp, np->scolor);
# Line 128 | Line 133 | double  omega;                 /* light source size */
133                   *  is always modified by material color.
134                   */
135                                                  /* roughness + source */
136 <                dtmp = np->alpha2/2.0 + omega/(2.0*PI);
136 >                dtmp = np->alpha2 + omega/PI;
137                                                  /* gaussian */
138 <                dtmp = exp((DOT(np->prdir,ldir)-1.)/dtmp)/(2.*PI)/dtmp;
138 >                dtmp = exp((2.*DOT(np->prdir,ldir)-2.)/dtmp)/(PI*dtmp);
139                                                  /* worth using? */
140                  if (dtmp > FTINY) {
141                          copycolor(ctmp, np->mcolor);
142 <                        dtmp *= np->tspec * omega * sqrt(ldot/np->pdot);
142 >                        dtmp *= np->tspec * omega * sqrt(-ldot/np->pdot);
143                          scalecolor(ctmp, dtmp);
144                          addcolor(cval, ctmp);
145                  }
# Line 158 | Line 163 | register RAY  *r;
163          if (m->oargs.nfargs != (m->otype == MAT_TRANS ? 7 : 5))
164                  objerror(m, USER, "bad number of arguments");
165          nd.mp = m;
166 +        nd.rp = r;
167                                                  /* get material color */
168          setcolor(nd.mcolor, m->oargs.farg[0],
169                             m->oargs.farg[1],
# Line 195 | Line 201 | register RAY  *r;
201                  if (!(nd.specfl & SP_PURE) &&
202                                  specthresh > FTINY &&
203                                  (specthresh >= 1.-FTINY ||
204 <                                specthresh > nd.rspec))
204 >                                specthresh + .05 - .1*frandom() > nd.rspec))
205                          nd.specfl |= SP_RBLT;
206                                                  /* compute reflected ray */
207                  for (i = 0; i < 3; i++)
# Line 224 | Line 230 | register RAY  *r;
230                                                          /* check threshold */
231                          if (!(nd.specfl & SP_PURE) && specthresh > FTINY &&
232                                          (specthresh >= 1.-FTINY ||
233 <                                        specthresh > nd.tspec))
233 >                                specthresh + .05 - .1*frandom() > nd.tspec))
234                                  nd.specfl |= SP_TBLT;
235                          if (r->crtype & SHADOW ||
236                                          DOT(r->pert,r->pert) <= FTINY*FTINY) {
# Line 232 | Line 238 | register RAY  *r;
238                                  transtest = 2;
239                          } else {
240                                  for (i = 0; i < 3; i++)         /* perturb */
241 <                                        nd.prdir[i] = r->rdir[i] -
236 <                                                        0.5*r->pert[i];
241 >                                        nd.prdir[i] = r->rdir[i] - r->pert[i];
242                                  if (DOT(nd.prdir, r->ron) < -FTINY)
243                                          normalize(nd.prdir);    /* OK */
244                                  else
# Line 362 | Line 367 | register NORMDAT  *np;
367                  if (rv[1] <= FTINY)
368                          d = 1.0;
369                  else
370 <                        d = sqrt( np->alpha2/4.0 * -log(rv[1]) );
370 >                        d = sqrt( -log(rv[1]) * np->alpha2 );
371                  for (i = 0; i < 3; i++)
372                          sr.rdir[i] = np->prdir[i] + d*(cosp*u[i] + sinp*v[i]);
373                  if (DOT(sr.rdir, r->ron) < -FTINY)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines