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.42 by greg, Mon Sep 20 17:32:04 2004 UTC vs.
Revision 2.47 by greg, Fri Oct 8 22:08:26 2010 UTC

# Line 101 | Line 101 | diraniso(              /* compute source contribution */
101          if (ldot > FTINY && (np->specfl&(SP_REFL|SP_BADU)) == SP_REFL) {
102                  /*
103                   *  Compute specular reflection coefficient using
104 <                 *  anisotropic gaussian distribution model.
104 >                 *  anisotropic Gaussian distribution model.
105                   */
106                                                  /* add source width if flat */
107                  if (np->specfl & SP_FLAT)
# Line 119 | Line 119 | diraniso(              /* compute source contribution */
119                  dtmp1 *= dtmp1 / au2;
120                  dtmp2 = DOT(np->v, h);
121                  dtmp2 *= dtmp2 / av2;
122 <                                                /* gaussian */
122 >                                                /* new W-G-M-D model */
123                  dtmp = DOT(np->pnorm, h);
124 <                dtmp = (dtmp1 + dtmp2) / (dtmp*dtmp);
125 <                dtmp = exp(-dtmp) / (4.0*PI * np->pdot * sqrt(au2*av2));
124 >                dtmp *= dtmp;
125 >                dtmp1 = (dtmp1 + dtmp2) / dtmp;
126 >                dtmp = exp(-dtmp1) * DOT(h,h) /
127 >                                (PI * dtmp*dtmp * sqrt(au2*av2));
128                                                  /* worth using? */
129                  if (dtmp > FTINY) {
130                          copycolor(ctmp, np->scolor);
131 <                        dtmp *= omega;
131 >                        dtmp *= ldot * omega;
132                          scalecolor(ctmp, dtmp);
133                          addcolor(cval, ctmp);
134                  }
# Line 166 | Line 168 | diraniso(              /* compute source contribution */
168                          }
169                  } else
170                          dtmp = 0.0;
171 <                                                /* gaussian */
172 <                dtmp = exp(-dtmp) / (PI * np->pdot * sqrt(au2*av2));
171 >                                                /* Gaussian */
172 >                dtmp = exp(-dtmp) * (1.0/PI) * sqrt(-ldot/(np->pdot*au2*av2));
173                                                  /* worth using? */
174                  if (dtmp > FTINY) {
175                          copycolor(ctmp, np->mcolor);
# Line 214 | Line 216 | m_aniso(                       /* shade ray that hit something anisotropic
216          nd.specfl = 0;
217          nd.u_alpha = m->oargs.farg[4];
218          nd.v_alpha = m->oargs.farg[5];
219 <        if (nd.u_alpha < FTINY || nd.v_alpha <= FTINY)
219 >        if (nd.u_alpha <= FTINY || nd.v_alpha <= FTINY)
220                  objerror(m, USER, "roughness too small");
221  
222          nd.pdot = raynormal(nd.pnorm, r);       /* perturb normal */
# Line 234 | Line 236 | m_aniso(                       /* shade ray that hit something anisotropic
236                  if (specthresh >= nd.rspec-FTINY)
237                          nd.specfl |= SP_RBLT;
238                                                  /* compute refl. direction */
239 <                for (i = 0; i < 3; i++)
238 <                        nd.vrefl[i] = r->rdir[i] + 2.0*nd.pdot*nd.pnorm[i];
239 >                VSUM(nd.vrefl, r->rdir, nd.pnorm, 2.0*nd.pdot);
240                  if (DOT(nd.vrefl, r->ron) <= FTINY)     /* penetration? */
241 <                        for (i = 0; i < 3; i++)         /* safety measure */
241 <                                nd.vrefl[i] = r->rdir[i] + 2.*r->rod*r->ron[i];
241 >                        VSUM(nd.vrefl, r->rdir, r->ron, 2.0*r->rod);
242          }
243                                                  /* compute transmission */
244          if (m->otype == MAT_TRANS2) {
# Line 276 | Line 276 | m_aniso(                       /* shade ray that hit something anisotropic
276                  agaussamp(r, &nd);
277  
278          if (nd.rdiff > FTINY) {         /* ambient from this side */
279 <                ambient(ctmp, r, nd.pnorm);
279 >                copycolor(ctmp, nd.mcolor);     /* modified by material color */
280                  if (nd.specfl & SP_RBLT)
281                          scalecolor(ctmp, 1.0-nd.trans);
282                  else
283                          scalecolor(ctmp, nd.rdiff);
284 <                multcolor(ctmp, nd.mcolor);     /* modified by material color */
284 >                multambient(ctmp, r, nd.pnorm);
285                  addcolor(r->rcol, ctmp);        /* add to returned color */
286          }
287          if (nd.tdiff > FTINY) {         /* ambient from other side */
# Line 291 | Line 291 | m_aniso(                       /* shade ray that hit something anisotropic
291                  bnorm[0] = -nd.pnorm[0];
292                  bnorm[1] = -nd.pnorm[1];
293                  bnorm[2] = -nd.pnorm[2];
294 <                ambient(ctmp, r, bnorm);
294 >                copycolor(ctmp, nd.mcolor);     /* modified by color */
295                  if (nd.specfl & SP_TBLT)
296                          scalecolor(ctmp, nd.trans);
297                  else
298                          scalecolor(ctmp, nd.tdiff);
299 <                multcolor(ctmp, nd.mcolor);     /* modified by color */
299 >                multambient(ctmp, r, bnorm);
300                  addcolor(r->rcol, ctmp);
301                  flipsurface(r);
302          }
# Line 339 | Line 339 | getacoords(            /* set up coordinate system */
339  
340  
341   static void
342 < agaussamp(              /* sample anisotropic gaussian specular */
342 > agaussamp(              /* sample anisotropic Gaussian specular */
343          RAY  *r,
344          register ANISODAT  *np
345   )
# Line 348 | Line 348 | agaussamp(             /* sample anisotropic gaussian specular */
348          FVECT  h;
349          double  rv[2];
350          double  d, sinp, cosp;
351 <        int  niter;
351 >        COLOR   scol;
352 >        int  niter, ns2go;
353          register int  i;
354                                          /* compute reflection */
355          if ((np->specfl & (SP_REFL|SP_RBLT)) == SP_REFL &&
356 <                        rayorigin(&sr, r, SPECULAR, np->rspec) == 0) {
356 >                        rayorigin(&sr, SPECULAR, r, np->scolor) == 0) {
357 >                copycolor(scol, np->scolor);
358 >                ns2go = 1;
359 >                if (specjitter > 1.5) { /* multiple samples? */
360 >                        ns2go = specjitter*r->rweight + .5;
361 >                        if ((d = bright(scol)) <= minweight*ns2go)
362 >                                ns2go = d/minweight;
363 >                        if (ns2go > 1) {
364 >                                d = 1./ns2go;
365 >                                scalecolor(scol, d);
366 >                        } else
367 >                                ns2go = 1;
368 >                }
369                  dimlist[ndims++] = (int)np->mp;
370 <                for (niter = 0; niter < MAXITER; niter++) {
371 <                        if (niter)
370 >                for (niter = ns2go*MAXITER; (ns2go > 0) & (niter > 0); niter--) {
371 >                        if (specjitter > 1.5)
372                                  d = frandom();
373                          else
374                                  d = urand(ilhash(dimlist,ndims)+samplendx);
# Line 363 | Line 376 | agaussamp(             /* sample anisotropic gaussian specular */
376                          d = 2.0*PI * rv[0];
377                          cosp = tcos(d) * np->u_alpha;
378                          sinp = tsin(d) * np->v_alpha;
379 <                        d = sqrt(cosp*cosp + sinp*sinp);
380 <                        cosp /= d;
381 <                        sinp /= d;
382 <                        rv[1] = 1.0 - specjitter*rv[1];
379 >                        d = 1./sqrt(cosp*cosp + sinp*sinp);
380 >                        cosp *= d;
381 >                        sinp *= d;
382 >                        if ((0. <= specjitter) & (specjitter < 1.))
383 >                                rv[1] = 1.0 - specjitter*rv[1];
384                          if (rv[1] <= FTINY)
385                                  d = 1.0;
386                          else
# Line 377 | Line 391 | agaussamp(             /* sample anisotropic gaussian specular */
391                                  h[i] = np->pnorm[i] +
392                                          d*(cosp*np->u[i] + sinp*np->v[i]);
393                          d = -2.0 * DOT(h, r->rdir) / (1.0 + d*d);
394 <                        for (i = 0; i < 3; i++)
395 <                                sr.rdir[i] = r->rdir[i] + d*h[i];
396 <                        if (DOT(sr.rdir, r->ron) > FTINY) {
397 <                                rayvalue(&sr);
398 <                                multcolor(sr.rcol, np->scolor);
399 <                                addcolor(r->rcol, sr.rcol);
400 <                                break;
394 >                        if (d <= np->pdot + FTINY)
395 >                                continue;
396 >                        VSUM(sr.rdir, r->rdir, h, d);
397 >                        if (DOT(sr.rdir, r->ron) <= FTINY)
398 >                                continue;
399 >                        checknorm(sr.rdir);
400 >                        if (specjitter > 1.5) { /* adjusted W-G-M-D weight */
401 >                                copycolor(sr.rcoef, scol);
402 >                                d = 2.*(1. - np->pdot/d);
403 >                                scalecolor(sr.rcoef, d);
404 >                                rayclear(&sr);
405                          }
406 +                        rayvalue(&sr);
407 +                        multcolor(sr.rcol, sr.rcoef);
408 +                        addcolor(r->rcol, sr.rcol);
409 +                        --ns2go;
410                  }
411                  ndims--;
412          }
413                                          /* compute transmission */
414 +        copycolor(sr.rcoef, np->mcolor);                /* modify by material color */
415 +        scalecolor(sr.rcoef, np->tspec);
416          if ((np->specfl & (SP_TRAN|SP_TBLT)) == SP_TRAN &&
417 <                        rayorigin(&sr, r, SPECULAR, np->tspec) == 0) {
417 >                        rayorigin(&sr, SPECULAR, r, sr.rcoef) == 0) {
418 >                copycolor(scol, sr.rcoef);
419 >                ns2go = 1;
420 >                if (specjitter > 1.5) { /* multiple samples? */
421 >                        ns2go = specjitter*r->rweight + .5;
422 >                        if ((d = bright(scol)) <= minweight*ns2go)
423 >                                ns2go = d/minweight;
424 >                        if (ns2go > 1) {
425 >                                d = 1./ns2go;
426 >                                scalecolor(scol, d);
427 >                        } else
428 >                                ns2go = 1;
429 >                }
430                  dimlist[ndims++] = (int)np->mp;
431 <                for (niter = 0; niter < MAXITER; niter++) {
432 <                        if (niter)
431 >                for (niter = ns2go*MAXITER; (ns2go > 0) & (niter > 0); niter--) {
432 >                        if (specjitter > 1.5)
433                                  d = frandom();
434                          else
435                                  d = urand(ilhash(dimlist,ndims)+1823+samplendx);
# Line 401 | Line 437 | agaussamp(             /* sample anisotropic gaussian specular */
437                          d = 2.0*PI * rv[0];
438                          cosp = tcos(d) * np->u_alpha;
439                          sinp = tsin(d) * np->v_alpha;
440 <                        d = sqrt(cosp*cosp + sinp*sinp);
441 <                        cosp /= d;
442 <                        sinp /= d;
443 <                        rv[1] = 1.0 - specjitter*rv[1];
440 >                        d = 1./sqrt(cosp*cosp + sinp*sinp);
441 >                        cosp *= d;
442 >                        sinp *= d;
443 >                        if ((0. <= specjitter) & (specjitter < 1.))
444 >                                rv[1] = 1.0 - specjitter*rv[1];
445                          if (rv[1] <= FTINY)
446                                  d = 1.0;
447                          else
# Line 414 | Line 451 | agaussamp(             /* sample anisotropic gaussian specular */
451                          for (i = 0; i < 3; i++)
452                                  sr.rdir[i] = np->prdir[i] +
453                                                  d*(cosp*np->u[i] + sinp*np->v[i]);
454 <                        if (DOT(sr.rdir, r->ron) < -FTINY) {
455 <                                normalize(sr.rdir);     /* OK, normalize */
456 <                                rayvalue(&sr);
457 <                                scalecolor(sr.rcol, np->tspec);
458 <                                multcolor(sr.rcol, np->mcolor); /* modify */
459 <                                addcolor(r->rcol, sr.rcol);
423 <                                break;
454 >                        if (DOT(sr.rdir, r->ron) >= -FTINY)
455 >                                continue;
456 >                        normalize(sr.rdir);     /* OK, normalize */
457 >                        if (specjitter > 1.5) { /* multi-sampling */
458 >                                copycolor(sr.rcoef, scol);
459 >                                rayclear(&sr);
460                          }
461 +                        rayvalue(&sr);
462 +                        multcolor(sr.rcol, sr.rcoef);
463 +                        addcolor(r->rcol, sr.rcol);
464 +                        --ns2go;
465                  }
466                  ndims--;
467          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines