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.1 by greg, Sat Jan 4 19:52:49 1992 UTC vs.
Revision 2.3 by greg, Mon Jan 6 18:01:41 1992 UTC

# Line 38 | Line 38 | static char SCCSid[] = "$SunId$ LBL";
38   #define  SP_TRAN        02              /* has transmitted specular */
39   #define  SP_PURE        010             /* purely specular (zero roughness) */
40   #define  SP_BADU        020             /* bad u direction calculation */
41 + #define  SP_FLAT        040             /* reflecting surface is flat */
42  
43   typedef struct {
43        RAY  *rp;               /* ray pointer */
44          OBJREC  *mp;            /* material pointer */
45 +        RAY  *rp;               /* ray pointer */
46          short  specfl;          /* specularity flags, defined above */
47          COLOR  mcolor;          /* color of this material */
48          COLOR  scolor;          /* color of specular component */
# Line 92 | Line 93 | double  omega;                 /* light source size */
93                   *  Compute specular reflection coefficient using
94                   *  anisotropic gaussian distribution model.
95                   */
96 <                                                /* roughness + source */
97 <                au2 = av2 = omega/(4.0*PI);
96 >                                                /* add source width if flat */
97 >                if (np->specfl & SP_FLAT)
98 >                        au2 = av2 = omega/(4.0*PI);
99 >                else
100 >                        au2 = av2 = 0.0;
101                  au2 += np->u_alpha * np->u_alpha;
102                  av2 += np->v_alpha * np->v_alpha;
103                                                  /* half vector */
# Line 160 | Line 164 | register RAY  *r;
164  
165          if (m->oargs.nfargs != (m->otype == MAT_TRANS2 ? 8 : 6))
166                  objerror(m, USER, "bad number of real arguments");
163        nd.rp = r;
167          nd.mp = m;
168 +        nd.rp = r;
169                                                  /* get material color */
170          setcolor(nd.mcolor, m->oargs.farg[0],
171                             m->oargs.farg[1],
# Line 316 | Line 320 | register ANISODAT  *np;
320          FVECT  h;
321          double  rv[2];
322          double  d, sinp, cosp;
323 <        int  confuse;
323 >        int  ntries;
324          register int  i;
325                                          /* compute reflection */
326          if (np->specfl & SP_REFL &&
327                          rayorigin(&sr, r, SPECULAR, np->rspec) == 0) {
324                confuse = 0;
328                  dimlist[ndims++] = (int)np->mp;
329 <        refagain:
330 <                dimlist[ndims] = confuse += 3601;
331 <                d = urand(ilhash(dimlist,ndims+1)+samplendx);
332 <                multisamp(rv, 2, d);
333 <                d = 2.0*PI * rv[0];
334 <                cosp = np->u_alpha * cos(d);
335 <                sinp = np->v_alpha * sin(d);
336 <                d = sqrt(cosp*cosp + sinp*sinp);
337 <                cosp /= d;
338 <                sinp /= d;
339 <                if (rv[1] <= FTINY)
340 <                        d = 1.0;
341 <                else
342 <                        d = sqrt( -log(rv[1]) /
343 <                                (cosp*cosp/(np->u_alpha*np->u_alpha) +
344 <                                 sinp*sinp/(np->v_alpha*np->v_alpha)) );
345 <                for (i = 0; i < 3; i++)
346 <                        h[i] = np->pnorm[i] +
329 >                for (ntries = 0; ntries < 10; ntries++) {
330 >                        dimlist[ndims] = ntries * 3601;
331 >                        d = urand(ilhash(dimlist,ndims+1)+samplendx);
332 >                        multisamp(rv, 2, d);
333 >                        d = 2.0*PI * rv[0];
334 >                        cosp = np->u_alpha * cos(d);
335 >                        sinp = np->v_alpha * sin(d);
336 >                        d = sqrt(cosp*cosp + sinp*sinp);
337 >                        cosp /= d;
338 >                        sinp /= d;
339 >                        if (rv[1] <= FTINY)
340 >                                d = 1.0;
341 >                        else
342 >                                d = sqrt(-log(rv[1]) /
343 >                                        (cosp*cosp/(np->u_alpha*np->u_alpha) +
344 >                                         sinp*sinp/(np->v_alpha*np->v_alpha)));
345 >                        for (i = 0; i < 3; i++)
346 >                                h[i] = np->pnorm[i] +
347                                          d*(cosp*np->u[i] + sinp*np->v[i]);
348 <                d = -2.0 * DOT(h, r->rdir) / (1.0 + d*d);
349 <                for (i = 0; i < 3; i++)
350 <                        sr.rdir[i] = r->rdir[i] + d*h[i];
351 <                if (DOT(sr.rdir, r->ron) <= FTINY)      /* oops! */
352 <                        goto refagain;
353 <                rayvalue(&sr);
354 <                multcolor(sr.rcol, np->scolor);
355 <                addcolor(r->rcol, sr.rcol);
348 >                        d = -2.0 * DOT(h, r->rdir) / (1.0 + d*d);
349 >                        for (i = 0; i < 3; i++)
350 >                                sr.rdir[i] = r->rdir[i] + d*h[i];
351 >                        if (DOT(sr.rdir, r->ron) > FTINY) {
352 >                                rayvalue(&sr);
353 >                                multcolor(sr.rcol, np->scolor);
354 >                                addcolor(r->rcol, sr.rcol);
355 >                                break;
356 >                        }
357 >                }
358                  ndims--;
359          }
360                                          /* compute transmission */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines