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.7 by greg, Wed Jan 15 11:41:44 1992 UTC vs.
Revision 2.38 by greg, Sat Feb 22 02:07:29 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1992 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   *  normal.c - shading function for normal materials.
6   *
# Line 14 | Line 11 | static char SCCSid[] = "$SunId$ LBL";
11   *     Later changes described in delta comments.
12   */
13  
14 + /* ====================================================================
15 + * The Radiance Software License, Version 1.0
16 + *
17 + * Copyright (c) 1990 - 2002 The Regents of the University of California,
18 + * through Lawrence Berkeley National Laboratory.   All rights reserved.
19 + *
20 + * Redistribution and use in source and binary forms, with or without
21 + * modification, are permitted provided that the following conditions
22 + * are met:
23 + *
24 + * 1. Redistributions of source code must retain the above copyright
25 + *         notice, this list of conditions and the following disclaimer.
26 + *
27 + * 2. Redistributions in binary form must reproduce the above copyright
28 + *       notice, this list of conditions and the following disclaimer in
29 + *       the documentation and/or other materials provided with the
30 + *       distribution.
31 + *
32 + * 3. The end-user documentation included with the redistribution,
33 + *           if any, must include the following acknowledgment:
34 + *             "This product includes Radiance software
35 + *                 (http://radsite.lbl.gov/)
36 + *                 developed by the Lawrence Berkeley National Laboratory
37 + *               (http://www.lbl.gov/)."
38 + *       Alternately, this acknowledgment may appear in the software itself,
39 + *       if and wherever such third-party acknowledgments normally appear.
40 + *
41 + * 4. The names "Radiance," "Lawrence Berkeley National Laboratory"
42 + *       and "The Regents of the University of California" must
43 + *       not be used to endorse or promote products derived from this
44 + *       software without prior written permission. For written
45 + *       permission, please contact [email protected].
46 + *
47 + * 5. Products derived from this software may not be called "Radiance",
48 + *       nor may "Radiance" appear in their name, without prior written
49 + *       permission of Lawrence Berkeley National Laboratory.
50 + *
51 + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
52 + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
53 + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
54 + * DISCLAIMED.   IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR
55 + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
56 + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
57 + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
58 + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
59 + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
60 + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
61 + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
62 + * SUCH DAMAGE.
63 + * ====================================================================
64 + *
65 + * This software consists of voluntary contributions made by many
66 + * individuals on behalf of Lawrence Berkeley National Laboratory.   For more
67 + * information on Lawrence Berkeley National Laboratory, please see
68 + * <http://www.lbl.gov/>.
69 + */
70 +
71   #include  "ray.h"
72  
73   #include  "otypes.h"
74  
75   #include  "random.h"
76  
77 < extern double  specthresh;              /* specular sampling threshold */
78 < extern double  specjitter;              /* specular sampling jitter */
77 > #ifndef  MAXITER
78 > #define  MAXITER        10              /* maximum # specular ray attempts */
79 > #endif
80 >                                        /* estimate of Fresnel function */
81 > #define  FRESNE(ci)     (exp(-6.0*(ci)) - 0.00247875217)
82  
83 + static void  gaussamp();
84 +
85   /*
86 < *      This routine uses portions of the reflection
87 < *  model described by Cook and Torrance.
29 < *      The computation of specular components has been simplified by
30 < *  numerous approximations and ommisions to improve speed.
86 > *      This routine implements the isotropic Gaussian
87 > *  model described by Ward in Siggraph `92 article.
88   *      We orient the surface towards the incoming ray, so a single
89   *  surface can be used to represent an infinitely thin object.
90   *
# Line 38 | Line 95 | extern double  specjitter;             /* specular sampling jitte
95   *      red     grn     blu     rspec   rough   trans   tspec
96   */
97  
41 #define  BSPEC(m)       (6.0)           /* specularity parameter b */
42
98                                  /* specularity flags */
99   #define  SP_REFL        01              /* has reflected specular component */
100   #define  SP_TRAN        02              /* has transmitted specular */
101 < #define  SP_PURE        010             /* purely specular (zero roughness) */
102 < #define  SP_FLAT        020             /* flat reflecting surface */
103 < #define  SP_RBLT        040             /* reflection below sample threshold */
104 < #define  SP_TBLT        0100            /* transmission below threshold */
101 > #define  SP_PURE        04              /* purely specular (zero roughness) */
102 > #define  SP_FLAT        010             /* flat reflecting surface */
103 > #define  SP_RBLT        020             /* reflection below sample threshold */
104 > #define  SP_TBLT        040             /* transmission below threshold */
105  
106   typedef struct {
107          OBJREC  *mp;            /* material pointer */
108 +        RAY  *rp;               /* ray pointer */
109          short  specfl;          /* specularity flags, defined above */
110          COLOR  mcolor;          /* color of this material */
111          COLOR  scolor;          /* color of specular component */
# Line 64 | Line 120 | typedef struct {
120   }  NORMDAT;             /* normal material data */
121  
122  
123 + static void
124   dirnorm(cval, np, ldir, omega)          /* compute source contribution */
125   COLOR  cval;                    /* returned coefficient */
126   register NORMDAT  *np;          /* material data */
# Line 71 | Line 128 | FVECT  ldir;                   /* light source direction */
128   double  omega;                  /* light source size */
129   {
130          double  ldot;
131 <        double  dtmp;
132 <        int     i;
131 >        double  ldiff;
132 >        double  dtmp, d2;
133 >        FVECT  vtmp;
134          COLOR  ctmp;
135  
136          setcolor(cval, 0.0, 0.0, 0.0);
# Line 82 | Line 140 | double  omega;                 /* light source size */
140          if (ldot < 0.0 ? np->trans <= FTINY : np->trans >= 1.0-FTINY)
141                  return;         /* wrong side */
142  
143 <        if (ldot > FTINY && np->rdiff > FTINY) {
143 >                                /* Fresnel estimate */
144 >        ldiff = np->rdiff;
145 >        if (np->specfl & SP_PURE && (np->rspec > FTINY & ldiff > FTINY))
146 >                ldiff *= 1. - FRESNE(fabs(ldot));
147 >
148 >        if (ldot > FTINY && ldiff > FTINY) {
149                  /*
150                   *  Compute and add diffuse reflected component to returned
151                   *  color.  The diffuse reflected component will always be
152                   *  modified by the color of the material.
153                   */
154                  copycolor(ctmp, np->mcolor);
155 <                dtmp = ldot * omega * np->rdiff / PI;
155 >                dtmp = ldot * omega * ldiff / PI;
156                  scalecolor(ctmp, dtmp);
157                  addcolor(cval, ctmp);
158          }
# Line 99 | Line 162 | double  omega;                 /* light source size */
162                   *  gaussian distribution model.
163                   */
164                                                  /* roughness */
165 <                dtmp = 2.0*np->alpha2;
165 >                dtmp = np->alpha2;
166                                                  /* + source if flat */
167                  if (np->specfl & SP_FLAT)
168 <                        dtmp += omega/(2.0*PI);
168 >                        dtmp += omega/(4.0*PI);
169 >                                                /* half vector */
170 >                vtmp[0] = ldir[0] - np->rp->rdir[0];
171 >                vtmp[1] = ldir[1] - np->rp->rdir[1];
172 >                vtmp[2] = ldir[2] - np->rp->rdir[2];
173 >                d2 = DOT(vtmp, np->pnorm);
174 >                d2 *= d2;
175 >                d2 = (DOT(vtmp,vtmp) - d2) / d2;
176                                                  /* gaussian */
177 <                dtmp = exp((DOT(np->vrefl,ldir)-1.)/dtmp)/(2.*PI)/dtmp;
177 >                dtmp = exp(-d2/dtmp)/(4.*PI*dtmp);
178                                                  /* worth using? */
179                  if (dtmp > FTINY) {
180                          copycolor(ctmp, np->scolor);
181 <                        dtmp *= omega / np->pdot;
181 >                        dtmp *= omega * sqrt(ldot/np->pdot);
182                          scalecolor(ctmp, dtmp);
183                          addcolor(cval, ctmp);
184                  }
# Line 128 | Line 198 | double  omega;                 /* light source size */
198                   *  is always modified by material color.
199                   */
200                                                  /* roughness + source */
201 <                dtmp = np->alpha2 + omega/(2.0*PI);
201 >                dtmp = np->alpha2 + omega/PI;
202                                                  /* gaussian */
203 <                dtmp = exp((DOT(np->prdir,ldir)-1.)/dtmp)/(2.*PI)/dtmp;
203 >                dtmp = exp((2.*DOT(np->prdir,ldir)-2.)/dtmp)/(PI*dtmp);
204                                                  /* worth using? */
205                  if (dtmp > FTINY) {
206                          copycolor(ctmp, np->mcolor);
207 <                        dtmp *= np->tspec * omega / np->pdot;
207 >                        dtmp *= np->tspec * omega * sqrt(-ldot/np->pdot);
208                          scalecolor(ctmp, dtmp);
209                          addcolor(cval, ctmp);
210                  }
# Line 142 | Line 212 | double  omega;                 /* light source size */
212   }
213  
214  
215 + int
216   m_normal(m, r)                  /* color a ray that hit something normal */
217   register OBJREC  *m;
218   register RAY  *r;
219   {
220          NORMDAT  nd;
221 +        double  fest;
222          double  transtest, transdist;
223 <        double  dtmp;
223 >        double  mirtest, mirdist;
224 >        int     hastexture;
225 >        double  d;
226          COLOR  ctmp;
227          register int  i;
228                                                  /* easy shadow test */
229          if (r->crtype & SHADOW && m->otype != MAT_TRANS)
230 <                return;
230 >                return(1);
231  
232          if (m->oargs.nfargs != (m->otype == MAT_TRANS ? 7 : 5))
233                  objerror(m, USER, "bad number of arguments");
234 +                                                /* check for back side */
235 +        if (r->rod < 0.0) {
236 +                if (!backvis && m->otype != MAT_TRANS) {
237 +                        raytrans(r);
238 +                        return(1);
239 +                }
240 +                flipsurface(r);                 /* reorient if backvis */
241 +        }
242          nd.mp = m;
243 +        nd.rp = r;
244                                                  /* get material color */
245          setcolor(nd.mcolor, m->oargs.farg[0],
246                             m->oargs.farg[1],
# Line 167 | Line 250 | register RAY  *r;
250          nd.alpha2 = m->oargs.farg[4];
251          if ((nd.alpha2 *= nd.alpha2) <= FTINY)
252                  nd.specfl |= SP_PURE;
253 <                                                /* reorient if necessary */
254 <        if (r->rod < 0.0)
172 <                flipsurface(r);
253 >        if (r->ro != NULL && isflat(r->ro->otype))
254 >                nd.specfl |= SP_FLAT;
255                                                  /* get modifiers */
256          raytexture(r, m->omod);
257 <        nd.pdot = raynormal(nd.pnorm, r);       /* perturb normal */
257 >        if (hastexture = DOT(r->pert,r->pert) > FTINY*FTINY)
258 >                nd.pdot = raynormal(nd.pnorm, r);       /* perturb normal */
259 >        else {
260 >                VCOPY(nd.pnorm, r->ron);
261 >                nd.pdot = r->rod;
262 >        }
263          if (nd.pdot < .001)
264                  nd.pdot = .001;                 /* non-zero for dirnorm() */
265          multcolor(nd.mcolor, r->pcol);          /* modify material color */
266 <        transtest = 0;
267 <                                                /* get specular component */
268 <        if ((nd.rspec = m->oargs.farg[3]) > FTINY) {
269 <                nd.specfl |= SP_REFL;
270 <                                                /* compute specular color */
271 <                if (m->otype == MAT_METAL)
272 <                        copycolor(nd.scolor, nd.mcolor);
273 <                else
274 <                        setcolor(nd.scolor, 1.0, 1.0, 1.0);
188 <                scalecolor(nd.scolor, nd.rspec);
189 <                                                /* improved model */
190 <                dtmp = exp(-BSPEC(m)*nd.pdot);
191 <                for (i = 0; i < 3; i++)
192 <                        colval(nd.scolor,i) += (1.0-colval(nd.scolor,i))*dtmp;
193 <                nd.rspec += (1.0-nd.rspec)*dtmp;
194 <                                                /* check threshold */
195 <                if (specthresh > FTINY &&
196 <                                ((specthresh >= 1.-FTINY ||
197 <                                specthresh + (.1 - .2*urand(8199+samplendx))
198 <                                        > nd.rspec)))
199 <                        nd.specfl |= SP_RBLT;
200 <                                                /* compute reflected ray */
201 <                for (i = 0; i < 3; i++)
202 <                        nd.vrefl[i] = r->rdir[i] + 2.0*nd.pdot*nd.pnorm[i];
203 <                if (DOT(nd.vrefl, r->ron) <= FTINY)     /* penetration? */
204 <                        for (i = 0; i < 3; i++)         /* safety measure */
205 <                                nd.vrefl[i] = r->rdir[i] + 2.*r->rod*r->ron[i];
206 <
207 <                if (!(r->crtype & SHADOW) && nd.specfl & SP_PURE) {
208 <                        RAY  lr;
209 <                        if (rayorigin(&lr, r, REFLECTED, nd.rspec) == 0) {
210 <                                VCOPY(lr.rdir, nd.vrefl);
211 <                                rayvalue(&lr);
212 <                                multcolor(lr.rcol, nd.scolor);
213 <                                addcolor(r->rcol, lr.rcol);
214 <                        }
215 <                }
216 <        }
266 >        mirtest = transtest = 0;
267 >        mirdist = transdist = r->rot;
268 >        nd.rspec = m->oargs.farg[3];
269 >                                                /* compute Fresnel approx. */
270 >        if (nd.specfl & SP_PURE && nd.rspec > FTINY) {
271 >                fest = FRESNE(r->rod);
272 >                nd.rspec += fest*(1. - nd.rspec);
273 >        } else
274 >                fest = 0.;
275                                                  /* compute transmission */
276          if (m->otype == MAT_TRANS) {
277                  nd.trans = m->oargs.farg[5]*(1.0 - nd.rspec);
# Line 222 | Line 280 | register RAY  *r;
280                  if (nd.tspec > FTINY) {
281                          nd.specfl |= SP_TRAN;
282                                                          /* check threshold */
283 <                        if (specthresh > FTINY &&
284 <                                        ((specthresh >= 1.-FTINY ||
227 <                                        specthresh +
228 <                                            (.1 - .2*urand(7241+samplendx))
229 <                                                > nd.tspec)))
283 >                        if (!(nd.specfl & SP_PURE) &&
284 >                                        specthresh >= nd.tspec-FTINY)
285                                  nd.specfl |= SP_TBLT;
286 <                        if (r->crtype & SHADOW ||
232 <                                        DOT(r->pert,r->pert) <= FTINY*FTINY) {
286 >                        if (!hastexture || r->crtype & SHADOW) {
287                                  VCOPY(nd.prdir, r->rdir);
288                                  transtest = 2;
289                          } else {
290                                  for (i = 0; i < 3; i++)         /* perturb */
291 <                                        nd.prdir[i] = r->rdir[i] -
238 <                                                        .75*r->pert[i];
291 >                                        nd.prdir[i] = r->rdir[i] - r->pert[i];
292                                  if (DOT(nd.prdir, r->ron) < -FTINY)
293                                          normalize(nd.prdir);    /* OK */
294                                  else
# Line 245 | Line 298 | register RAY  *r;
298          } else
299                  nd.tdiff = nd.tspec = nd.trans = 0.0;
300                                                  /* transmitted ray */
301 <        if ((nd.specfl&(SP_TRAN|SP_PURE)) == (SP_TRAN|SP_PURE)) {
301 >        if ((nd.specfl&(SP_TRAN|SP_PURE|SP_TBLT)) == (SP_TRAN|SP_PURE)) {
302                  RAY  lr;
303                  if (rayorigin(&lr, r, TRANS, nd.tspec) == 0) {
304                          VCOPY(lr.rdir, nd.prdir);
# Line 256 | Line 309 | register RAY  *r;
309                          transtest *= bright(lr.rcol);
310                          transdist = r->rot + lr.rt;
311                  }
312 <        }
312 >        } else
313 >                transtest = 0;
314  
315 <        if (r->crtype & SHADOW)                 /* the rest is shadow */
316 <                return;
315 >        if (r->crtype & SHADOW) {               /* the rest is shadow */
316 >                r->rt = transdist;
317 >                return(1);
318 >        }
319 >                                                /* get specular reflection */
320 >        if (nd.rspec > FTINY) {
321 >                nd.specfl |= SP_REFL;
322 >                                                /* compute specular color */
323 >                if (m->otype != MAT_METAL) {
324 >                        setcolor(nd.scolor, nd.rspec, nd.rspec, nd.rspec);
325 >                } else if (fest > FTINY) {
326 >                        d = nd.rspec*(1. - fest);
327 >                        for (i = 0; i < 3; i++)
328 >                                nd.scolor[i] = fest + nd.mcolor[i]*d;
329 >                } else {
330 >                        copycolor(nd.scolor, nd.mcolor);
331 >                        scalecolor(nd.scolor, nd.rspec);
332 >                }
333 >                                                /* check threshold */
334 >                if (!(nd.specfl & SP_PURE) && specthresh >= nd.rspec-FTINY)
335 >                        nd.specfl |= SP_RBLT;
336 >                                                /* compute reflected ray */
337 >                for (i = 0; i < 3; i++)
338 >                        nd.vrefl[i] = r->rdir[i] + 2.*nd.pdot*nd.pnorm[i];
339 >                                                /* penetration? */
340 >                if (hastexture && DOT(nd.vrefl, r->ron) <= FTINY)
341 >                        for (i = 0; i < 3; i++)         /* safety measure */
342 >                                nd.vrefl[i] = r->rdir[i] + 2.*r->rod*r->ron[i];
343 >        }
344 >                                                /* reflected ray */
345 >        if ((nd.specfl&(SP_REFL|SP_PURE|SP_RBLT)) == (SP_REFL|SP_PURE)) {
346 >                RAY  lr;
347 >                if (rayorigin(&lr, r, REFLECTED, nd.rspec) == 0) {
348 >                        VCOPY(lr.rdir, nd.vrefl);
349 >                        rayvalue(&lr);
350 >                        multcolor(lr.rcol, nd.scolor);
351 >                        addcolor(r->rcol, lr.rcol);
352 >                        if (!hastexture && nd.specfl & SP_FLAT) {
353 >                                mirtest = 2.*bright(lr.rcol);
354 >                                mirdist = r->rot + lr.rt;
355 >                        }
356 >                }
357 >        }
358                                                  /* diffuse reflection */
359          nd.rdiff = 1.0 - nd.trans - nd.rspec;
360  
361          if (nd.specfl & SP_PURE && nd.rdiff <= FTINY && nd.tdiff <= FTINY)
362 <                return;                         /* 100% pure specular */
362 >                return(1);                      /* 100% pure specular */
363  
364 <        if (r->ro->otype == OBJ_FACE || r->ro->otype == OBJ_RING)
365 <                nd.specfl |= SP_FLAT;
364 >        if (!(nd.specfl & SP_PURE))
365 >                gaussamp(r, &nd);               /* checks *BLT flags */
366  
272        if (nd.specfl & (SP_REFL|SP_TRAN) && !(nd.specfl & SP_PURE))
273                gaussamp(r, &nd);
274
367          if (nd.rdiff > FTINY) {         /* ambient from this side */
368 <                ambient(ctmp, r);
368 >                ambient(ctmp, r, hastexture?nd.pnorm:r->ron);
369                  if (nd.specfl & SP_RBLT)
370                          scalecolor(ctmp, 1.0-nd.trans);
371                  else
# Line 283 | Line 375 | register RAY  *r;
375          }
376          if (nd.tdiff > FTINY) {         /* ambient from other side */
377                  flipsurface(r);
378 <                ambient(ctmp, r);
378 >                if (hastexture) {
379 >                        FVECT  bnorm;
380 >                        bnorm[0] = -nd.pnorm[0];
381 >                        bnorm[1] = -nd.pnorm[1];
382 >                        bnorm[2] = -nd.pnorm[2];
383 >                        ambient(ctmp, r, bnorm);
384 >                } else
385 >                        ambient(ctmp, r, r->ron);
386                  if (nd.specfl & SP_TBLT)
387                          scalecolor(ctmp, nd.trans);
388                  else
# Line 295 | Line 394 | register RAY  *r;
394                                          /* add direct component */
395          direct(r, dirnorm, &nd);
396                                          /* check distance */
397 <        if (transtest > bright(r->rcol))
397 >        d = bright(r->rcol);
398 >        if (transtest > d)
399                  r->rt = transdist;
400 +        else if (mirtest > d)
401 +                r->rt = mirdist;
402 +
403 +        return(1);
404   }
405  
406  
407 < static
407 > static void
408   gaussamp(r, np)                 /* sample gaussian specular */
409   RAY  *r;
410   register NORMDAT  *np;
# Line 309 | Line 413 | register NORMDAT  *np;
413          FVECT  u, v, h;
414          double  rv[2];
415          double  d, sinp, cosp;
416 +        int  niter;
417          register int  i;
418 +                                        /* quick test */
419 +        if ((np->specfl & (SP_REFL|SP_RBLT)) != SP_REFL &&
420 +                        (np->specfl & (SP_TRAN|SP_TBLT)) != SP_TRAN)
421 +                return;
422                                          /* set up sample coordinates */
423          v[0] = v[1] = v[2] = 0.0;
424          for (i = 0; i < 3; i++)
# Line 323 | Line 432 | register NORMDAT  *np;
432          if ((np->specfl & (SP_REFL|SP_RBLT)) == SP_REFL &&
433                          rayorigin(&sr, r, SPECULAR, np->rspec) == 0) {
434                  dimlist[ndims++] = (int)np->mp;
435 <                d = urand(ilhash(dimlist,ndims)+samplendx);
436 <                multisamp(rv, 2, d);
437 <                d = 2.0*PI * rv[0];
438 <                cosp = cos(d);
439 <                sinp = sin(d);
440 <                rv[1] = 1.0 - specjitter*rv[1];
441 <                if (rv[1] <= FTINY)
442 <                        d = 1.0;
443 <                else
444 <                        d = sqrt( np->alpha2 * -log(rv[1]) );
445 <                for (i = 0; i < 3; i++)
446 <                        h[i] = np->pnorm[i] + d*(cosp*u[i] + sinp*v[i]);
447 <                d = -2.0 * DOT(h, r->rdir) / (1.0 + d*d);
448 <                for (i = 0; i < 3; i++)
449 <                        sr.rdir[i] = r->rdir[i] + d*h[i];
450 <                if (DOT(sr.rdir, r->ron) <= FTINY)
451 <                        VCOPY(sr.rdir, np->vrefl);      /* jitter no good */
452 <                rayvalue(&sr);
453 <                multcolor(sr.rcol, np->scolor);
454 <                addcolor(r->rcol, sr.rcol);
435 >                for (niter = 0; niter < MAXITER; niter++) {
436 >                        if (niter)
437 >                                d = frandom();
438 >                        else
439 >                                d = urand(ilhash(dimlist,ndims)+samplendx);
440 >                        multisamp(rv, 2, d);
441 >                        d = 2.0*PI * rv[0];
442 >                        cosp = tcos(d);
443 >                        sinp = tsin(d);
444 >                        rv[1] = 1.0 - specjitter*rv[1];
445 >                        if (rv[1] <= FTINY)
446 >                                d = 1.0;
447 >                        else
448 >                                d = sqrt( np->alpha2 * -log(rv[1]) );
449 >                        for (i = 0; i < 3; i++)
450 >                                h[i] = np->pnorm[i] + d*(cosp*u[i] + sinp*v[i]);
451 >                        d = -2.0 * DOT(h, r->rdir) / (1.0 + d*d);
452 >                        for (i = 0; i < 3; i++)
453 >                                sr.rdir[i] = r->rdir[i] + d*h[i];
454 >                        if (DOT(sr.rdir, r->ron) > FTINY) {
455 >                                rayvalue(&sr);
456 >                                multcolor(sr.rcol, np->scolor);
457 >                                addcolor(r->rcol, sr.rcol);
458 >                                break;
459 >                        }
460 >                }
461                  ndims--;
462          }
463                                          /* compute transmission */
464 +        if ((np->specfl & (SP_TRAN|SP_TBLT)) == SP_TRAN &&
465 +                        rayorigin(&sr, r, SPECULAR, np->tspec) == 0) {
466 +                dimlist[ndims++] = (int)np->mp;
467 +                for (niter = 0; niter < MAXITER; niter++) {
468 +                        if (niter)
469 +                                d = frandom();
470 +                        else
471 +                                d = urand(ilhash(dimlist,ndims)+1823+samplendx);
472 +                        multisamp(rv, 2, d);
473 +                        d = 2.0*PI * rv[0];
474 +                        cosp = tcos(d);
475 +                        sinp = tsin(d);
476 +                        rv[1] = 1.0 - specjitter*rv[1];
477 +                        if (rv[1] <= FTINY)
478 +                                d = 1.0;
479 +                        else
480 +                                d = sqrt( np->alpha2 * -log(rv[1]) );
481 +                        for (i = 0; i < 3; i++)
482 +                                sr.rdir[i] = np->prdir[i] + d*(cosp*u[i] + sinp*v[i]);
483 +                        if (DOT(sr.rdir, r->ron) < -FTINY) {
484 +                                normalize(sr.rdir);     /* OK, normalize */
485 +                                rayvalue(&sr);
486 +                                scalecolor(sr.rcol, np->tspec);
487 +                                multcolor(sr.rcol, np->mcolor); /* modified */
488 +                                addcolor(r->rcol, sr.rcol);
489 +                                break;
490 +                        }
491 +                }
492 +                ndims--;
493 +        }
494   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines