41 |
|
#define SP_REFL 01 /* has reflected specular component */ |
42 |
|
#define SP_TRAN 02 /* has transmitted specular */ |
43 |
|
#define SP_PURE 010 /* purely specular (zero roughness) */ |
44 |
+ |
#define SP_FLAT 020 /* flat reflecting surface */ |
45 |
|
|
46 |
|
typedef struct { |
47 |
|
OBJREC *mp; /* material pointer */ |
67 |
|
{ |
68 |
|
double ldot; |
69 |
|
double dtmp; |
70 |
+ |
int i; |
71 |
|
COLOR ctmp; |
72 |
|
|
73 |
|
setcolor(cval, 0.0, 0.0, 0.0); |
93 |
|
* Compute specular reflection coefficient using |
94 |
|
* gaussian distribution model. |
95 |
|
*/ |
96 |
< |
/* roughness + source */ |
97 |
< |
dtmp = 2.0*np->alpha2 + omega/(2.0*PI); |
96 |
> |
/* roughness */ |
97 |
> |
dtmp = 2.0*np->alpha2; |
98 |
> |
/* + source if flat */ |
99 |
> |
if (np->specfl & SP_FLAT) |
100 |
> |
dtmp += omega/(2.0*PI); |
101 |
|
/* gaussian */ |
102 |
|
dtmp = exp((DOT(np->vrefl,ldir)-1.)/dtmp)/(2.*PI)/dtmp; |
103 |
|
/* worth using? */ |
242 |
|
if (nd.specfl & SP_PURE && nd.rdiff <= FTINY && nd.tdiff <= FTINY) |
243 |
|
return; /* 100% pure specular */ |
244 |
|
|
245 |
+ |
if (r->ro->otype == OBJ_FACE || r->ro->otype == OBJ_RING) |
246 |
+ |
nd.specfl |= SP_FLAT; |
247 |
+ |
|
248 |
|
if (nd.specfl & (SP_REFL|SP_TRAN) && !(nd.specfl & SP_PURE)) |
249 |
|
gaussamp(r, &nd); |
250 |
|
|
279 |
|
FVECT u, v, h; |
280 |
|
double rv[2]; |
281 |
|
double d, sinp, cosp; |
282 |
< |
int confuse; |
282 |
> |
int ntries; |
283 |
|
register int i; |
284 |
|
/* set up sample coordinates */ |
285 |
|
v[0] = v[1] = v[2] = 0.0; |
293 |
|
/* compute reflection */ |
294 |
|
if (np->specfl & SP_REFL && |
295 |
|
rayorigin(&sr, r, SPECULAR, np->rspec) == 0) { |
288 |
– |
confuse = 0; |
296 |
|
dimlist[ndims++] = (int)np->mp; |
297 |
< |
refagain: |
298 |
< |
dimlist[ndims] = confuse += 3601; |
299 |
< |
d = urand(ilhash(dimlist,ndims+1)+samplendx); |
300 |
< |
multisamp(rv, 2, d); |
301 |
< |
d = 2.0*PI * rv[0]; |
302 |
< |
cosp = cos(d); |
303 |
< |
sinp = sin(d); |
304 |
< |
if (rv[1] <= FTINY) |
305 |
< |
d = 1.0; |
306 |
< |
else |
307 |
< |
d = sqrt( np->alpha2 * -log(rv[1]) ); |
308 |
< |
for (i = 0; i < 3; i++) |
309 |
< |
h[i] = np->pnorm[i] + d*(cosp*u[i] + sinp*v[i]); |
310 |
< |
d = -2.0 * DOT(h, r->rdir) / (1.0 + d*d); |
311 |
< |
for (i = 0; i < 3; i++) |
312 |
< |
sr.rdir[i] = r->rdir[i] + d*h[i]; |
313 |
< |
if (DOT(sr.rdir, r->ron) <= FTINY) /* oops! */ |
314 |
< |
goto refagain; |
315 |
< |
rayvalue(&sr); |
316 |
< |
multcolor(sr.rcol, np->scolor); |
317 |
< |
addcolor(r->rcol, sr.rcol); |
297 |
> |
for (ntries = 0; ntries < 10; ntries++) { |
298 |
> |
dimlist[ndims] = ntries * 8912; |
299 |
> |
d = urand(ilhash(dimlist,ndims+1)+samplendx); |
300 |
> |
multisamp(rv, 2, d); |
301 |
> |
d = 2.0*PI * rv[0]; |
302 |
> |
cosp = cos(d); |
303 |
> |
sinp = sin(d); |
304 |
> |
if (rv[1] <= FTINY) |
305 |
> |
d = 1.0; |
306 |
> |
else |
307 |
> |
d = sqrt( np->alpha2 * -log(rv[1]) ); |
308 |
> |
for (i = 0; i < 3; i++) |
309 |
> |
h[i] = np->pnorm[i] + d*(cosp*u[i] + sinp*v[i]); |
310 |
> |
d = -2.0 * DOT(h, r->rdir) / (1.0 + d*d); |
311 |
> |
for (i = 0; i < 3; i++) |
312 |
> |
sr.rdir[i] = r->rdir[i] + d*h[i]; |
313 |
> |
if (DOT(sr.rdir, r->ron) > FTINY) { |
314 |
> |
rayvalue(&sr); |
315 |
> |
multcolor(sr.rcol, np->scolor); |
316 |
> |
addcolor(r->rcol, sr.rcol); |
317 |
> |
break; |
318 |
> |
} |
319 |
> |
} |
320 |
|
ndims--; |
321 |
|
} |
322 |
|
/* compute transmission */ |