23 |
|
extern double specthresh; /* specular sampling threshold */ |
24 |
|
extern double specjitter; /* specular sampling jitter */ |
25 |
|
|
26 |
+ |
static gaussamp(); |
27 |
+ |
|
28 |
|
/* |
29 |
< |
* This routine uses portions of the reflection |
30 |
< |
* model described by Cook and Torrance. |
29 |
< |
* The computation of specular components has been simplified by |
30 |
< |
* numerous approximations and ommisions to improve speed. |
29 |
> |
* This routine implements the isotropic Gaussian |
30 |
> |
* model described by Ward in Siggraph `92 article. |
31 |
|
* We orient the surface towards the incoming ray, so a single |
32 |
|
* surface can be used to represent an infinitely thin object. |
33 |
|
* |
38 |
|
* red grn blu rspec rough trans tspec |
39 |
|
*/ |
40 |
|
|
41 |
– |
#define BSPEC(m) (6.0) /* specularity parameter b */ |
42 |
– |
|
41 |
|
/* specularity flags */ |
42 |
|
#define SP_REFL 01 /* has reflected specular component */ |
43 |
|
#define SP_TRAN 02 /* has transmitted specular */ |
102 |
|
/* + source if flat */ |
103 |
|
if (np->specfl & SP_FLAT) |
104 |
|
dtmp += omega/(4.0*PI); |
105 |
< |
/* delta */ |
105 |
> |
/* half vector */ |
106 |
|
vtmp[0] = ldir[0] - np->rp->rdir[0]; |
107 |
|
vtmp[1] = ldir[1] - np->rp->rdir[1]; |
108 |
|
vtmp[2] = ldir[2] - np->rp->rdir[2]; |
109 |
|
d2 = DOT(vtmp, np->pnorm); |
110 |
< |
d2 = 2.0 - 2.0*d2/sqrt(DOT(vtmp,vtmp)); |
110 |
> |
d2 *= d2; |
111 |
> |
d2 = (DOT(vtmp,vtmp) - d2) / d2; |
112 |
|
/* gaussian */ |
113 |
|
dtmp = exp(-d2/dtmp)/(4.*PI*dtmp); |
114 |
|
/* worth using? */ |
136 |
|
/* roughness + source */ |
137 |
|
dtmp = np->alpha2 + omega/PI; |
138 |
|
/* gaussian */ |
139 |
< |
dtmp = exp((2.*DOT(np->prdir,ldir)-2.)/dtmp)/(4.*PI*dtmp); |
139 |
> |
dtmp = exp((2.*DOT(np->prdir,ldir)-2.)/dtmp)/(PI*dtmp); |
140 |
|
/* worth using? */ |
141 |
|
if (dtmp > FTINY) { |
142 |
|
copycolor(ctmp, np->mcolor); |
154 |
|
{ |
155 |
|
NORMDAT nd; |
156 |
|
double transtest, transdist; |
158 |
– |
double dtmp; |
157 |
|
COLOR ctmp; |
158 |
|
register int i; |
159 |
|
/* easy shadow test */ |
192 |
|
else |
193 |
|
setcolor(nd.scolor, 1.0, 1.0, 1.0); |
194 |
|
scalecolor(nd.scolor, nd.rspec); |
197 |
– |
/* improved model */ |
198 |
– |
dtmp = exp(-BSPEC(m)*nd.pdot); |
199 |
– |
for (i = 0; i < 3; i++) |
200 |
– |
colval(nd.scolor,i) += (1.0-colval(nd.scolor,i))*dtmp; |
201 |
– |
nd.rspec += (1.0-nd.rspec)*dtmp; |
195 |
|
/* check threshold */ |
196 |
< |
if (!(nd.specfl & SP_PURE) && |
204 |
< |
specthresh > FTINY && |
205 |
< |
(specthresh >= 1.-FTINY || |
206 |
< |
specthresh + .05 - .1*frandom() > nd.rspec)) |
196 |
> |
if (!(nd.specfl & SP_PURE) && specthresh >= nd.rspec-FTINY) |
197 |
|
nd.specfl |= SP_RBLT; |
198 |
|
/* compute reflected ray */ |
199 |
|
for (i = 0; i < 3; i++) |
220 |
|
if (nd.tspec > FTINY) { |
221 |
|
nd.specfl |= SP_TRAN; |
222 |
|
/* check threshold */ |
223 |
< |
if (!(nd.specfl & SP_PURE) && specthresh > FTINY && |
224 |
< |
(specthresh >= 1.-FTINY || |
235 |
< |
specthresh + .05 - .1*frandom() > nd.tspec)) |
223 |
> |
if (!(nd.specfl & SP_PURE) && |
224 |
> |
specthresh >= nd.tspec-FTINY) |
225 |
|
nd.specfl |= SP_TBLT; |
226 |
|
if (r->crtype & SHADOW || |
227 |
|
DOT(r->pert,r->pert) <= FTINY*FTINY) { |