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.11 by greg, Fri Feb 21 14:53:16 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 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 >                                                /* 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/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 / 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 + (.05 - .1*frandom()) > 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 221 | 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 +
227 <                                            (.05 - .1*frandom()) > 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 232 | 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] -
236 <                                                        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 265 | 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 309 | 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 357 | 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