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.16 by greg, Wed May 6 17:36:00 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 74 | Line 72 | double  omega;                 /* light source size */
72          double  ldot;
73          double  dtmp, d2;
74          FVECT  vtmp;
77        register int    i;
75          COLOR  ctmp;
76  
77          setcolor(cval, 0.0, 0.0, 0.0);
# Line 105 | Line 102 | double  omega;                 /* light source size */
102                                                  /* + source if flat */
103                  if (np->specfl & SP_FLAT)
104                          dtmp += omega/(4.0*PI);
105 <                                                /* delta */
106 <                for (i = 0; i < 3; i++)
107 <                        vtmp[i] = ldir[i] - np->rp->rdir[i];
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 = 2.0 - 2.0*d2/sqrt(DOT(vtmp,vtmp));
110 >                d2 *= d2;
111 >                d2 = (DOT(vtmp,vtmp) - d2) / d2;
112                                                  /* gaussian */
113                  dtmp = exp(-d2/dtmp)/(4.*PI*dtmp);
114                                                  /* worth using? */
# Line 135 | Line 134 | double  omega;                 /* light source size */
134                   *  is always modified by material color.
135                   */
136                                                  /* roughness + source */
137 <                dtmp = np->alpha2/2.0 + 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 * sqrt(ldot/np->pdot);
143 >                        dtmp *= np->tspec * omega * sqrt(-ldot/np->pdot);
144                          scalecolor(ctmp, dtmp);
145                          addcolor(cval, ctmp);
146                  }
# Line 203 | Line 202 | register RAY  *r;
202                  if (!(nd.specfl & SP_PURE) &&
203                                  specthresh > FTINY &&
204                                  (specthresh >= 1.-FTINY ||
205 <                                specthresh > nd.rspec))
205 >                                specthresh + .05 - .1*frandom() > nd.rspec))
206                          nd.specfl |= SP_RBLT;
207                                                  /* compute reflected ray */
208                  for (i = 0; i < 3; i++)
# Line 232 | Line 231 | register RAY  *r;
231                                                          /* check threshold */
232                          if (!(nd.specfl & SP_PURE) && specthresh > FTINY &&
233                                          (specthresh >= 1.-FTINY ||
234 <                                        specthresh > nd.tspec))
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 240 | 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] -
244 <                                                        0.5*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 370 | Line 368 | register NORMDAT  *np;
368                  if (rv[1] <= FTINY)
369                          d = 1.0;
370                  else
371 <                        d = sqrt( np->alpha2/4.0 * -log(rv[1]) );
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)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines