16 |
|
|
17 |
|
#ifdef DISPERSE |
18 |
|
#include "source.h" |
19 |
+ |
static disperse(); |
20 |
+ |
static int lambda(); |
21 |
|
#endif |
22 |
|
|
23 |
|
/* |
50 |
|
|
51 |
|
#define MINCOS 0.997 /* minimum dot product for dispersion */ |
52 |
|
|
53 |
+ |
extern COLOR cextinction; /* global coefficient of extinction */ |
54 |
+ |
extern double salbedo; /* global scattering albedo */ |
55 |
|
|
56 |
< |
m_dielectric(m, r) /* color a ray which hit something transparent */ |
56 |
> |
|
57 |
> |
m_dielectric(m, r) /* color a ray which hit a dielectric interface */ |
58 |
|
OBJREC *m; |
59 |
|
register RAY *r; |
60 |
|
{ |
56 |
– |
double sqrt(), pow(); |
61 |
|
double cos1, cos2, nratio; |
62 |
< |
COLOR mcolor; |
62 |
> |
COLOR ctrans; |
63 |
> |
double talb; |
64 |
|
double mabsorp; |
65 |
< |
double refl, trans, transbright; |
65 |
> |
double refl, trans; |
66 |
|
FVECT dnorm; |
67 |
|
double d1, d2; |
68 |
|
RAY p; |
85 |
|
dnorm[0] = -dnorm[0]; |
86 |
|
dnorm[1] = -dnorm[1]; |
87 |
|
dnorm[2] = -dnorm[2]; |
88 |
< |
setcolor(mcolor, pow(m->oargs.farg[0], r->rot), |
89 |
< |
pow(m->oargs.farg[1], r->rot), |
90 |
< |
pow(m->oargs.farg[2], r->rot)); |
88 |
> |
setcolor(r->cext, -log(m->oargs.farg[0]*colval(r->pcol,RED)), |
89 |
> |
-log(m->oargs.farg[1]*colval(r->pcol,GRN)), |
90 |
> |
-log(m->oargs.farg[2]*colval(r->pcol,BLU))); |
91 |
> |
r->albedo = 0.; |
92 |
> |
r->gecc = 0.; |
93 |
> |
if (m->otype == MAT_INTERFACE) { |
94 |
> |
setcolor(ctrans, |
95 |
> |
-log(m->oargs.farg[4]*colval(r->pcol,RED)), |
96 |
> |
-log(m->oargs.farg[5]*colval(r->pcol,GRN)), |
97 |
> |
-log(m->oargs.farg[6]*colval(r->pcol,BLU))); |
98 |
> |
talb = 0.; |
99 |
> |
} else { |
100 |
> |
copycolor(ctrans, cextinction); |
101 |
> |
talb = salbedo; |
102 |
> |
} |
103 |
|
} else { /* outside */ |
104 |
|
nratio = 1.0 / nratio; |
105 |
< |
if (m->otype == MAT_INTERFACE) |
106 |
< |
setcolor(mcolor, pow(m->oargs.farg[4], r->rot), |
107 |
< |
pow(m->oargs.farg[5], r->rot), |
108 |
< |
pow(m->oargs.farg[6], r->rot)); |
109 |
< |
else |
110 |
< |
setcolor(mcolor, 1.0, 1.0, 1.0); |
105 |
> |
|
106 |
> |
setcolor(ctrans, -log(m->oargs.farg[0]*colval(r->pcol,RED)), |
107 |
> |
-log(m->oargs.farg[1]*colval(r->pcol,GRN)), |
108 |
> |
-log(m->oargs.farg[2]*colval(r->pcol,BLU))); |
109 |
> |
talb = 0.; |
110 |
> |
if (m->otype == MAT_INTERFACE) { |
111 |
> |
setcolor(r->cext, |
112 |
> |
-log(m->oargs.farg[4]*colval(r->pcol,RED)), |
113 |
> |
-log(m->oargs.farg[5]*colval(r->pcol,GRN)), |
114 |
> |
-log(m->oargs.farg[6]*colval(r->pcol,BLU))); |
115 |
> |
r->albedo = 0.; |
116 |
> |
r->gecc = 0.; |
117 |
> |
} |
118 |
|
} |
119 |
< |
mabsorp = bright(mcolor); |
119 |
> |
mabsorp = exp(-bright(r->cext)*r->rot); /* approximate */ |
120 |
|
|
121 |
|
d2 = 1.0 - nratio*nratio*(1.0 - cos1*cos1); /* compute cos theta2 */ |
122 |
|
|
137 |
|
d1 = (d1 - d2) / (d1 + d2); |
138 |
|
refl += d1 * d1; |
139 |
|
|
140 |
< |
refl /= 2.0; |
140 |
> |
refl *= 0.5; |
141 |
|
trans = 1.0 - refl; |
118 |
– |
transbright = -FTINY; |
142 |
|
|
143 |
|
if (rayorigin(&p, r, REFRACTED, mabsorp*trans) == 0) { |
144 |
|
|
151 |
|
if (m->otype != MAT_DIELECTRIC |
152 |
|
|| r->rod > 0.0 |
153 |
|
|| r->crtype & SHADOW |
154 |
+ |
|| !directvis |
155 |
|
|| m->oargs.farg[4] == 0.0 |
156 |
|
|| !disperse(m, r, p.rdir, trans)) |
157 |
|
#endif |
158 |
|
{ |
159 |
+ |
copycolor(p.cext, ctrans); |
160 |
+ |
p.albedo = talb; |
161 |
|
rayvalue(&p); |
136 |
– |
multcolor(mcolor, r->pcol); /* modify */ |
162 |
|
scalecolor(p.rcol, trans); |
163 |
|
addcolor(r->rcol, p.rcol); |
164 |
< |
transbright = bright(p.rcol); |
165 |
< |
r->rt = r->rot + p.rt; |
164 |
> |
if (nratio >= 1.0-FTINY && nratio <= 1.0+FTINY) |
165 |
> |
r->rt = r->rot + p.rt; |
166 |
|
} |
167 |
|
} |
168 |
|
} |
178 |
|
|
179 |
|
scalecolor(p.rcol, refl); /* color contribution */ |
180 |
|
addcolor(r->rcol, p.rcol); |
156 |
– |
if (bright(p.rcol) > transbright) |
157 |
– |
r->rt = r->rot + p.rt; |
181 |
|
} |
182 |
< |
|
183 |
< |
multcolor(r->rcol, mcolor); /* multiply by transmittance */ |
182 |
> |
/* rayvalue() computes absorption */ |
183 |
> |
return(1); |
184 |
|
} |
185 |
|
|
186 |
|
|
193 |
|
FVECT vt; |
194 |
|
double tr; |
195 |
|
{ |
173 |
– |
double sqrt(); |
196 |
|
RAY sray, *entray; |
197 |
|
FVECT v1, v2, n1, n2; |
198 |
|
FVECT dv, v2Xdv; |
199 |
|
double v2Xdvv2Xdv; |
200 |
< |
int sn, success = 0; |
201 |
< |
double omega; |
200 |
> |
int success = 0; |
201 |
> |
SRCINDEX si; |
202 |
|
FVECT vtmp1, vtmp2; |
203 |
|
double dtmp1, dtmp2; |
204 |
|
int l1, l2; |
260 |
|
v2Xdvv2Xdv = DOT(v2Xdv, v2Xdv); |
261 |
|
|
262 |
|
/* check sources */ |
263 |
< |
for (sn = 0; sn < nsources; sn++) { |
263 |
> |
initsrcindex(&si); |
264 |
> |
while (srcray(&sray, r, &si)) { |
265 |
|
|
266 |
< |
if ((omega = srcray(&sray, r, sn)) == 0.0 || |
244 |
< |
DOT(sray.rdir, v2) < MINCOS) |
266 |
> |
if (DOT(sray.rdir, v2) < MINCOS) |
267 |
|
continue; /* bad source */ |
246 |
– |
|
268 |
|
/* adjust source ray */ |
269 |
|
|
270 |
|
dtmp1 = DOT(v2Xdv, sray.rdir) / v2Xdvv2Xdv; |
289 |
|
*/ |
290 |
|
|
291 |
|
fcross(vtmp1, v2Xdv, sray.rdir); |
292 |
< |
dtmp1 = sqrt(omega / v2Xdvv2Xdv / PI); |
292 |
> |
dtmp1 = sqrt(si.dom / v2Xdvv2Xdv / PI); |
293 |
|
|
294 |
|
/* compute first ray */ |
295 |
|
for (i = 0; i < 3; i++) |