16 |
|
|
17 |
|
#include "random.h" |
18 |
|
|
19 |
+ |
extern double specthresh; /* specular sampling threshold */ |
20 |
+ |
extern double specjitter; /* specular sampling jitter */ |
21 |
+ |
|
22 |
|
/* |
23 |
|
* This anisotropic reflection model uses a variant on the |
24 |
|
* exponential Gaussian used in normal.c. |
40 |
|
#define SP_REFL 01 /* has reflected specular component */ |
41 |
|
#define SP_TRAN 02 /* has transmitted specular */ |
42 |
|
#define SP_PURE 010 /* purely specular (zero roughness) */ |
43 |
< |
#define SP_BADU 020 /* bad u direction calculation */ |
44 |
< |
#define SP_FLAT 040 /* reflecting surface is flat */ |
43 |
> |
#define SP_FLAT 020 /* reflecting surface is flat */ |
44 |
> |
#define SP_RBLT 040 /* reflection below sample threshold */ |
45 |
> |
#define SP_TBLT 0100 /* transmission below threshold */ |
46 |
> |
#define SP_BADU 0200 /* bad u direction calculation */ |
47 |
|
|
48 |
|
typedef struct { |
49 |
|
OBJREC *mp; /* material pointer */ |
205 |
|
for (i = 0; i < 3; i++) |
206 |
|
colval(nd.scolor,i) += (1.0-colval(nd.scolor,i))*dtmp; |
207 |
|
nd.rspec += (1.0-nd.rspec)*dtmp; |
208 |
+ |
/* check threshold */ |
209 |
+ |
if (specthresh > FTINY && |
210 |
+ |
((specthresh >= 1.-FTINY || |
211 |
+ |
specthresh + (.1 - .2*urand(8199+samplendx)) |
212 |
+ |
> nd.rspec))) |
213 |
+ |
nd.specfl |= SP_RBLT; |
214 |
|
|
215 |
|
if (!(r->crtype & SHADOW) && nd.specfl & SP_PURE) { |
216 |
|
RAY lr; |
231 |
|
nd.tdiff = nd.trans - nd.tspec; |
232 |
|
if (nd.tspec > FTINY) { |
233 |
|
nd.specfl |= SP_TRAN; |
234 |
+ |
/* check threshold */ |
235 |
+ |
if (specthresh > FTINY && |
236 |
+ |
((specthresh >= 1.-FTINY || |
237 |
+ |
specthresh + |
238 |
+ |
(.1 - .2*urand(7241+samplendx)) |
239 |
+ |
> nd.tspec))) |
240 |
+ |
nd.specfl |= SP_TBLT; |
241 |
|
if (r->crtype & SHADOW || |
242 |
|
DOT(r->pert,r->pert) <= FTINY*FTINY) { |
243 |
|
VCOPY(nd.prdir, r->rdir); |
273 |
|
if (nd.specfl & SP_PURE && nd.rdiff <= FTINY && nd.tdiff <= FTINY) |
274 |
|
return; /* 100% pure specular */ |
275 |
|
|
276 |
+ |
if (r->ro->otype == OBJ_FACE || r->ro->otype == OBJ_RING) |
277 |
+ |
nd.specfl |= SP_FLAT; |
278 |
+ |
|
279 |
|
getacoords(r, &nd); /* set up coordinates */ |
280 |
|
|
281 |
|
if (nd.specfl & (SP_REFL|SP_TRAN) && !(nd.specfl & (SP_PURE|SP_BADU))) |
283 |
|
|
284 |
|
if (nd.rdiff > FTINY) { /* ambient from this side */ |
285 |
|
ambient(ctmp, r); |
286 |
< |
scalecolor(ctmp, nd.rdiff); |
286 |
> |
if (nd.specfl & SP_RBLT) |
287 |
> |
scalecolor(ctmp, 1.0-nd.trans); |
288 |
> |
else |
289 |
> |
scalecolor(ctmp, nd.rdiff); |
290 |
|
multcolor(ctmp, nd.mcolor); /* modified by material color */ |
291 |
|
addcolor(r->rcol, ctmp); /* add to returned color */ |
292 |
|
} |
293 |
|
if (nd.tdiff > FTINY) { /* ambient from other side */ |
294 |
|
flipsurface(r); |
295 |
|
ambient(ctmp, r); |
296 |
< |
scalecolor(ctmp, nd.tdiff); |
296 |
> |
if (nd.specfl & SP_TBLT) |
297 |
> |
scalecolor(ctmp, nd.trans); |
298 |
> |
else |
299 |
> |
scalecolor(ctmp, nd.tdiff); |
300 |
|
multcolor(ctmp, nd.mcolor); /* modified by color */ |
301 |
|
addcolor(r->rcol, ctmp); |
302 |
|
flipsurface(r); |
350 |
|
int ntries; |
351 |
|
register int i; |
352 |
|
/* compute reflection */ |
353 |
< |
if (np->specfl & SP_REFL && |
353 |
> |
if ((np->specfl & (SP_REFL|SP_RBLT)) == SP_REFL && |
354 |
|
rayorigin(&sr, r, SPECULAR, np->rspec) == 0) { |
355 |
|
dimlist[ndims++] = (int)np->mp; |
356 |
|
for (ntries = 0; ntries < 10; ntries++) { |
363 |
|
d = sqrt(cosp*cosp + sinp*sinp); |
364 |
|
cosp /= d; |
365 |
|
sinp /= d; |
366 |
+ |
rv[1] = 1.0 - specjitter*rv[1]; |
367 |
|
if (rv[1] <= FTINY) |
368 |
|
d = 1.0; |
369 |
|
else |