| 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 (nd.rspec <= specthresh+FTINY) |
| 210 |
+ |
nd.specfl |= SP_RBLT; |
| 211 |
|
|
| 212 |
|
if (!(r->crtype & SHADOW) && nd.specfl & SP_PURE) { |
| 213 |
|
RAY lr; |
| 228 |
|
nd.tdiff = nd.trans - nd.tspec; |
| 229 |
|
if (nd.tspec > FTINY) { |
| 230 |
|
nd.specfl |= SP_TRAN; |
| 231 |
+ |
/* check threshold */ |
| 232 |
+ |
if (nd.tspec <= specthresh+FTINY) |
| 233 |
+ |
nd.specfl |= SP_TBLT; |
| 234 |
|
if (r->crtype & SHADOW || |
| 235 |
|
DOT(r->pert,r->pert) <= FTINY*FTINY) { |
| 236 |
|
VCOPY(nd.prdir, r->rdir); |
| 266 |
|
if (nd.specfl & SP_PURE && nd.rdiff <= FTINY && nd.tdiff <= FTINY) |
| 267 |
|
return; /* 100% pure specular */ |
| 268 |
|
|
| 269 |
+ |
if (r->ro->otype == OBJ_FACE || r->ro->otype == OBJ_RING) |
| 270 |
+ |
nd.specfl |= SP_FLAT; |
| 271 |
+ |
|
| 272 |
|
getacoords(r, &nd); /* set up coordinates */ |
| 273 |
|
|
| 274 |
|
if (nd.specfl & (SP_REFL|SP_TRAN) && !(nd.specfl & (SP_PURE|SP_BADU))) |
| 276 |
|
|
| 277 |
|
if (nd.rdiff > FTINY) { /* ambient from this side */ |
| 278 |
|
ambient(ctmp, r); |
| 279 |
< |
scalecolor(ctmp, nd.rdiff); |
| 279 |
> |
if (nd.specfl & SP_RBLT) |
| 280 |
> |
scalecolor(ctmp, 1.0-nd.trans); |
| 281 |
> |
else |
| 282 |
> |
scalecolor(ctmp, nd.rdiff); |
| 283 |
|
multcolor(ctmp, nd.mcolor); /* modified by material color */ |
| 284 |
|
addcolor(r->rcol, ctmp); /* add to returned color */ |
| 285 |
|
} |
| 286 |
|
if (nd.tdiff > FTINY) { /* ambient from other side */ |
| 287 |
|
flipsurface(r); |
| 288 |
|
ambient(ctmp, r); |
| 289 |
< |
scalecolor(ctmp, nd.tdiff); |
| 289 |
> |
if (nd.specfl & SP_TBLT) |
| 290 |
> |
scalecolor(ctmp, nd.trans); |
| 291 |
> |
else |
| 292 |
> |
scalecolor(ctmp, nd.tdiff); |
| 293 |
|
multcolor(ctmp, nd.mcolor); /* modified by color */ |
| 294 |
|
addcolor(r->rcol, ctmp); |
| 295 |
|
flipsurface(r); |
| 343 |
|
int ntries; |
| 344 |
|
register int i; |
| 345 |
|
/* compute reflection */ |
| 346 |
< |
if (np->specfl & SP_REFL && |
| 346 |
> |
if ((np->specfl & (SP_REFL|SP_RBLT)) == SP_REFL && |
| 347 |
|
rayorigin(&sr, r, SPECULAR, np->rspec) == 0) { |
| 348 |
|
dimlist[ndims++] = (int)np->mp; |
| 349 |
|
for (ntries = 0; ntries < 10; ntries++) { |
| 356 |
|
d = sqrt(cosp*cosp + sinp*sinp); |
| 357 |
|
cosp /= d; |
| 358 |
|
sinp /= d; |
| 359 |
+ |
rv[1] = 1.0 - specjitter*rv[1]; |
| 360 |
|
if (rv[1] <= FTINY) |
| 361 |
|
d = 1.0; |
| 362 |
|
else |