--- ray/src/rt/aniso.c 2004/09/20 17:32:04 2.42 +++ ray/src/rt/aniso.c 2010/10/01 18:11:18 2.46 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: aniso.c,v 2.42 2004/09/20 17:32:04 greg Exp $"; +static const char RCSid[] = "$Id: aniso.c,v 2.46 2010/10/01 18:11:18 greg Exp $"; #endif /* * Shading functions for anisotropic materials. @@ -101,7 +101,7 @@ diraniso( /* compute source contribution */ if (ldot > FTINY && (np->specfl&(SP_REFL|SP_BADU)) == SP_REFL) { /* * Compute specular reflection coefficient using - * anisotropic gaussian distribution model. + * anisotropic Gaussian distribution model. */ /* add source width if flat */ if (np->specfl & SP_FLAT) @@ -119,14 +119,16 @@ diraniso( /* compute source contribution */ dtmp1 *= dtmp1 / au2; dtmp2 = DOT(np->v, h); dtmp2 *= dtmp2 / av2; - /* gaussian */ + /* new W-G-M-D model */ dtmp = DOT(np->pnorm, h); - dtmp = (dtmp1 + dtmp2) / (dtmp*dtmp); - dtmp = exp(-dtmp) / (4.0*PI * np->pdot * sqrt(au2*av2)); + dtmp *= dtmp; + dtmp1 = (dtmp1 + dtmp2) / dtmp; + dtmp = exp(-dtmp1) * DOT(h,h) / + (PI * dtmp*dtmp * sqrt(au2*av2)); /* worth using? */ if (dtmp > FTINY) { copycolor(ctmp, np->scolor); - dtmp *= omega; + dtmp *= ldot * omega; scalecolor(ctmp, dtmp); addcolor(cval, ctmp); } @@ -166,8 +168,8 @@ diraniso( /* compute source contribution */ } } else dtmp = 0.0; - /* gaussian */ - dtmp = exp(-dtmp) / (PI * np->pdot * sqrt(au2*av2)); + /* Gaussian */ + dtmp = exp(-dtmp) * (1.0/PI) * sqrt(-ldot/(np->pdot*au2*av2)); /* worth using? */ if (dtmp > FTINY) { copycolor(ctmp, np->mcolor); @@ -214,7 +216,7 @@ m_aniso( /* shade ray that hit something anisotropic nd.specfl = 0; nd.u_alpha = m->oargs.farg[4]; nd.v_alpha = m->oargs.farg[5]; - if (nd.u_alpha < FTINY || nd.v_alpha <= FTINY) + if (nd.u_alpha <= FTINY || nd.v_alpha <= FTINY) objerror(m, USER, "roughness too small"); nd.pdot = raynormal(nd.pnorm, r); /* perturb normal */ @@ -276,12 +278,12 @@ m_aniso( /* shade ray that hit something anisotropic agaussamp(r, &nd); if (nd.rdiff > FTINY) { /* ambient from this side */ - ambient(ctmp, r, nd.pnorm); + copycolor(ctmp, nd.mcolor); /* modified by material color */ if (nd.specfl & SP_RBLT) scalecolor(ctmp, 1.0-nd.trans); else scalecolor(ctmp, nd.rdiff); - multcolor(ctmp, nd.mcolor); /* modified by material color */ + multambient(ctmp, r, nd.pnorm); addcolor(r->rcol, ctmp); /* add to returned color */ } if (nd.tdiff > FTINY) { /* ambient from other side */ @@ -291,12 +293,12 @@ m_aniso( /* shade ray that hit something anisotropic bnorm[0] = -nd.pnorm[0]; bnorm[1] = -nd.pnorm[1]; bnorm[2] = -nd.pnorm[2]; - ambient(ctmp, r, bnorm); + copycolor(ctmp, nd.mcolor); /* modified by color */ if (nd.specfl & SP_TBLT) scalecolor(ctmp, nd.trans); else scalecolor(ctmp, nd.tdiff); - multcolor(ctmp, nd.mcolor); /* modified by color */ + multambient(ctmp, r, bnorm); addcolor(r->rcol, ctmp); flipsurface(r); } @@ -339,7 +341,7 @@ getacoords( /* set up coordinate system */ static void -agaussamp( /* sample anisotropic gaussian specular */ +agaussamp( /* sample anisotropic Gaussian specular */ RAY *r, register ANISODAT *np ) @@ -352,7 +354,7 @@ agaussamp( /* sample anisotropic gaussian specular */ register int i; /* compute reflection */ if ((np->specfl & (SP_REFL|SP_RBLT)) == SP_REFL && - rayorigin(&sr, r, SPECULAR, np->rspec) == 0) { + rayorigin(&sr, SPECULAR, r, np->scolor) == 0) { dimlist[ndims++] = (int)np->mp; for (niter = 0; niter < MAXITER; niter++) { if (niter) @@ -380,8 +382,9 @@ agaussamp( /* sample anisotropic gaussian specular */ for (i = 0; i < 3; i++) sr.rdir[i] = r->rdir[i] + d*h[i]; if (DOT(sr.rdir, r->ron) > FTINY) { + checknorm(sr.rdir); rayvalue(&sr); - multcolor(sr.rcol, np->scolor); + multcolor(sr.rcol, sr.rcoef); addcolor(r->rcol, sr.rcol); break; } @@ -389,8 +392,10 @@ agaussamp( /* sample anisotropic gaussian specular */ ndims--; } /* compute transmission */ + copycolor(sr.rcoef, np->mcolor); /* modify by material color */ + scalecolor(sr.rcoef, np->tspec); if ((np->specfl & (SP_TRAN|SP_TBLT)) == SP_TRAN && - rayorigin(&sr, r, SPECULAR, np->tspec) == 0) { + rayorigin(&sr, SPECULAR, r, sr.rcoef) == 0) { dimlist[ndims++] = (int)np->mp; for (niter = 0; niter < MAXITER; niter++) { if (niter) @@ -417,8 +422,7 @@ agaussamp( /* sample anisotropic gaussian specular */ if (DOT(sr.rdir, r->ron) < -FTINY) { normalize(sr.rdir); /* OK, normalize */ rayvalue(&sr); - scalecolor(sr.rcol, np->tspec); - multcolor(sr.rcol, np->mcolor); /* modify */ + multcolor(sr.rcol, sr.rcoef); addcolor(r->rcol, sr.rcol); break; }