--- ray/src/rt/normal.c 2010/10/12 19:01:14 2.58 +++ ray/src/rt/normal.c 2012/07/29 19:01:39 2.62 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: normal.c,v 2.58 2010/10/12 19:01:14 greg Exp $"; +static const char RCSid[] = "$Id: normal.c,v 2.62 2012/07/29 19:01:39 greg Exp $"; #endif /* * normal.c - shading function for normal materials. @@ -65,19 +65,18 @@ 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( /* compute source contribution */ COLOR cval, /* returned coefficient */ - void *nnp, /* material data */ + void *nnp, /* material data */ FVECT ldir, /* light source direction */ double omega /* light source size */ ) { - register NORMDAT *np = nnp; + NORMDAT *np = nnp; double ldot; double lrdiff, ltdiff; double dtmp, d2, d3, d4; @@ -123,9 +122,7 @@ dirnorm( /* compute source contribution */ if (np->specfl & SP_FLAT) dtmp += omega * (0.25/PI); /* half vector */ - vtmp[0] = ldir[0] - np->rp->rdir[0]; - vtmp[1] = ldir[1] - np->rp->rdir[1]; - vtmp[2] = ldir[2] - np->rp->rdir[2]; + VSUB(vtmp, ldir, np->rp->rdir); d2 = DOT(vtmp, np->pnorm); d2 *= d2; d3 = DOT(vtmp,vtmp); @@ -169,10 +166,10 @@ dirnorm( /* compute source contribution */ } -extern int +int m_normal( /* color a ray that hit something normal */ - register OBJREC *m, - register RAY *r + OBJREC *m, + RAY *r ) { NORMDAT nd; @@ -182,7 +179,7 @@ m_normal( /* color a ray that hit something normal * int hastexture; double d; COLOR ctmp; - register int i; + int i; /* easy shadow test */ if (r->crtype & SHADOW && m->otype != MAT_TRANS) return(1); @@ -227,7 +224,7 @@ m_normal( /* color a ray that hit something normal * nd.rspec = m->oargs.farg[3]; /* compute Fresnel approx. */ if (nd.specfl & SP_PURE && nd.rspec >= FRESTHRESH) { - fest = FRESNE(r->rod); + fest = FRESNE(nd.pdot); nd.rspec += fest*(1. - nd.rspec); } else fest = 0.; @@ -325,10 +322,9 @@ m_normal( /* color a ray that hit something normal * if (nd.rdiff > FTINY) { /* ambient from this side */ copycolor(ctmp, nd.mcolor); /* modified by material color */ - if (nd.specfl & SP_RBLT) - scalecolor(ctmp, 1.0-nd.trans); - else - scalecolor(ctmp, nd.rdiff); + scalecolor(ctmp, nd.rdiff); + if (nd.specfl & SP_RBLT) /* add in specular as well? */ + addcolor(ctmp, nd.scolor); multambient(ctmp, r, hastexture ? nd.pnorm : r->ron); addcolor(r->rcol, ctmp); /* add to returned color */ } @@ -366,16 +362,16 @@ m_normal( /* color a ray that hit something normal * static void gaussamp( /* sample Gaussian specular */ RAY *r, - register NORMDAT *np + NORMDAT *np ) { RAY sr; FVECT u, v, h; double rv[2]; double d, sinp, cosp; - COLOR scol; + COLOR scol; int maxiter, ntrials, nstarget, nstaken; - register int i; + int i; /* quick test */ if ((np->specfl & (SP_REFL|SP_RBLT)) != SP_REFL && (np->specfl & (SP_TRAN|SP_TBLT)) != SP_TRAN) @@ -405,7 +401,7 @@ gaussamp( /* sample Gaussian specular */ nstarget = 1; } setcolor(scol, 0., 0., 0.); - dimlist[ndims++] = (int)np->mp; + dimlist[ndims++] = (int)(size_t)np->mp; maxiter = MAXITER*nstarget; for (nstaken = ntrials = 0; nstaken < nstarget && ntrials < maxiter; ntrials++) { @@ -432,7 +428,7 @@ gaussamp( /* sample Gaussian specular */ continue; checknorm(sr.rdir); if (nstarget > 1) { /* W-G-M-D adjustment */ - rayclear(&sr); + if (nstaken) rayclear(&sr); rayvalue(&sr); d = 2./(1. + r->rod/d); scalecolor(sr.rcol, d); @@ -469,7 +465,7 @@ gaussamp( /* sample Gaussian specular */ } else nstarget = 1; } - dimlist[ndims++] = (int)np->mp; + dimlist[ndims++] = (int)(size_t)np->mp; maxiter = MAXITER*nstarget; for (nstaken = ntrials = 0; nstaken < nstarget && ntrials < maxiter; ntrials++) { @@ -493,7 +489,7 @@ gaussamp( /* sample Gaussian specular */ if (DOT(sr.rdir, r->ron) >= -FTINY) continue; normalize(sr.rdir); /* OK, normalize */ - if (nstarget > 1) /* multi-sampling */ + if (nstaken) /* multi-sampling */ rayclear(&sr); rayvalue(&sr); multcolor(sr.rcol, sr.rcoef);