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.5 by greg, Wed Jan 15 11:02:43 1992 UTC vs.
Revision 2.6 by greg, Wed Jan 15 11:41:47 1992 UTC

# Line 51 | Line 51 | typedef struct {
51          short  specfl;          /* specularity flags, defined above */
52          COLOR  mcolor;          /* color of this material */
53          COLOR  scolor;          /* color of specular component */
54 +        FVECT  vrefl;           /* vector in reflected direction */
55          FVECT  prdir;           /* vector in transmitted direction */
56          FVECT  u, v;            /* u and v vectors orienting anisotropy */
57          double  u_alpha;        /* u roughness */
# Line 211 | Line 212 | register RAY  *r;
212                                  specthresh + (.1 - .2*urand(8199+samplendx))
213                                          > nd.rspec)))
214                          nd.specfl |= SP_RBLT;
215 +                                                /* compute refl. direction */
216 +                for (i = 0; i < 3; i++)
217 +                        nd.vrefl[i] = r->rdir[i] + 2.0*nd.pdot*nd.pnorm[i];
218 +                if (DOT(nd.vrefl, r->ron) <= FTINY)     /* penetration? */
219 +                        for (i = 0; i < 3; i++)         /* safety measure */
220 +                                nd.vrefl[i] = r->rdir[i] + 2.*r->rod*r->ron[i];
221  
222                  if (!(r->crtype & SHADOW) && nd.specfl & SP_PURE) {
223                          RAY  lr;
224                          if (rayorigin(&lr, r, REFLECTED, nd.rspec) == 0) {
225 <                                for (i = 0; i < 3; i++)
219 <                                        lr.rdir[i] = r->rdir[i] +
220 <                                                2.0*nd.pdot*nd.pnorm[i];
225 >                                VCOPY(lr.rdir, nd.vrefl);
226                                  rayvalue(&lr);
227                                  multcolor(lr.rcol, nd.scolor);
228                                  addcolor(r->rcol, lr.rcol);
# Line 246 | Line 251 | register RAY  *r;
251                                  for (i = 0; i < 3; i++)         /* perturb */
252                                          nd.prdir[i] = r->rdir[i] -
253                                                          .75*r->pert[i];
254 <                                normalize(nd.prdir);
254 >                                if (DOT(nd.prdir, r->ron) < -FTINY)
255 >                                        normalize(nd.prdir);    /* OK */
256 >                                else
257 >                                        VCOPY(nd.prdir, r->rdir);
258                          }
259                  }
260          } else
# Line 347 | Line 355 | register ANISODAT  *np;
355          FVECT  h;
356          double  rv[2];
357          double  d, sinp, cosp;
350        int  ntries;
358          register int  i;
359                                          /* compute reflection */
360          if ((np->specfl & (SP_REFL|SP_RBLT)) == SP_REFL &&
361                          rayorigin(&sr, r, SPECULAR, np->rspec) == 0) {
362                  dimlist[ndims++] = (int)np->mp;
363 <                for (ntries = 0; ntries < 10; ntries++) {
364 <                        dimlist[ndims] = ntries * 3601;
365 <                        d = urand(ilhash(dimlist,ndims+1)+samplendx);
366 <                        multisamp(rv, 2, d);
367 <                        d = 2.0*PI * rv[0];
368 <                        cosp = np->u_alpha * cos(d);
369 <                        sinp = np->v_alpha * sin(d);
370 <                        d = sqrt(cosp*cosp + sinp*sinp);
371 <                        cosp /= d;
372 <                        sinp /= d;
373 <                        rv[1] = 1.0 - specjitter*rv[1];
374 <                        if (rv[1] <= FTINY)
375 <                                d = 1.0;
376 <                        else
377 <                                d = sqrt(-log(rv[1]) /
378 <                                        (cosp*cosp/(np->u_alpha*np->u_alpha) +
379 <                                         sinp*sinp/(np->v_alpha*np->v_alpha)));
380 <                        for (i = 0; i < 3; i++)
381 <                                h[i] = np->pnorm[i] +
382 <                                        d*(cosp*np->u[i] + sinp*np->v[i]);
383 <                        d = -2.0 * DOT(h, r->rdir) / (1.0 + d*d);
384 <                        for (i = 0; i < 3; i++)
385 <                                sr.rdir[i] = r->rdir[i] + d*h[i];
386 <                        if (DOT(sr.rdir, r->ron) > FTINY) {
387 <                                rayvalue(&sr);
388 <                                multcolor(sr.rcol, np->scolor);
382 <                                addcolor(r->rcol, sr.rcol);
383 <                                break;
384 <                        }
385 <                }
363 >                d = urand(ilhash(dimlist,ndims)+samplendx);
364 >                multisamp(rv, 2, d);
365 >                d = 2.0*PI * rv[0];
366 >                cosp = np->u_alpha * cos(d);
367 >                sinp = np->v_alpha * sin(d);
368 >                d = sqrt(cosp*cosp + sinp*sinp);
369 >                cosp /= d;
370 >                sinp /= d;
371 >                rv[1] = 1.0 - specjitter*rv[1];
372 >                if (rv[1] <= FTINY)
373 >                        d = 1.0;
374 >                else
375 >                        d = sqrt(-log(rv[1]) /
376 >                                (cosp*cosp/(np->u_alpha*np->u_alpha) +
377 >                                 sinp*sinp/(np->v_alpha*np->v_alpha)));
378 >                for (i = 0; i < 3; i++)
379 >                        h[i] = np->pnorm[i] +
380 >                                d*(cosp*np->u[i] + sinp*np->v[i]);
381 >                d = -2.0 * DOT(h, r->rdir) / (1.0 + d*d);
382 >                for (i = 0; i < 3; i++)
383 >                        sr.rdir[i] = r->rdir[i] + d*h[i];
384 >                if (DOT(sr.rdir, r->ron) <= FTINY)      /* penetration? */
385 >                        VCOPY(sr.rdir, np->vrefl);      /* jitter no good */
386 >                rayvalue(&sr);
387 >                multcolor(sr.rcol, np->scolor);
388 >                addcolor(r->rcol, sr.rcol);
389                  ndims--;
390          }
391                                          /* compute transmission */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines