--- ray/src/rt/normal.c 2003/06/17 21:49:57 2.44 +++ ray/src/rt/normal.c 2004/09/20 17:32:04 2.48 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: normal.c,v 2.44 2003/06/17 21:49:57 greg Exp $"; +static const char RCSid[] = "$Id: normal.c,v 2.48 2004/09/20 17:32:04 greg Exp $"; #endif /* * normal.c - shading function for normal materials. @@ -14,9 +14,10 @@ static const char RCSid[] = "$Id: normal.c,v 2.44 2003 #include "copyright.h" #include "ray.h" - +#include "ambient.h" +#include "source.h" #include "otypes.h" - +#include "rtotypes.h" #include "random.h" #ifndef MAXITER @@ -25,7 +26,6 @@ static const char RCSid[] = "$Id: normal.c,v 2.44 2003 /* estimate of Fresnel function */ #define FRESNE(ci) (exp(-5.85*(ci)) - 0.00287989916) -static void gaussamp(); /* * This routine implements the isotropic Gaussian @@ -64,14 +64,19 @@ typedef struct { double pdot; /* perturbed dot product */ } NORMDAT; /* normal material data */ +static srcdirf_t dirnorm; +static void gaussamp(RAY *r, NORMDAT *np); + static void -dirnorm(cval, np, ldir, omega) /* compute source contribution */ -COLOR cval; /* returned coefficient */ -register NORMDAT *np; /* material data */ -FVECT ldir; /* light source direction */ -double omega; /* light source size */ +dirnorm( /* compute source contribution */ + COLOR cval, /* returned coefficient */ + void *nnp, /* material data */ + FVECT ldir, /* light source direction */ + double omega /* light source size */ +) { + register NORMDAT *np = nnp; double ldot; double ldiff; double dtmp, d2; @@ -87,7 +92,7 @@ double omega; /* light source size */ /* Fresnel estimate */ ldiff = np->rdiff; - if (np->specfl & SP_PURE && (np->rspec > FTINY & ldiff > FTINY)) + if (np->specfl & SP_PURE && (np->rspec > FTINY) & (ldiff > FTINY)) ldiff *= 1. - FRESNE(fabs(ldot)); if (ldot > FTINY && ldiff > FTINY) { @@ -97,7 +102,7 @@ double omega; /* light source size */ * modified by the color of the material. */ copycolor(ctmp, np->mcolor); - dtmp = ldot * omega * ldiff / PI; + dtmp = ldot * omega * ldiff * (1.0/PI); scalecolor(ctmp, dtmp); addcolor(cval, ctmp); } @@ -110,7 +115,7 @@ double omega; /* light source size */ dtmp = np->alpha2; /* + source if flat */ if (np->specfl & SP_FLAT) - dtmp += omega/(4.0*PI); + dtmp += omega * (0.25/PI); /* half vector */ vtmp[0] = ldir[0] - np->rp->rdir[0]; vtmp[1] = ldir[1] - np->rp->rdir[1]; @@ -119,11 +124,11 @@ double omega; /* light source size */ d2 *= d2; d2 = (DOT(vtmp,vtmp) - d2) / d2; /* gaussian */ - dtmp = exp(-d2/dtmp)/(4.*PI*dtmp); + dtmp = exp(-d2/dtmp)/(4.*PI * np->pdot * dtmp); /* worth using? */ if (dtmp > FTINY) { copycolor(ctmp, np->scolor); - dtmp *= omega * sqrt(ldot/np->pdot); + dtmp *= omega; scalecolor(ctmp, dtmp); addcolor(cval, ctmp); } @@ -133,7 +138,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); } @@ -143,13 +148,14 @@ double omega; /* light source size */ * is always modified by material color. */ /* roughness + source */ - dtmp = np->alpha2 + omega/PI; + dtmp = np->alpha2 + omega*(1.0/PI); /* gaussian */ - dtmp = exp((2.*DOT(np->prdir,ldir)-2.)/dtmp)/(PI*dtmp); + dtmp = exp((2.*DOT(np->prdir,ldir)-2.)/dtmp) / + (PI*np->pdot*dtmp); /* worth using? */ if (dtmp > FTINY) { copycolor(ctmp, np->mcolor); - dtmp *= np->tspec * omega * sqrt(-ldot/np->pdot); + dtmp *= np->tspec * omega; scalecolor(ctmp, dtmp); addcolor(cval, ctmp); } @@ -157,10 +163,11 @@ double omega; /* light source size */ } -int -m_normal(m, r) /* color a ray that hit something normal */ -register OBJREC *m; -register RAY *r; +extern int +m_normal( /* color a ray that hit something normal */ + register OBJREC *m, + register RAY *r +) { NORMDAT nd; double fest; @@ -198,7 +205,7 @@ register RAY *r; if ((nd.alpha2 *= nd.alpha2) <= FTINY) nd.specfl |= SP_PURE; - if (hastexture = (DOT(r->pert,r->pert) > FTINY*FTINY)) { + if ( (hastexture = (DOT(r->pert,r->pert) > FTINY*FTINY)) ) { nd.pdot = raynormal(nd.pnorm, r); /* perturb normal */ } else { VCOPY(nd.pnorm, r->ron); @@ -351,9 +358,10 @@ register RAY *r; static void -gaussamp(r, np) /* sample gaussian specular */ -RAY *r; -register NORMDAT *np; +gaussamp( /* sample gaussian specular */ + RAY *r, + register NORMDAT *np +) { RAY sr; FVECT u, v, h;