8 |
|
#include "copyright.h" |
9 |
|
|
10 |
|
#include "ray.h" |
11 |
< |
|
11 |
> |
#include "ambient.h" |
12 |
|
#include "otypes.h" |
13 |
< |
|
13 |
> |
#include "rtotypes.h" |
14 |
> |
#include "source.h" |
15 |
|
#include "func.h" |
15 |
– |
|
16 |
|
#include "random.h" |
17 |
|
|
18 |
|
#ifndef MAXITER |
60 |
|
double pdot; /* perturbed dot product */ |
61 |
|
} ANISODAT; /* anisotropic material data */ |
62 |
|
|
63 |
< |
static void getacoords(); |
64 |
< |
static void agaussamp(); |
63 |
> |
static srcdirf_t diraniso; |
64 |
> |
static void getacoords(RAY *r, ANISODAT *np); |
65 |
> |
static void agaussamp(RAY *r, ANISODAT *np); |
66 |
|
|
67 |
|
|
68 |
|
static void |
69 |
< |
diraniso(cval, np, ldir, omega) /* compute source contribution */ |
70 |
< |
COLOR cval; /* returned coefficient */ |
71 |
< |
register ANISODAT *np; /* material data */ |
72 |
< |
FVECT ldir; /* light source direction */ |
73 |
< |
double omega; /* light source size */ |
69 |
> |
diraniso( /* compute source contribution */ |
70 |
> |
COLOR cval, /* returned coefficient */ |
71 |
> |
void *nnp, /* material data */ |
72 |
> |
FVECT ldir, /* light source direction */ |
73 |
> |
double omega /* light source size */ |
74 |
> |
) |
75 |
|
{ |
76 |
+ |
register ANISODAT *np = nnp; |
77 |
|
double ldot; |
78 |
|
double dtmp, dtmp1, dtmp2; |
79 |
|
FVECT h; |
94 |
|
* modified by the color of the material. |
95 |
|
*/ |
96 |
|
copycolor(ctmp, np->mcolor); |
97 |
< |
dtmp = ldot * omega * np->rdiff / PI; |
97 |
> |
dtmp = ldot * omega * np->rdiff * (1.0/PI); |
98 |
|
scalecolor(ctmp, dtmp); |
99 |
|
addcolor(cval, ctmp); |
100 |
|
} |
105 |
|
*/ |
106 |
|
/* add source width if flat */ |
107 |
|
if (np->specfl & SP_FLAT) |
108 |
< |
au2 = av2 = omega/(4.0*PI); |
108 |
> |
au2 = av2 = omega * (0.25/PI); |
109 |
|
else |
110 |
|
au2 = av2 = 0.0; |
111 |
|
au2 += np->u_alpha*np->u_alpha; |
122 |
|
/* gaussian */ |
123 |
|
dtmp = DOT(np->pnorm, h); |
124 |
|
dtmp = (dtmp1 + dtmp2) / (dtmp*dtmp); |
125 |
< |
dtmp = exp(-dtmp) * (0.25/PI) |
123 |
< |
* sqrt(ldot/(np->pdot*au2*av2)); |
125 |
> |
dtmp = exp(-dtmp) / (4.0*PI * np->pdot * sqrt(au2*av2)); |
126 |
|
/* worth using? */ |
127 |
|
if (dtmp > FTINY) { |
128 |
|
copycolor(ctmp, np->scolor); |
136 |
|
* Compute diffuse transmission. |
137 |
|
*/ |
138 |
|
copycolor(ctmp, np->mcolor); |
139 |
< |
dtmp = -ldot * omega * np->tdiff / PI; |
139 |
> |
dtmp = -ldot * omega * np->tdiff * (1.0/PI); |
140 |
|
scalecolor(ctmp, dtmp); |
141 |
|
addcolor(cval, ctmp); |
142 |
|
} |
146 |
|
* is always modified by material color. |
147 |
|
*/ |
148 |
|
/* roughness + source */ |
149 |
< |
au2 = av2 = omega / PI; |
149 |
> |
au2 = av2 = omega * (1.0/PI); |
150 |
|
au2 += np->u_alpha*np->u_alpha; |
151 |
|
av2 += np->v_alpha*np->v_alpha; |
152 |
|
/* "half vector" */ |
167 |
|
} else |
168 |
|
dtmp = 0.0; |
169 |
|
/* gaussian */ |
170 |
< |
dtmp = exp(-dtmp) * (1.0/PI) |
169 |
< |
* sqrt(-ldot/(np->pdot*au2*av2)); |
170 |
> |
dtmp = exp(-dtmp) / (PI * np->pdot * sqrt(au2*av2)); |
171 |
|
/* worth using? */ |
172 |
|
if (dtmp > FTINY) { |
173 |
|
copycolor(ctmp, np->mcolor); |
179 |
|
} |
180 |
|
|
181 |
|
|
182 |
< |
int |
183 |
< |
m_aniso(m, r) /* shade ray that hit something anisotropic */ |
184 |
< |
register OBJREC *m; |
185 |
< |
register RAY *r; |
182 |
> |
extern int |
183 |
> |
m_aniso( /* shade ray that hit something anisotropic */ |
184 |
> |
register OBJREC *m, |
185 |
> |
register RAY *r |
186 |
> |
) |
187 |
|
{ |
188 |
|
ANISODAT nd; |
189 |
|
COLOR ctmp; |
267 |
|
/* diffuse reflection */ |
268 |
|
nd.rdiff = 1.0 - nd.trans - nd.rspec; |
269 |
|
|
270 |
< |
if (r->ro != NULL && isflat(r->ro->otype) && |
269 |
< |
DOT(r->pert,r->pert) <= FTINY*FTINY) |
270 |
> |
if (r->ro != NULL && isflat(r->ro->otype)) |
271 |
|
nd.specfl |= SP_FLAT; |
272 |
|
|
273 |
|
getacoords(r, &nd); /* set up coordinates */ |
276 |
|
agaussamp(r, &nd); |
277 |
|
|
278 |
|
if (nd.rdiff > FTINY) { /* ambient from this side */ |
279 |
< |
ambient(ctmp, r, nd.pnorm); |
279 |
> |
copycolor(ctmp, nd.mcolor); /* modified by material color */ |
280 |
|
if (nd.specfl & SP_RBLT) |
281 |
|
scalecolor(ctmp, 1.0-nd.trans); |
282 |
|
else |
283 |
|
scalecolor(ctmp, nd.rdiff); |
284 |
< |
multcolor(ctmp, nd.mcolor); /* modified by material color */ |
284 |
> |
multambient(ctmp, r, nd.pnorm); |
285 |
|
addcolor(r->rcol, ctmp); /* add to returned color */ |
286 |
|
} |
287 |
|
if (nd.tdiff > FTINY) { /* ambient from other side */ |
291 |
|
bnorm[0] = -nd.pnorm[0]; |
292 |
|
bnorm[1] = -nd.pnorm[1]; |
293 |
|
bnorm[2] = -nd.pnorm[2]; |
294 |
< |
ambient(ctmp, r, bnorm); |
294 |
> |
copycolor(ctmp, nd.mcolor); /* modified by color */ |
295 |
|
if (nd.specfl & SP_TBLT) |
296 |
|
scalecolor(ctmp, nd.trans); |
297 |
|
else |
298 |
|
scalecolor(ctmp, nd.tdiff); |
299 |
< |
multcolor(ctmp, nd.mcolor); /* modified by color */ |
299 |
> |
multambient(ctmp, r, bnorm); |
300 |
|
addcolor(r->rcol, ctmp); |
301 |
|
flipsurface(r); |
302 |
|
} |
308 |
|
|
309 |
|
|
310 |
|
static void |
311 |
< |
getacoords(r, np) /* set up coordinate system */ |
312 |
< |
RAY *r; |
313 |
< |
register ANISODAT *np; |
311 |
> |
getacoords( /* set up coordinate system */ |
312 |
> |
RAY *r, |
313 |
> |
register ANISODAT *np |
314 |
> |
) |
315 |
|
{ |
316 |
|
register MFUNC *mf; |
317 |
|
register int i; |
339 |
|
|
340 |
|
|
341 |
|
static void |
342 |
< |
agaussamp(r, np) /* sample anisotropic gaussian specular */ |
343 |
< |
RAY *r; |
344 |
< |
register ANISODAT *np; |
342 |
> |
agaussamp( /* sample anisotropic gaussian specular */ |
343 |
> |
RAY *r, |
344 |
> |
register ANISODAT *np |
345 |
> |
) |
346 |
|
{ |
347 |
|
RAY sr; |
348 |
|
FVECT h; |
352 |
|
register int i; |
353 |
|
/* compute reflection */ |
354 |
|
if ((np->specfl & (SP_REFL|SP_RBLT)) == SP_REFL && |
355 |
< |
rayorigin(&sr, r, SPECULAR, np->rspec) == 0) { |
355 |
> |
rayorigin(&sr, SPECULAR, r, np->scolor) == 0) { |
356 |
|
dimlist[ndims++] = (int)np->mp; |
357 |
|
for (niter = 0; niter < MAXITER; niter++) { |
358 |
|
if (niter) |
381 |
|
sr.rdir[i] = r->rdir[i] + d*h[i]; |
382 |
|
if (DOT(sr.rdir, r->ron) > FTINY) { |
383 |
|
rayvalue(&sr); |
384 |
< |
multcolor(sr.rcol, np->scolor); |
384 |
> |
multcolor(sr.rcol, sr.rcoef); |
385 |
|
addcolor(r->rcol, sr.rcol); |
386 |
|
break; |
387 |
|
} |
389 |
|
ndims--; |
390 |
|
} |
391 |
|
/* compute transmission */ |
392 |
+ |
copycolor(sr.rcoef, np->mcolor); /* modify by material color */ |
393 |
+ |
scalecolor(sr.rcoef, np->tspec); |
394 |
|
if ((np->specfl & (SP_TRAN|SP_TBLT)) == SP_TRAN && |
395 |
< |
rayorigin(&sr, r, SPECULAR, np->tspec) == 0) { |
395 |
> |
rayorigin(&sr, SPECULAR, r, sr.rcoef) == 0) { |
396 |
|
dimlist[ndims++] = (int)np->mp; |
397 |
|
for (niter = 0; niter < MAXITER; niter++) { |
398 |
|
if (niter) |
419 |
|
if (DOT(sr.rdir, r->ron) < -FTINY) { |
420 |
|
normalize(sr.rdir); /* OK, normalize */ |
421 |
|
rayvalue(&sr); |
422 |
< |
scalecolor(sr.rcol, np->tspec); |
418 |
< |
multcolor(sr.rcol, np->mcolor); /* modify */ |
422 |
> |
multcolor(sr.rcol, sr.rcoef); |
423 |
|
addcolor(r->rcol, sr.rcol); |
424 |
|
break; |
425 |
|
} |