53 |
|
FVECT vrefl; /* vector in reflected direction */ |
54 |
|
FVECT prdir; /* vector in transmitted direction */ |
55 |
|
FVECT u, v; /* u and v vectors orienting anisotropy */ |
56 |
< |
double u_alpha2; /* u roughness squared */ |
57 |
< |
double v_alpha2; /* v roughness squared */ |
56 |
> |
double u_alpha; /* u roughness */ |
57 |
> |
double v_alpha; /* v roughness */ |
58 |
|
double rdiff, rspec; /* reflected specular, diffuse */ |
59 |
|
double trans; /* transmissivity */ |
60 |
|
double tdiff, tspec; /* transmitted specular, diffuse */ |
103 |
|
au2 = av2 = omega/(4.0*PI); |
104 |
|
else |
105 |
|
au2 = av2 = 0.0; |
106 |
< |
au2 += np->u_alpha2; |
107 |
< |
av2 += np->v_alpha2; |
106 |
> |
au2 += np->u_alpha*np->u_alpha; |
107 |
> |
av2 += np->v_alpha*np->v_alpha; |
108 |
|
/* half vector */ |
109 |
|
h[0] = ldir[0] - np->rp->rdir[0]; |
110 |
|
h[1] = ldir[1] - np->rp->rdir[1]; |
117 |
|
dtmp2 *= dtmp2 / av2; |
118 |
|
/* gaussian */ |
119 |
|
dtmp = (dtmp1 + dtmp2) / (1.0 + DOT(np->pnorm, h)); |
120 |
< |
dtmp = exp(-2.0*dtmp) * 1.0/(4.0*PI) |
120 |
> |
dtmp = exp(-2.0*dtmp) * (1.0/4.0/PI) |
121 |
|
* sqrt(ldot/(np->pdot*au2*av2)); |
122 |
|
/* worth using? */ |
123 |
|
if (dtmp > FTINY) { |
143 |
|
*/ |
144 |
|
/* roughness + source */ |
145 |
|
au2 = av2 = omega / PI; |
146 |
< |
au2 += np->u_alpha2; |
147 |
< |
av2 += np->v_alpha2; |
146 |
> |
au2 += np->u_alpha*np->u_alpha; |
147 |
> |
av2 += np->v_alpha*np->v_alpha; |
148 |
|
/* "half vector" */ |
149 |
|
h[0] = ldir[0] - np->prdir[0]; |
150 |
|
h[1] = ldir[1] - np->prdir[1]; |
151 |
|
h[2] = ldir[2] - np->prdir[2]; |
152 |
< |
dtmp = DOT(h,np->pnorm); |
153 |
< |
dtmp = DOT(h,h) - dtmp*dtmp; |
152 |
> |
dtmp = DOT(h,h); |
153 |
|
if (dtmp > FTINY*FTINY) { |
154 |
< |
dtmp1 = DOT(h,np->u); |
155 |
< |
dtmp1 = dtmp1*dtmp1 / (au2*dtmp); |
156 |
< |
dtmp2 = DOT(h,np->v); |
157 |
< |
dtmp2 = dtmp2*dtmp2 / (av2*dtmp); |
158 |
< |
dtmp = 2. - 2.*DOT(ldir,np->prdir); |
159 |
< |
dtmp *= dtmp1 + dtmp2; |
154 |
> |
dtmp1 = DOT(h,np->pnorm); |
155 |
> |
dtmp = 1.0 - dtmp1*dtmp1/dtmp; |
156 |
> |
if (dtmp > FTINY*FTINY) { |
157 |
> |
dtmp1 = DOT(h,np->u); |
158 |
> |
dtmp1 = dtmp1*dtmp1 / au2; |
159 |
> |
dtmp2 = DOT(h,np->v); |
160 |
> |
dtmp2 = dtmp2*dtmp2 / av2; |
161 |
> |
dtmp = (dtmp1 + dtmp2) / dtmp; |
162 |
> |
} |
163 |
|
} else |
164 |
|
dtmp = 0.0; |
165 |
|
/* gaussian */ |
166 |
< |
dtmp = exp(-dtmp) * 1.0/(4.0*PI) |
166 |
> |
dtmp = exp(-dtmp) * (1.0/PI) |
167 |
|
* sqrt(-ldot/(np->pdot*au2*av2)); |
168 |
|
/* worth using? */ |
169 |
|
if (dtmp > FTINY) { |
198 |
|
m->oargs.farg[2]); |
199 |
|
/* get roughness */ |
200 |
|
nd.specfl = 0; |
201 |
< |
nd.u_alpha2 = m->oargs.farg[4]; |
202 |
< |
nd.u_alpha2 *= nd.u_alpha2; |
203 |
< |
nd.v_alpha2 = m->oargs.farg[5]; |
202 |
< |
nd.v_alpha2 *= nd.v_alpha2; |
203 |
< |
if (nd.u_alpha2 < FTINY*FTINY || nd.v_alpha2 <= FTINY*FTINY) |
201 |
> |
nd.u_alpha = m->oargs.farg[4]; |
202 |
> |
nd.v_alpha = m->oargs.farg[5]; |
203 |
> |
if (nd.u_alpha < FTINY || nd.v_alpha <= FTINY) |
204 |
|
objerror(m, USER, "roughness too small"); |
205 |
|
/* reorient if necessary */ |
206 |
|
if (r->rod < 0.0) |
347 |
|
d = urand(ilhash(dimlist,ndims)+samplendx); |
348 |
|
multisamp(rv, 2, d); |
349 |
|
d = 2.0*PI * rv[0]; |
350 |
< |
cosp = cos(d); |
351 |
< |
sinp = sin(d); |
352 |
< |
d = sqrt(np->u_alpha2*cosp*cosp + np->v_alpha2*sinp*sinp); |
350 |
> |
cosp = cos(d) * np->u_alpha; |
351 |
> |
sinp = sin(d) * np->v_alpha; |
352 |
> |
d = sqrt(cosp*cosp + sinp*sinp); |
353 |
|
cosp /= d; |
354 |
|
sinp /= d; |
355 |
|
rv[1] = 1.0 - specjitter*rv[1]; |
357 |
|
d = 1.0; |
358 |
|
else |
359 |
|
d = sqrt(-log(rv[1]) / |
360 |
< |
(cosp*cosp/np->u_alpha2 + |
361 |
< |
sinp*sinp/np->v_alpha2)); |
360 |
> |
(cosp*cosp/(np->u_alpha*np->u_alpha) + |
361 |
> |
sinp*sinp/(np->v_alpha*np->v_alpha))); |
362 |
|
for (i = 0; i < 3; i++) |
363 |
|
h[i] = np->pnorm[i] + |
364 |
|
d*(cosp*np->u[i] + sinp*np->v[i]); |
379 |
|
d = urand(ilhash(dimlist,ndims)+1823+samplendx); |
380 |
|
multisamp(rv, 2, d); |
381 |
|
d = 2.0*PI * rv[0]; |
382 |
< |
cosp = cos(d); |
383 |
< |
sinp = sin(d); |
382 |
> |
cosp = cos(d) * np->u_alpha; |
383 |
> |
sinp = sin(d) * np->v_alpha; |
384 |
> |
d = sqrt(cosp*cosp + sinp*sinp); |
385 |
> |
cosp /= d; |
386 |
> |
sinp /= d; |
387 |
|
rv[1] = 1.0 - specjitter*rv[1]; |
388 |
|
if (rv[1] <= FTINY) |
389 |
|
d = 1.0; |
390 |
|
else |
391 |
|
d = sqrt(-log(rv[1]) / |
392 |
< |
(cosp*cosp*4./np->u_alpha2 + |
393 |
< |
sinp*sinp*4./np->v_alpha2)); |
392 |
> |
(cosp*cosp/(np->u_alpha*np->u_alpha) + |
393 |
> |
sinp*sinp/(np->v_alpha*np->u_alpha))); |
394 |
|
for (i = 0; i < 3; i++) |
395 |
|
sr.rdir[i] = np->prdir[i] + |
396 |
|
d*(cosp*np->u[i] + sinp*np->v[i]); |