ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/aniso.c
(Generate patch)

Comparing ray/src/rt/aniso.c (file contents):
Revision 2.2 by greg, Sat Jan 4 23:36:40 1992 UTC vs.
Revision 2.34 by greg, Sat Feb 22 02:07:28 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   *  Shading functions for anisotropic materials.
6   */
7  
8 + /* ====================================================================
9 + * The Radiance Software License, Version 1.0
10 + *
11 + * Copyright (c) 1990 - 2002 The Regents of the University of California,
12 + * through Lawrence Berkeley National Laboratory.   All rights reserved.
13 + *
14 + * Redistribution and use in source and binary forms, with or without
15 + * modification, are permitted provided that the following conditions
16 + * are met:
17 + *
18 + * 1. Redistributions of source code must retain the above copyright
19 + *         notice, this list of conditions and the following disclaimer.
20 + *
21 + * 2. Redistributions in binary form must reproduce the above copyright
22 + *       notice, this list of conditions and the following disclaimer in
23 + *       the documentation and/or other materials provided with the
24 + *       distribution.
25 + *
26 + * 3. The end-user documentation included with the redistribution,
27 + *           if any, must include the following acknowledgment:
28 + *             "This product includes Radiance software
29 + *                 (http://radsite.lbl.gov/)
30 + *                 developed by the Lawrence Berkeley National Laboratory
31 + *               (http://www.lbl.gov/)."
32 + *       Alternately, this acknowledgment may appear in the software itself,
33 + *       if and wherever such third-party acknowledgments normally appear.
34 + *
35 + * 4. The names "Radiance," "Lawrence Berkeley National Laboratory"
36 + *       and "The Regents of the University of California" must
37 + *       not be used to endorse or promote products derived from this
38 + *       software without prior written permission. For written
39 + *       permission, please contact [email protected].
40 + *
41 + * 5. Products derived from this software may not be called "Radiance",
42 + *       nor may "Radiance" appear in their name, without prior written
43 + *       permission of Lawrence Berkeley National Laboratory.
44 + *
45 + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
46 + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
47 + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
48 + * DISCLAIMED.   IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR
49 + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
50 + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
51 + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
52 + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
53 + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
54 + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
55 + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
56 + * SUCH DAMAGE.
57 + * ====================================================================
58 + *
59 + * This software consists of voluntary contributions made by many
60 + * individuals on behalf of Lawrence Berkeley National Laboratory.   For more
61 + * information on Lawrence Berkeley National Laboratory, please see
62 + * <http://www.lbl.gov/>.
63 + */
64 +
65   #include  "ray.h"
66  
67   #include  "otypes.h"
# Line 16 | Line 70 | static char SCCSid[] = "$SunId$ LBL";
70  
71   #include  "random.h"
72  
73 + #ifndef  MAXITER
74 + #define  MAXITER        10              /* maximum # specular ray attempts */
75 + #endif
76 +
77   /*
78 < *      This anisotropic reflection model uses a variant on the
79 < *  exponential Gaussian used in normal.c.
78 > *      This routine implements the anisotropic Gaussian
79 > *  model described by Ward in Siggraph `92 article.
80   *      We orient the surface towards the incoming ray, so a single
81   *  surface can be used to represent an infinitely thin object.
82   *
# Line 31 | Line 89 | static char SCCSid[] = "$SunId$ LBL";
89   *  8  red      grn     blu     rspec   u-rough v-rough trans   tspec
90   */
91  
34 #define  BSPEC(m)       (6.0)           /* specularity parameter b */
35
92                                  /* specularity flags */
93   #define  SP_REFL        01              /* has reflected specular component */
94   #define  SP_TRAN        02              /* has transmitted specular */
95 < #define  SP_PURE        010             /* purely specular (zero roughness) */
96 < #define  SP_BADU        020             /* bad u direction calculation */
97 < #define  SP_FLAT        040             /* reflecting surface is flat */
95 > #define  SP_FLAT        04              /* reflecting surface is flat */
96 > #define  SP_RBLT        010             /* reflection below sample threshold */
97 > #define  SP_TBLT        020             /* transmission below threshold */
98 > #define  SP_BADU        040             /* bad u direction calculation */
99  
100   typedef struct {
101          OBJREC  *mp;            /* material pointer */
# Line 46 | Line 103 | typedef struct {
103          short  specfl;          /* specularity flags, defined above */
104          COLOR  mcolor;          /* color of this material */
105          COLOR  scolor;          /* color of specular component */
106 +        FVECT  vrefl;           /* vector in reflected direction */
107          FVECT  prdir;           /* vector in transmitted direction */
108          FVECT  u, v;            /* u and v vectors orienting anisotropy */
109          double  u_alpha;        /* u roughness */
# Line 57 | Line 115 | typedef struct {
115          double  pdot;           /* perturbed dot product */
116   }  ANISODAT;            /* anisotropic material data */
117  
118 + static void     getacoords();
119 + static void     agaussamp();
120  
121 +
122 + static void
123   diraniso(cval, np, ldir, omega)         /* compute source contribution */
124   COLOR  cval;                    /* returned coefficient */
125   register ANISODAT  *np;         /* material data */
# Line 65 | Line 127 | FVECT  ldir;                   /* light source direction */
127   double  omega;                  /* light source size */
128   {
129          double  ldot;
130 <        double  dtmp, dtmp2;
130 >        double  dtmp, dtmp1, dtmp2;
131          FVECT  h;
132          double  au2, av2;
133          COLOR  ctmp;
# Line 88 | Line 150 | double  omega;                 /* light source size */
150                  scalecolor(ctmp, dtmp);
151                  addcolor(cval, ctmp);
152          }
153 <        if (ldot > FTINY && (np->specfl&(SP_REFL|SP_PURE|SP_BADU)) == SP_REFL) {
153 >        if (ldot > FTINY && (np->specfl&(SP_REFL|SP_BADU)) == SP_REFL) {
154                  /*
155                   *  Compute specular reflection coefficient using
156                   *  anisotropic gaussian distribution model.
# Line 98 | Line 160 | double  omega;                 /* light source size */
160                          au2 = av2 = omega/(4.0*PI);
161                  else
162                          au2 = av2 = 0.0;
163 <                au2 += np->u_alpha * np->u_alpha;
164 <                av2 += np->v_alpha * np->v_alpha;
163 >                au2 += np->u_alpha*np->u_alpha;
164 >                av2 += np->v_alpha*np->v_alpha;
165                                                  /* half vector */
166                  h[0] = ldir[0] - np->rp->rdir[0];
167                  h[1] = ldir[1] - np->rp->rdir[1];
168                  h[2] = ldir[2] - np->rp->rdir[2];
107                normalize(h);
169                                                  /* ellipse */
170 <                dtmp = DOT(np->u, h);
171 <                dtmp *= dtmp / au2;
170 >                dtmp1 = DOT(np->u, h);
171 >                dtmp1 *= dtmp1 / au2;
172                  dtmp2 = DOT(np->v, h);
173                  dtmp2 *= dtmp2 / av2;
174                                                  /* gaussian */
175 <                dtmp = (dtmp + dtmp2) / (1.0 + DOT(np->pnorm, h));
176 <                dtmp = exp(-2.0*dtmp) / (4.0*PI * sqrt(au2*av2));
175 >                dtmp = DOT(np->pnorm, h);
176 >                dtmp = (dtmp1 + dtmp2) / (dtmp*dtmp);
177 >                dtmp = exp(-dtmp) * (0.25/PI)
178 >                                * sqrt(ldot/(np->pdot*au2*av2));
179                                                  /* worth using? */
180                  if (dtmp > FTINY) {
181                          copycolor(ctmp, np->scolor);
182 <                        dtmp *= omega / np->pdot;
182 >                        dtmp *= omega;
183                          scalecolor(ctmp, dtmp);
184                          addcolor(cval, ctmp);
185                  }
# Line 130 | Line 193 | double  omega;                 /* light source size */
193                  scalecolor(ctmp, dtmp);
194                  addcolor(cval, ctmp);
195          }
196 <        if (ldot < -FTINY && (np->specfl&(SP_TRAN|SP_PURE|SP_BADU)) == SP_TRAN) {
196 >        if (ldot < -FTINY && (np->specfl&(SP_TRAN|SP_BADU)) == SP_TRAN) {
197                  /*
198                   *  Compute specular transmission.  Specular transmission
199                   *  is always modified by material color.
200                   */
201                                                  /* roughness + source */
202 +                au2 = av2 = omega / PI;
203 +                au2 += np->u_alpha*np->u_alpha;
204 +                av2 += np->v_alpha*np->v_alpha;
205 +                                                /* "half vector" */
206 +                h[0] = ldir[0] - np->prdir[0];
207 +                h[1] = ldir[1] - np->prdir[1];
208 +                h[2] = ldir[2] - np->prdir[2];
209 +                dtmp = DOT(h,h);
210 +                if (dtmp > FTINY*FTINY) {
211 +                        dtmp1 = DOT(h,np->pnorm);
212 +                        dtmp = 1.0 - dtmp1*dtmp1/dtmp;
213 +                        if (dtmp > FTINY*FTINY) {
214 +                                dtmp1 = DOT(h,np->u);
215 +                                dtmp1 *= dtmp1 / au2;
216 +                                dtmp2 = DOT(h,np->v);
217 +                                dtmp2 *= dtmp2 / av2;
218 +                                dtmp = (dtmp1 + dtmp2) / dtmp;
219 +                        }
220 +                } else
221 +                        dtmp = 0.0;
222                                                  /* gaussian */
223 <                dtmp = 0.0;
223 >                dtmp = exp(-dtmp) * (1.0/PI)
224 >                                * sqrt(-ldot/(np->pdot*au2*av2));
225                                                  /* worth using? */
226                  if (dtmp > FTINY) {
227                          copycolor(ctmp, np->mcolor);
228 <                        dtmp *= np->tspec * omega / np->pdot;
228 >                        dtmp *= np->tspec * omega;
229                          scalecolor(ctmp, dtmp);
230                          addcolor(cval, ctmp);
231                  }
# Line 149 | Line 233 | double  omega;                 /* light source size */
233   }
234  
235  
236 + int
237   m_aniso(m, r)                   /* shade ray that hit something anisotropic */
238   register OBJREC  *m;
239   register RAY  *r;
240   {
241          ANISODAT  nd;
157        double  transtest, transdist;
158        double  dtmp;
242          COLOR  ctmp;
243          register int  i;
244                                                  /* easy shadow test */
245 <        if (r->crtype & SHADOW && m->otype != MAT_TRANS2)
246 <                return;
245 >        if (r->crtype & SHADOW)
246 >                return(1);
247  
248          if (m->oargs.nfargs != (m->otype == MAT_TRANS2 ? 8 : 6))
249                  objerror(m, USER, "bad number of real arguments");
# Line 174 | Line 257 | register RAY  *r;
257          nd.specfl = 0;
258          nd.u_alpha = m->oargs.farg[4];
259          nd.v_alpha = m->oargs.farg[5];
260 <        if (nd.u_alpha <= FTINY || nd.v_alpha <= FTINY)
261 <                nd.specfl |= SP_PURE;
262 <                                                /* reorient if necessary */
263 <        if (r->rod < 0.0)
264 <                flipsurface(r);
260 >        if (nd.u_alpha < FTINY || nd.v_alpha <= FTINY)
261 >                objerror(m, USER, "roughness too small");
262 >                                                /* check for back side */
263 >        if (r->rod < 0.0) {
264 >                if (!backvis && m->otype != MAT_TRANS2) {
265 >                        raytrans(r);
266 >                        return(1);
267 >                }
268 >                flipsurface(r);                 /* reorient if backvis */
269 >        }
270                                                  /* get modifiers */
271          raytexture(r, m->omod);
272          nd.pdot = raynormal(nd.pnorm, r);       /* perturb normal */
273          if (nd.pdot < .001)
274                  nd.pdot = .001;                 /* non-zero for diraniso() */
275          multcolor(nd.mcolor, r->pcol);          /* modify material color */
188        transtest = 0;
276                                                  /* get specular component */
277          if ((nd.rspec = m->oargs.farg[3]) > FTINY) {
278                  nd.specfl |= SP_REFL;
# Line 195 | Line 282 | register RAY  *r;
282                  else
283                          setcolor(nd.scolor, 1.0, 1.0, 1.0);
284                  scalecolor(nd.scolor, nd.rspec);
285 <                                                /* improved model */
286 <                dtmp = exp(-BSPEC(m)*nd.pdot);
285 >                                                /* check threshold */
286 >                if (specthresh >= nd.rspec-FTINY)
287 >                        nd.specfl |= SP_RBLT;
288 >                                                /* compute refl. direction */
289                  for (i = 0; i < 3; i++)
290 <                        colval(nd.scolor,i) += (1.0-colval(nd.scolor,i))*dtmp;
291 <                nd.rspec += (1.0-nd.rspec)*dtmp;
292 <
293 <                if (!(r->crtype & SHADOW) && nd.specfl & SP_PURE) {
205 <                        RAY  lr;
206 <                        if (rayorigin(&lr, r, REFLECTED, nd.rspec) == 0) {
207 <                                for (i = 0; i < 3; i++)
208 <                                        lr.rdir[i] = r->rdir[i] +
209 <                                                2.0*nd.pdot*nd.pnorm[i];
210 <                                rayvalue(&lr);
211 <                                multcolor(lr.rcol, nd.scolor);
212 <                                addcolor(r->rcol, lr.rcol);
213 <                        }
214 <                }
290 >                        nd.vrefl[i] = r->rdir[i] + 2.0*nd.pdot*nd.pnorm[i];
291 >                if (DOT(nd.vrefl, r->ron) <= FTINY)     /* penetration? */
292 >                        for (i = 0; i < 3; i++)         /* safety measure */
293 >                                nd.vrefl[i] = r->rdir[i] + 2.*r->rod*r->ron[i];
294          }
295                                                  /* compute transmission */
296 <        if (m->otype == MAT_TRANS) {
296 >        if (m->otype == MAT_TRANS2) {
297                  nd.trans = m->oargs.farg[6]*(1.0 - nd.rspec);
298                  nd.tspec = nd.trans * m->oargs.farg[7];
299                  nd.tdiff = nd.trans - nd.tspec;
300                  if (nd.tspec > FTINY) {
301                          nd.specfl |= SP_TRAN;
302 <                        if (r->crtype & SHADOW ||
303 <                                        DOT(r->pert,r->pert) <= FTINY*FTINY) {
302 >                                                        /* check threshold */
303 >                        if (specthresh >= nd.tspec-FTINY)
304 >                                nd.specfl |= SP_TBLT;
305 >                        if (DOT(r->pert,r->pert) <= FTINY*FTINY) {
306                                  VCOPY(nd.prdir, r->rdir);
226                                transtest = 2;
307                          } else {
308                                  for (i = 0; i < 3; i++)         /* perturb */
309 <                                        nd.prdir[i] = r->rdir[i] -
310 <                                                        .75*r->pert[i];
311 <                                normalize(nd.prdir);
309 >                                        nd.prdir[i] = r->rdir[i] - r->pert[i];
310 >                                if (DOT(nd.prdir, r->ron) < -FTINY)
311 >                                        normalize(nd.prdir);    /* OK */
312 >                                else
313 >                                        VCOPY(nd.prdir, r->rdir);
314                          }
315                  }
316          } else
317                  nd.tdiff = nd.tspec = nd.trans = 0.0;
236                                                /* transmitted ray */
237        if ((nd.specfl&(SP_TRAN|SP_PURE)) == (SP_TRAN|SP_PURE)) {
238                RAY  lr;
239                if (rayorigin(&lr, r, TRANS, nd.tspec) == 0) {
240                        VCOPY(lr.rdir, nd.prdir);
241                        rayvalue(&lr);
242                        scalecolor(lr.rcol, nd.tspec);
243                        multcolor(lr.rcol, nd.mcolor);  /* modified by color */
244                        addcolor(r->rcol, lr.rcol);
245                        transtest *= bright(lr.rcol);
246                        transdist = r->rot + lr.rt;
247                }
248        }
318  
250        if (r->crtype & SHADOW)                 /* the rest is shadow */
251                return;
319                                                  /* diffuse reflection */
320          nd.rdiff = 1.0 - nd.trans - nd.rspec;
321  
322 <        if (nd.specfl & SP_PURE && nd.rdiff <= FTINY && nd.tdiff <= FTINY)
323 <                return;                         /* 100% pure specular */
322 >        if (r->ro != NULL && isflat(r->ro->otype))
323 >                nd.specfl |= SP_FLAT;
324  
325          getacoords(r, &nd);                     /* set up coordinates */
326  
327 <        if (nd.specfl & (SP_REFL|SP_TRAN) && !(nd.specfl & (SP_PURE|SP_BADU)))
327 >        if (nd.specfl & (SP_REFL|SP_TRAN) && !(nd.specfl & SP_BADU))
328                  agaussamp(r, &nd);
329  
330          if (nd.rdiff > FTINY) {         /* ambient from this side */
331 <                ambient(ctmp, r);
332 <                scalecolor(ctmp, nd.rdiff);
331 >                ambient(ctmp, r, nd.pnorm);
332 >                if (nd.specfl & SP_RBLT)
333 >                        scalecolor(ctmp, 1.0-nd.trans);
334 >                else
335 >                        scalecolor(ctmp, nd.rdiff);
336                  multcolor(ctmp, nd.mcolor);     /* modified by material color */
337                  addcolor(r->rcol, ctmp);        /* add to returned color */
338          }
339          if (nd.tdiff > FTINY) {         /* ambient from other side */
340 +                FVECT  bnorm;
341 +
342                  flipsurface(r);
343 <                ambient(ctmp, r);
344 <                scalecolor(ctmp, nd.tdiff);
343 >                bnorm[0] = -nd.pnorm[0];
344 >                bnorm[1] = -nd.pnorm[1];
345 >                bnorm[2] = -nd.pnorm[2];
346 >                ambient(ctmp, r, bnorm);
347 >                if (nd.specfl & SP_TBLT)
348 >                        scalecolor(ctmp, nd.trans);
349 >                else
350 >                        scalecolor(ctmp, nd.tdiff);
351                  multcolor(ctmp, nd.mcolor);     /* modified by color */
352                  addcolor(r->rcol, ctmp);
353                  flipsurface(r);
354          }
355                                          /* add direct component */
356          direct(r, diraniso, &nd);
357 <                                        /* check distance */
358 <        if (transtest > bright(r->rcol))
281 <                r->rt = transdist;
357 >
358 >        return(1);
359   }
360  
361  
362 < static
362 > static void
363   getacoords(r, np)               /* set up coordinate system */
364   RAY  *r;
365   register ANISODAT  *np;
# Line 300 | Line 377 | register ANISODAT  *np;
377                  np->specfl |= SP_BADU;
378                  return;
379          }
380 <        multv3(np->u, np->u, mf->f->xfm);
380 >        if (mf->f != &unitxf)
381 >                multv3(np->u, np->u, mf->f->xfm);
382          fcross(np->v, np->pnorm, np->u);
383          if (normalize(np->v) == 0.0) {
384                  objerror(np->mp, WARNING, "illegal orientation vector");
# Line 311 | Line 389 | register ANISODAT  *np;
389   }
390  
391  
392 < static
392 > static void
393   agaussamp(r, np)                /* sample anisotropic gaussian specular */
394   RAY  *r;
395   register ANISODAT  *np;
# Line 320 | Line 398 | register ANISODAT  *np;
398          FVECT  h;
399          double  rv[2];
400          double  d, sinp, cosp;
401 <        int  confuse;
401 >        int  niter;
402          register int  i;
403                                          /* compute reflection */
404 <        if (np->specfl & SP_REFL &&
404 >        if ((np->specfl & (SP_REFL|SP_RBLT)) == SP_REFL &&
405                          rayorigin(&sr, r, SPECULAR, np->rspec) == 0) {
328                confuse = 0;
406                  dimlist[ndims++] = (int)np->mp;
407 <        refagain:
408 <                dimlist[ndims] = confuse += 3601;
409 <                d = urand(ilhash(dimlist,ndims+1)+samplendx);
410 <                multisamp(rv, 2, d);
411 <                d = 2.0*PI * rv[0];
412 <                cosp = np->u_alpha * cos(d);
413 <                sinp = np->v_alpha * sin(d);
414 <                d = sqrt(cosp*cosp + sinp*sinp);
415 <                cosp /= d;
416 <                sinp /= d;
417 <                if (rv[1] <= FTINY)
418 <                        d = 1.0;
419 <                else
420 <                        d = sqrt( -log(rv[1]) /
421 <                                (cosp*cosp/(np->u_alpha*np->u_alpha) +
422 <                                 sinp*sinp/(np->v_alpha*np->v_alpha)) );
423 <                for (i = 0; i < 3; i++)
424 <                        h[i] = np->pnorm[i] +
407 >                for (niter = 0; niter < MAXITER; niter++) {
408 >                        if (niter)
409 >                                d = frandom();
410 >                        else
411 >                                d = urand(ilhash(dimlist,ndims)+samplendx);
412 >                        multisamp(rv, 2, d);
413 >                        d = 2.0*PI * rv[0];
414 >                        cosp = tcos(d) * np->u_alpha;
415 >                        sinp = tsin(d) * np->v_alpha;
416 >                        d = sqrt(cosp*cosp + sinp*sinp);
417 >                        cosp /= d;
418 >                        sinp /= d;
419 >                        rv[1] = 1.0 - specjitter*rv[1];
420 >                        if (rv[1] <= FTINY)
421 >                                d = 1.0;
422 >                        else
423 >                                d = sqrt(-log(rv[1]) /
424 >                                        (cosp*cosp/(np->u_alpha*np->u_alpha) +
425 >                                         sinp*sinp/(np->v_alpha*np->v_alpha)));
426 >                        for (i = 0; i < 3; i++)
427 >                                h[i] = np->pnorm[i] +
428                                          d*(cosp*np->u[i] + sinp*np->v[i]);
429 <                d = -2.0 * DOT(h, r->rdir) / (1.0 + d*d);
430 <                for (i = 0; i < 3; i++)
431 <                        sr.rdir[i] = r->rdir[i] + d*h[i];
432 <                if (DOT(sr.rdir, r->ron) <= FTINY)      /* oops! */
433 <                        goto refagain;
434 <                rayvalue(&sr);
435 <                multcolor(sr.rcol, np->scolor);
436 <                addcolor(r->rcol, sr.rcol);
429 >                        d = -2.0 * DOT(h, r->rdir) / (1.0 + d*d);
430 >                        for (i = 0; i < 3; i++)
431 >                                sr.rdir[i] = r->rdir[i] + d*h[i];
432 >                        if (DOT(sr.rdir, r->ron) > FTINY) {
433 >                                rayvalue(&sr);
434 >                                multcolor(sr.rcol, np->scolor);
435 >                                addcolor(r->rcol, sr.rcol);
436 >                                break;
437 >                        }
438 >                }
439                  ndims--;
440          }
441                                          /* compute transmission */
442 +        if ((np->specfl & (SP_TRAN|SP_TBLT)) == SP_TRAN &&
443 +                        rayorigin(&sr, r, SPECULAR, np->tspec) == 0) {
444 +                dimlist[ndims++] = (int)np->mp;
445 +                for (niter = 0; niter < MAXITER; niter++) {
446 +                        if (niter)
447 +                                d = frandom();
448 +                        else
449 +                                d = urand(ilhash(dimlist,ndims)+1823+samplendx);
450 +                        multisamp(rv, 2, d);
451 +                        d = 2.0*PI * rv[0];
452 +                        cosp = tcos(d) * np->u_alpha;
453 +                        sinp = tsin(d) * np->v_alpha;
454 +                        d = sqrt(cosp*cosp + sinp*sinp);
455 +                        cosp /= d;
456 +                        sinp /= d;
457 +                        rv[1] = 1.0 - specjitter*rv[1];
458 +                        if (rv[1] <= FTINY)
459 +                                d = 1.0;
460 +                        else
461 +                                d = sqrt(-log(rv[1]) /
462 +                                        (cosp*cosp/(np->u_alpha*np->u_alpha) +
463 +                                         sinp*sinp/(np->v_alpha*np->v_alpha)));
464 +                        for (i = 0; i < 3; i++)
465 +                                sr.rdir[i] = np->prdir[i] +
466 +                                                d*(cosp*np->u[i] + sinp*np->v[i]);
467 +                        if (DOT(sr.rdir, r->ron) < -FTINY) {
468 +                                normalize(sr.rdir);     /* OK, normalize */
469 +                                rayvalue(&sr);
470 +                                scalecolor(sr.rcol, np->tspec);
471 +                                multcolor(sr.rcol, np->mcolor); /* modify */
472 +                                addcolor(r->rcol, sr.rcol);
473 +                                break;
474 +                        }
475 +                }
476 +                ndims--;
477 +        }
478   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines