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.9 by greg, Thu Jan 16 12:05:29 1992 UTC vs.
Revision 2.24 by greg, Mon Mar 8 12:37:27 1993 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines