19 |
|
extern double specthresh; /* specular sampling threshold */ |
20 |
|
extern double specjitter; /* specular sampling jitter */ |
21 |
|
|
22 |
< |
static agaussamp(); |
22 |
> |
extern int backvis; /* back faces visible? */ |
23 |
|
|
24 |
+ |
static agaussamp(), getacoords(); |
25 |
+ |
|
26 |
|
/* |
27 |
|
* This routine implements the anisotropic Gaussian |
28 |
|
* model described by Ward in Siggraph `92 article. |
38 |
|
* 8 red grn blu rspec u-rough v-rough trans tspec |
39 |
|
*/ |
40 |
|
|
39 |
– |
#define BSPEC(m) (6.0) /* specularity parameter b */ |
40 |
– |
|
41 |
|
/* specularity flags */ |
42 |
|
#define SP_REFL 01 /* has reflected specular component */ |
43 |
|
#define SP_TRAN 02 /* has transmitted specular */ |
183 |
|
register RAY *r; |
184 |
|
{ |
185 |
|
ANISODAT nd; |
186 |
– |
double dtmp; |
186 |
|
COLOR ctmp; |
187 |
|
register int i; |
188 |
|
/* easy shadow test */ |
189 |
|
if (r->crtype & SHADOW) |
190 |
< |
return; |
190 |
> |
return(1); |
191 |
|
|
192 |
|
if (m->oargs.nfargs != (m->otype == MAT_TRANS2 ? 8 : 6)) |
193 |
|
objerror(m, USER, "bad number of real arguments"); |
203 |
|
nd.v_alpha = m->oargs.farg[5]; |
204 |
|
if (nd.u_alpha < FTINY || nd.v_alpha <= FTINY) |
205 |
|
objerror(m, USER, "roughness too small"); |
206 |
< |
/* reorient if necessary */ |
207 |
< |
if (r->rod < 0.0) |
208 |
< |
flipsurface(r); |
206 |
> |
/* check for back side */ |
207 |
> |
if (r->rod < 0.0) { |
208 |
> |
if (!backvis && m->otype != MAT_TRANS2) { |
209 |
> |
raytrans(r); |
210 |
> |
return(1); |
211 |
> |
} |
212 |
> |
flipsurface(r); /* reorient if backvis */ |
213 |
> |
} |
214 |
|
/* get modifiers */ |
215 |
|
raytexture(r, m->omod); |
216 |
|
nd.pdot = raynormal(nd.pnorm, r); /* perturb normal */ |
226 |
|
else |
227 |
|
setcolor(nd.scolor, 1.0, 1.0, 1.0); |
228 |
|
scalecolor(nd.scolor, nd.rspec); |
225 |
– |
/* improved model */ |
226 |
– |
dtmp = exp(-BSPEC(m)*nd.pdot); |
227 |
– |
for (i = 0; i < 3; i++) |
228 |
– |
colval(nd.scolor,i) += (1.0-colval(nd.scolor,i))*dtmp; |
229 |
– |
nd.rspec += (1.0-nd.rspec)*dtmp; |
229 |
|
/* check threshold */ |
230 |
< |
if (specthresh > FTINY && |
232 |
< |
(specthresh >= 1.-FTINY || |
233 |
< |
specthresh + .05 - .1*frandom() > nd.rspec)) |
230 |
> |
if (specthresh >= nd.rspec-FTINY) |
231 |
|
nd.specfl |= SP_RBLT; |
232 |
|
/* compute refl. direction */ |
233 |
|
for (i = 0; i < 3; i++) |
244 |
|
if (nd.tspec > FTINY) { |
245 |
|
nd.specfl |= SP_TRAN; |
246 |
|
/* check threshold */ |
247 |
< |
if (specthresh > FTINY && |
251 |
< |
(specthresh >= 1.-FTINY || |
252 |
< |
specthresh + .05 - .1*frandom() > nd.tspec)) |
247 |
> |
if (specthresh >= nd.tspec-FTINY) |
248 |
|
nd.specfl |= SP_TBLT; |
249 |
|
if (DOT(r->pert,r->pert) <= FTINY*FTINY) { |
250 |
|
VCOPY(nd.prdir, r->rdir); |
263 |
|
/* diffuse reflection */ |
264 |
|
nd.rdiff = 1.0 - nd.trans - nd.rspec; |
265 |
|
|
266 |
< |
if (r->ro != NULL && (r->ro->otype == OBJ_FACE || |
272 |
< |
r->ro->otype == OBJ_RING)) |
266 |
> |
if (r->ro != NULL && isflat(r->ro->otype)) |
267 |
|
nd.specfl |= SP_FLAT; |
268 |
|
|
269 |
|
getacoords(r, &nd); /* set up coordinates */ |
293 |
|
} |
294 |
|
/* add direct component */ |
295 |
|
direct(r, diraniso, &nd); |
296 |
+ |
|
297 |
+ |
return(1); |
298 |
|
} |
299 |
|
|
300 |
|
|