--- ray/src/rt/normal.c 1992/05/14 11:32:07 2.17 +++ ray/src/rt/normal.c 1994/01/12 16:46:45 2.27 @@ -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 */ @@ -74,7 +72,6 @@ double omega; /* light source size */ double ldot; double dtmp, d2; FVECT vtmp; - register int i; COLOR ctmp; setcolor(cval, 0.0, 0.0, 0.0); @@ -105,11 +102,13 @@ double omega; /* light source size */ /* + source if flat */ if (np->specfl & SP_FLAT) dtmp += omega/(4.0*PI); - /* delta */ - for (i = 0; i < 3; i++) - vtmp[i] = ldir[i] - np->rp->rdir[i]; + /* 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? */ @@ -135,13 +134,13 @@ double omega; /* light source size */ * is always modified by material color. */ /* roughness + source */ - dtmp = np->alpha2/2.0 + omega/(2.0*PI); + dtmp = np->alpha2 + omega/PI; /* gaussian */ - dtmp = exp((DOT(np->prdir,ldir)-1.)/dtmp)/(2.*PI)/dtmp; + dtmp = exp((2.*DOT(np->prdir,ldir)-2.)/dtmp)/(PI*dtmp); /* worth using? */ if (dtmp > FTINY) { copycolor(ctmp, np->mcolor); - dtmp *= np->tspec * omega * sqrt(ldot/np->pdot); + dtmp *= np->tspec * omega * sqrt(-ldot/np->pdot); scalecolor(ctmp, dtmp); addcolor(cval, ctmp); } @@ -155,12 +154,11 @@ register RAY *r; { NORMDAT nd; double transtest, transdist; - double dtmp; COLOR ctmp; register int i; /* easy shadow test */ if (r->crtype & SHADOW && m->otype != MAT_TRANS) - return; + return(1); if (m->oargs.nfargs != (m->otype == MAT_TRANS ? 7 : 5)) objerror(m, USER, "bad number of arguments"); @@ -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) { @@ -240,8 +230,7 @@ register RAY *r; transtest = 2; } else { for (i = 0; i < 3; i++) /* perturb */ - nd.prdir[i] = r->rdir[i] - - 0.5*r->pert[i]; + nd.prdir[i] = r->rdir[i] - r->pert[i]; if (DOT(nd.prdir, r->ron) < -FTINY) normalize(nd.prdir); /* OK */ else @@ -266,12 +255,12 @@ register RAY *r; transtest = 0; if (r->crtype & SHADOW) /* the rest is shadow */ - return; + return(1); /* diffuse reflection */ nd.rdiff = 1.0 - nd.trans - nd.rspec; if (nd.specfl & SP_PURE && nd.rdiff <= FTINY && nd.tdiff <= FTINY) - return; /* 100% pure specular */ + return(1); /* 100% pure specular */ if (r->ro != NULL && (r->ro->otype == OBJ_FACE || r->ro->otype == OBJ_RING)) @@ -305,6 +294,8 @@ register RAY *r; /* check distance */ if (transtest > bright(r->rcol)) r->rt = transdist; + + return(1); } @@ -370,7 +361,7 @@ register NORMDAT *np; if (rv[1] <= FTINY) d = 1.0; else - d = sqrt( np->alpha2/4.0 * -log(rv[1]) ); + d = sqrt( -log(rv[1]) * np->alpha2 ); for (i = 0; i < 3; i++) sr.rdir[i] = np->prdir[i] + d*(cosp*u[i] + sinp*v[i]); if (DOT(sr.rdir, r->ron) < -FTINY)