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.18 by greg, Fri May 15 13:07:55 1992 UTC vs.
Revision 2.28 by greg, Wed Dec 21 09:51:49 1994 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 + extern int  backvis;                    /* back faces visible? */
27 +
28 + static  gaussamp();
29 +
30   /*
31 < *      This routine uses portions of the reflection
32 < *  model described by Cook and Torrance.
29 < *      The computation of specular components has been simplified by
30 < *  numerous approximations and ommisions to improve speed.
31 > *      This routine implements the isotropic Gaussian
32 > *  model described by Ward in Siggraph `92 article.
33   *      We orient the surface towards the incoming ray, so a single
34   *  surface can be used to represent an infinitely thin object.
35   *
# Line 38 | Line 40 | extern double  specjitter;             /* specular sampling jitte
40   *      red     grn     blu     rspec   rough   trans   tspec
41   */
42  
41 #define  BSPEC(m)       (6.0)           /* specularity parameter b */
42
43                                  /* specularity flags */
44   #define  SP_REFL        01              /* has reflected specular component */
45   #define  SP_TRAN        02              /* has transmitted specular */
# Line 104 | Line 104 | double  omega;                 /* light source size */
104                                                  /* + source if flat */
105                  if (np->specfl & SP_FLAT)
106                          dtmp += omega/(4.0*PI);
107 <                                                /* delta */
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 = 2.0 - 2.0*d2/sqrt(DOT(vtmp,vtmp));
112 >                d2 *= d2;
113 >                d2 = (DOT(vtmp,vtmp) - d2) / d2;
114                                                  /* gaussian */
115                  dtmp = exp(-d2/dtmp)/(4.*PI*dtmp);
116                                                  /* worth using? */
# Line 135 | Line 136 | double  omega;                 /* light source size */
136                   *  is always modified by material color.
137                   */
138                                                  /* roughness + source */
139 <                dtmp = np->alpha2/4.0 + omega/PI;
139 >                dtmp = np->alpha2 + omega/PI;
140                                                  /* gaussian */
141 <                dtmp = exp((2.*DOT(np->prdir,ldir)-2.)/dtmp)/(4.*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);
# Line 155 | Line 156 | register RAY  *r;
156   {
157          NORMDAT  nd;
158          double  transtest, transdist;
158        double  dtmp;
159          COLOR  ctmp;
160          register int  i;
161                                                  /* easy shadow test */
162          if (r->crtype & SHADOW && m->otype != MAT_TRANS)
163 <                return;
163 >                return(1);
164  
165          if (m->oargs.nfargs != (m->otype == MAT_TRANS ? 7 : 5))
166                  objerror(m, USER, "bad number of arguments");
# Line 175 | Line 175 | register RAY  *r;
175          nd.alpha2 = m->oargs.farg[4];
176          if ((nd.alpha2 *= nd.alpha2) <= FTINY)
177                  nd.specfl |= SP_PURE;
178 <                                                /* reorient if necessary */
179 <        if (r->rod < 0.0)
180 <                flipsurface(r);
178 >                                                /* check for back side */
179 >        if (r->rod < 0.0) {
180 >                if (!backvis && m->otype != MAT_TRANS) {
181 >                        raytrans(r);
182 >                        return(1);
183 >                }
184 >                flipsurface(r);                 /* reorient if backvis */
185 >        }
186                                                  /* get modifiers */
187          raytexture(r, m->omod);
188          nd.pdot = raynormal(nd.pnorm, r);       /* perturb normal */
# Line 185 | Line 190 | register RAY  *r;
190                  nd.pdot = .001;                 /* non-zero for dirnorm() */
191          multcolor(nd.mcolor, r->pcol);          /* modify material color */
192          transtest = 0;
193 +        transdist = r->rot;
194                                                  /* get specular component */
195          if ((nd.rspec = m->oargs.farg[3]) > FTINY) {
196                  nd.specfl |= SP_REFL;
# Line 194 | Line 200 | register RAY  *r;
200                  else
201                          setcolor(nd.scolor, 1.0, 1.0, 1.0);
202                  scalecolor(nd.scolor, nd.rspec);
197                                                /* improved model */
198                dtmp = exp(-BSPEC(m)*nd.pdot);
199                for (i = 0; i < 3; i++)
200                        colval(nd.scolor,i) += (1.0-colval(nd.scolor,i))*dtmp;
201                nd.rspec += (1.0-nd.rspec)*dtmp;
203                                                  /* check threshold */
204 <                if (!(nd.specfl & SP_PURE) &&
204 <                                specthresh > FTINY &&
205 <                                (specthresh >= 1.-FTINY ||
206 <                                specthresh + .05 - .1*frandom() > nd.rspec))
204 >                if (!(nd.specfl & SP_PURE) && specthresh >= nd.rspec-FTINY)
205                          nd.specfl |= SP_RBLT;
206                                                  /* compute reflected ray */
207                  for (i = 0; i < 3; i++)
# Line 230 | Line 228 | register RAY  *r;
228                  if (nd.tspec > FTINY) {
229                          nd.specfl |= SP_TRAN;
230                                                          /* check threshold */
231 <                        if (!(nd.specfl & SP_PURE) && specthresh > FTINY &&
232 <                                        (specthresh >= 1.-FTINY ||
235 <                                specthresh + .05 - .1*frandom() > nd.tspec))
231 >                        if (!(nd.specfl & SP_PURE) &&
232 >                                        specthresh >= nd.tspec-FTINY)
233                                  nd.specfl |= SP_TBLT;
234                          if (r->crtype & SHADOW ||
235                                          DOT(r->pert,r->pert) <= FTINY*FTINY) {
# Line 240 | Line 237 | register RAY  *r;
237                                  transtest = 2;
238                          } else {
239                                  for (i = 0; i < 3; i++)         /* perturb */
240 <                                        nd.prdir[i] = r->rdir[i] -
244 <                                                        0.5*r->pert[i];
240 >                                        nd.prdir[i] = r->rdir[i] - r->pert[i];
241                                  if (DOT(nd.prdir, r->ron) < -FTINY)
242                                          normalize(nd.prdir);    /* OK */
243                                  else
# Line 266 | Line 262 | register RAY  *r;
262                  transtest = 0;
263  
264          if (r->crtype & SHADOW)                 /* the rest is shadow */
265 <                return;
265 >                return(1);
266                                                  /* diffuse reflection */
267          nd.rdiff = 1.0 - nd.trans - nd.rspec;
268  
269          if (nd.specfl & SP_PURE && nd.rdiff <= FTINY && nd.tdiff <= FTINY)
270 <                return;                         /* 100% pure specular */
270 >                return(1);                      /* 100% pure specular */
271  
272          if (r->ro != NULL && (r->ro->otype == OBJ_FACE ||
273                          r->ro->otype == OBJ_RING))
# Line 305 | Line 301 | register RAY  *r;
301                                          /* check distance */
302          if (transtest > bright(r->rcol))
303                  r->rt = transdist;
304 +
305 +        return(1);
306   }
307  
308  
# 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