| 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); |
| 347 |
|
FVECT h; |
| 348 |
|
double rv[2]; |
| 349 |
|
double d, sinp, cosp; |
| 350 |
< |
int confuse; |
| 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) { |
| 328 |
– |
confuse = 0; |
| 355 |
|
dimlist[ndims++] = (int)np->mp; |
| 356 |
< |
refagain: |
| 357 |
< |
dimlist[ndims] = confuse += 3601; |
| 358 |
< |
d = urand(ilhash(dimlist,ndims+1)+samplendx); |
| 359 |
< |
multisamp(rv, 2, d); |
| 360 |
< |
d = 2.0*PI * rv[0]; |
| 361 |
< |
cosp = np->u_alpha * cos(d); |
| 362 |
< |
sinp = np->v_alpha * sin(d); |
| 363 |
< |
d = sqrt(cosp*cosp + sinp*sinp); |
| 364 |
< |
cosp /= d; |
| 365 |
< |
sinp /= d; |
| 366 |
< |
if (rv[1] <= FTINY) |
| 367 |
< |
d = 1.0; |
| 368 |
< |
else |
| 369 |
< |
d = sqrt( -log(rv[1]) / |
| 370 |
< |
(cosp*cosp/(np->u_alpha*np->u_alpha) + |
| 371 |
< |
sinp*sinp/(np->v_alpha*np->v_alpha)) ); |
| 372 |
< |
for (i = 0; i < 3; i++) |
| 373 |
< |
h[i] = np->pnorm[i] + |
| 356 |
> |
for (ntries = 0; ntries < 10; ntries++) { |
| 357 |
> |
dimlist[ndims] = ntries * 3601; |
| 358 |
> |
d = urand(ilhash(dimlist,ndims+1)+samplendx); |
| 359 |
> |
multisamp(rv, 2, d); |
| 360 |
> |
d = 2.0*PI * rv[0]; |
| 361 |
> |
cosp = np->u_alpha * cos(d); |
| 362 |
> |
sinp = np->v_alpha * sin(d); |
| 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 |
| 370 |
> |
d = sqrt(-log(rv[1]) / |
| 371 |
> |
(cosp*cosp/(np->u_alpha*np->u_alpha) + |
| 372 |
> |
sinp*sinp/(np->v_alpha*np->v_alpha))); |
| 373 |
> |
for (i = 0; i < 3; i++) |
| 374 |
> |
h[i] = np->pnorm[i] + |
| 375 |
|
d*(cosp*np->u[i] + sinp*np->v[i]); |
| 376 |
< |
d = -2.0 * DOT(h, r->rdir) / (1.0 + d*d); |
| 377 |
< |
for (i = 0; i < 3; i++) |
| 378 |
< |
sr.rdir[i] = r->rdir[i] + d*h[i]; |
| 379 |
< |
if (DOT(sr.rdir, r->ron) <= FTINY) /* oops! */ |
| 380 |
< |
goto refagain; |
| 381 |
< |
rayvalue(&sr); |
| 382 |
< |
multcolor(sr.rcol, np->scolor); |
| 383 |
< |
addcolor(r->rcol, sr.rcol); |
| 376 |
> |
d = -2.0 * DOT(h, r->rdir) / (1.0 + d*d); |
| 377 |
> |
for (i = 0; i < 3; i++) |
| 378 |
> |
sr.rdir[i] = r->rdir[i] + d*h[i]; |
| 379 |
> |
if (DOT(sr.rdir, r->ron) > FTINY) { |
| 380 |
> |
rayvalue(&sr); |
| 381 |
> |
multcolor(sr.rcol, np->scolor); |
| 382 |
> |
addcolor(r->rcol, sr.rcol); |
| 383 |
> |
break; |
| 384 |
> |
} |
| 385 |
> |
} |
| 386 |
|
ndims--; |
| 387 |
|
} |
| 388 |
|
/* compute transmission */ |