--- ray/src/rt/normal.c 1992/05/20 14:23:47 2.21 +++ ray/src/rt/normal.c 1993/08/24 12:59:28 2.26 @@ -23,11 +23,11 @@ static char SCCSid[] = "$SunId$ LBL"; extern double specthresh; /* specular sampling threshold */ extern double specjitter; /* specular sampling jitter */ +static gaussamp(); + /* - * This routine uses portions of the reflection - * model described by Cook and Torrance. - * The computation of specular components has been simplified by - * numerous approximations and ommisions to improve speed. + * This routine implements the isotropic Gaussian + * model described by Ward in Siggraph `92 article. * We orient the surface towards the incoming ray, so a single * surface can be used to represent an infinitely thin object. * @@ -38,8 +38,6 @@ extern double specjitter; /* specular sampling jitte * red grn blu rspec rough trans tspec */ -#define BSPEC(m) (6.0) /* specularity parameter b */ - /* specularity flags */ #define SP_REFL 01 /* has reflected specular component */ #define SP_TRAN 02 /* has transmitted specular */ @@ -104,12 +102,13 @@ double omega; /* light source size */ /* + source if flat */ if (np->specfl & SP_FLAT) dtmp += omega/(4.0*PI); - /* delta */ + /* 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]; d2 = DOT(vtmp, np->pnorm); - d2 = 2.0 - 2.0*d2/sqrt(DOT(vtmp,vtmp)); + d2 *= d2; + d2 = (DOT(vtmp,vtmp) - d2) / d2; /* gaussian */ dtmp = exp(-d2/dtmp)/(4.*PI*dtmp); /* worth using? */ @@ -155,7 +154,6 @@ register RAY *r; { NORMDAT nd; double transtest, transdist; - double dtmp; COLOR ctmp; register int i; /* easy shadow test */ @@ -185,6 +183,7 @@ register RAY *r; nd.pdot = .001; /* non-zero for dirnorm() */ multcolor(nd.mcolor, r->pcol); /* modify material color */ transtest = 0; + transdist = r->rot; /* get specular component */ if ((nd.rspec = m->oargs.farg[3]) > FTINY) { nd.specfl |= SP_REFL; @@ -194,16 +193,8 @@ register RAY *r; else setcolor(nd.scolor, 1.0, 1.0, 1.0); scalecolor(nd.scolor, nd.rspec); - /* improved model */ - dtmp = exp(-BSPEC(m)*nd.pdot); - for (i = 0; i < 3; i++) - colval(nd.scolor,i) += (1.0-colval(nd.scolor,i))*dtmp; - nd.rspec += (1.0-nd.rspec)*dtmp; /* check threshold */ - if (!(nd.specfl & SP_PURE) && - specthresh > FTINY && - (specthresh >= 1.-FTINY || - specthresh + .05 - .1*frandom() > nd.rspec)) + if (!(nd.specfl & SP_PURE) && specthresh >= nd.rspec-FTINY) nd.specfl |= SP_RBLT; /* compute reflected ray */ for (i = 0; i < 3; i++) @@ -230,9 +221,8 @@ register RAY *r; if (nd.tspec > FTINY) { nd.specfl |= SP_TRAN; /* check threshold */ - if (!(nd.specfl & SP_PURE) && specthresh > FTINY && - (specthresh >= 1.-FTINY || - specthresh + .05 - .1*frandom() > nd.tspec)) + if (!(nd.specfl & SP_PURE) && + specthresh >= nd.tspec-FTINY) nd.specfl |= SP_TBLT; if (r->crtype & SHADOW || DOT(r->pert,r->pert) <= FTINY*FTINY) {