--- ray/src/rt/aniso.c 2003/03/05 16:16:52 2.37 +++ ray/src/rt/aniso.c 2005/04/19 01:15:06 2.43 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: aniso.c,v 2.37 2003/03/05 16:16:52 greg Exp $"; +static const char RCSid[] = "$Id: aniso.c,v 2.43 2005/04/19 01:15:06 greg Exp $"; #endif /* * Shading functions for anisotropic materials. @@ -8,11 +8,11 @@ static const char RCSid[] = "$Id: aniso.c,v 2.37 2003/ #include "copyright.h" #include "ray.h" - +#include "ambient.h" #include "otypes.h" - +#include "rtotypes.h" +#include "source.h" #include "func.h" - #include "random.h" #ifndef MAXITER @@ -60,17 +60,20 @@ typedef struct { double pdot; /* perturbed dot product */ } ANISODAT; /* anisotropic material data */ -static void getacoords(); -static void agaussamp(); +static srcdirf_t diraniso; +static void getacoords(RAY *r, ANISODAT *np); +static void agaussamp(RAY *r, ANISODAT *np); static void -diraniso(cval, np, ldir, omega) /* compute source contribution */ -COLOR cval; /* returned coefficient */ -register ANISODAT *np; /* material data */ -FVECT ldir; /* light source direction */ -double omega; /* light source size */ +diraniso( /* compute source contribution */ + COLOR cval, /* returned coefficient */ + void *nnp, /* material data */ + FVECT ldir, /* light source direction */ + double omega /* light source size */ +) { + register ANISODAT *np = nnp; double ldot; double dtmp, dtmp1, dtmp2; FVECT h; @@ -91,7 +94,7 @@ double omega; /* light source size */ * modified by the color of the material. */ copycolor(ctmp, np->mcolor); - dtmp = ldot * omega * np->rdiff / PI; + dtmp = ldot * omega * np->rdiff * (1.0/PI); scalecolor(ctmp, dtmp); addcolor(cval, ctmp); } @@ -102,7 +105,7 @@ double omega; /* light source size */ */ /* add source width if flat */ if (np->specfl & SP_FLAT) - au2 = av2 = omega/(4.0*PI); + au2 = av2 = omega * (0.25/PI); else au2 = av2 = 0.0; au2 += np->u_alpha*np->u_alpha; @@ -119,8 +122,7 @@ double omega; /* light source size */ /* gaussian */ dtmp = DOT(np->pnorm, h); dtmp = (dtmp1 + dtmp2) / (dtmp*dtmp); - dtmp = exp(-dtmp) * (0.25/PI) - * sqrt(ldot/(np->pdot*au2*av2)); + dtmp = exp(-dtmp) / (4.0*PI * np->pdot * sqrt(au2*av2)); /* worth using? */ if (dtmp > FTINY) { copycolor(ctmp, np->scolor); @@ -134,7 +136,7 @@ double omega; /* light source size */ * Compute diffuse transmission. */ copycolor(ctmp, np->mcolor); - dtmp = -ldot * omega * np->tdiff / PI; + dtmp = -ldot * omega * np->tdiff * (1.0/PI); scalecolor(ctmp, dtmp); addcolor(cval, ctmp); } @@ -144,7 +146,7 @@ double omega; /* light source size */ * is always modified by material color. */ /* roughness + source */ - au2 = av2 = omega / PI; + au2 = av2 = omega * (1.0/PI); au2 += np->u_alpha*np->u_alpha; av2 += np->v_alpha*np->v_alpha; /* "half vector" */ @@ -165,8 +167,7 @@ double omega; /* light source size */ } else dtmp = 0.0; /* gaussian */ - dtmp = exp(-dtmp) * (1.0/PI) - * sqrt(-ldot/(np->pdot*au2*av2)); + dtmp = exp(-dtmp) / (PI * np->pdot * sqrt(au2*av2)); /* worth using? */ if (dtmp > FTINY) { copycolor(ctmp, np->mcolor); @@ -178,10 +179,11 @@ double omega; /* light source size */ } -int -m_aniso(m, r) /* shade ray that hit something anisotropic */ -register OBJREC *m; -register RAY *r; +extern int +m_aniso( /* shade ray that hit something anisotropic */ + register OBJREC *m, + register RAY *r +) { ANISODAT nd; COLOR ctmp; @@ -274,12 +276,12 @@ register RAY *r; 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 */ @@ -289,12 +291,12 @@ register RAY *r; 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); } @@ -306,9 +308,10 @@ register RAY *r; static void -getacoords(r, np) /* set up coordinate system */ -RAY *r; -register ANISODAT *np; +getacoords( /* set up coordinate system */ + RAY *r, + register ANISODAT *np +) { register MFUNC *mf; register int i; @@ -336,9 +339,10 @@ register ANISODAT *np; static void -agaussamp(r, np) /* sample anisotropic gaussian specular */ -RAY *r; -register ANISODAT *np; +agaussamp( /* sample anisotropic gaussian specular */ + RAY *r, + register ANISODAT *np +) { RAY sr; FVECT h; @@ -348,7 +352,7 @@ register ANISODAT *np; 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) @@ -377,7 +381,7 @@ register ANISODAT *np; sr.rdir[i] = r->rdir[i] + d*h[i]; if (DOT(sr.rdir, r->ron) > FTINY) { rayvalue(&sr); - multcolor(sr.rcol, np->scolor); + multcolor(sr.rcol, sr.rcoef); addcolor(r->rcol, sr.rcol); break; } @@ -385,8 +389,10 @@ register ANISODAT *np; 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) @@ -413,8 +419,7 @@ register ANISODAT *np; 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; }