10 |
|
#include "ray.h" |
11 |
|
#include "otypes.h" |
12 |
|
#include "rtotypes.h" |
13 |
+ |
#include "pmapmat.h" |
14 |
|
|
15 |
|
#ifdef DISPERSE |
16 |
|
#include "source.h" |
51 |
|
|
52 |
|
#define MINCOS 0.997 /* minimum dot product for dispersion */ |
53 |
|
|
53 |
– |
|
54 |
|
static double |
55 |
|
mylog( /* special log for extinction coefficients */ |
56 |
|
double x |
64 |
|
} |
65 |
|
|
66 |
|
|
67 |
< |
extern int |
67 |
> |
int |
68 |
|
m_dielectric( /* color a ray which hit a dielectric interface */ |
69 |
|
OBJREC *m, |
70 |
< |
register RAY *r |
70 |
> |
RAY *r |
71 |
|
) |
72 |
|
{ |
73 |
|
double cos1, cos2, nratio; |
74 |
|
COLOR ctrans; |
75 |
|
COLOR talb; |
76 |
|
int hastexture; |
77 |
< |
double transdist, transtest=0; |
78 |
< |
double mirdist, mirtest=0; |
77 |
> |
double transdist=0, transtest=0; |
78 |
> |
double mirdist=0, mirtest=0; |
79 |
|
int flatsurface; |
80 |
|
double refl, trans; |
81 |
|
FVECT dnorm; |
82 |
|
double d1, d2; |
83 |
|
RAY p; |
84 |
< |
register int i; |
84 |
> |
int i; |
85 |
|
|
86 |
+ |
/* PMAP: skip refracted shadow or ambient ray if accounted for in |
87 |
+ |
photon map */ |
88 |
+ |
if (shadowRayInPmap(r) || ambRayInPmap(r)) |
89 |
+ |
return(1); |
90 |
+ |
|
91 |
|
if (m->oargs.nfargs != (m->otype==MAT_DIELECTRIC ? 5 : 8)) |
92 |
|
objerror(m, USER, "bad arguments"); |
93 |
|
|
99 |
|
VCOPY(dnorm, r->ron); |
100 |
|
cos1 = r->rod; |
101 |
|
} |
102 |
< |
flatsurface = !hastexture && r->ro != NULL && isflat(r->ro->otype); |
102 |
> |
flatsurface = r->ro != NULL && isflat(r->ro->otype) && |
103 |
> |
!hastexture | (r->crtype & AMBIENT); |
104 |
|
|
105 |
|
/* index of refraction */ |
106 |
|
if (m->otype == MAT_DIELECTRIC) |
170 |
|
|
171 |
|
trans *= nratio*nratio; /* solid angle ratio */ |
172 |
|
|
173 |
< |
if (rayorigin(&p, r, REFRACTED, trans) == 0) { |
173 |
> |
setcolor(p.rcoef, trans, trans, trans); |
174 |
|
|
175 |
+ |
if (rayorigin(&p, REFRACTED, r, p.rcoef) == 0) { |
176 |
+ |
|
177 |
|
/* compute refracted ray */ |
178 |
|
d1 = nratio*cos1 - cos2; |
179 |
|
for (i = 0; i < 3; i++) |
186 |
|
p.rdir[i] = nratio*r->rdir[i] + |
187 |
|
d1*r->ron[i]; |
188 |
|
normalize(p.rdir); /* not exact */ |
189 |
< |
} |
189 |
> |
} else |
190 |
> |
checknorm(p.rdir); |
191 |
|
#ifdef DISPERSE |
192 |
|
if (m->otype != MAT_DIELECTRIC |
193 |
|
|| r->rod > 0.0 |
201 |
|
copycolor(p.cext, ctrans); |
202 |
|
copycolor(p.albedo, talb); |
203 |
|
rayvalue(&p); |
204 |
< |
scalecolor(p.rcol, trans); |
204 |
> |
multcolor(p.rcol, p.rcoef); |
205 |
|
addcolor(r->rcol, p.rcol); |
206 |
|
/* virtual distance */ |
207 |
|
if (flatsurface || |
208 |
< |
(1.-FTINY <= nratio && |
209 |
< |
nratio <= 1.+FTINY)) { |
208 |
> |
(1.-FTINY <= nratio) & |
209 |
> |
(nratio <= 1.+FTINY)) { |
210 |
|
transtest = 2*bright(p.rcol); |
211 |
|
transdist = r->rot + p.rt; |
212 |
|
} |
213 |
|
} |
214 |
|
} |
215 |
|
} |
216 |
< |
|
216 |
> |
setcolor(p.rcoef, refl, refl, refl); |
217 |
> |
|
218 |
|
if (!(r->crtype & SHADOW) && |
219 |
< |
rayorigin(&p, r, REFLECTED, refl) == 0) { |
219 |
> |
rayorigin(&p, REFLECTED, r, p.rcoef) == 0) { |
220 |
|
|
221 |
|
/* compute reflected ray */ |
222 |
< |
for (i = 0; i < 3; i++) |
213 |
< |
p.rdir[i] = r->rdir[i] + 2.0*cos1*dnorm[i]; |
222 |
> |
VSUM(p.rdir, r->rdir, dnorm, 2.*cos1); |
223 |
|
/* accidental penetration? */ |
224 |
|
if (hastexture && DOT(p.rdir,r->ron)*hastexture <= FTINY) |
225 |
< |
for (i = 0; i < 3; i++) /* ignore texture */ |
226 |
< |
p.rdir[i] = r->rdir[i] + 2.0*r->rod*r->ron[i]; |
218 |
< |
|
225 |
> |
VSUM(p.rdir, r->rdir, r->ron, 2.*r->rod); |
226 |
> |
checknorm(p.rdir); |
227 |
|
rayvalue(&p); /* reflected ray value */ |
228 |
|
|
229 |
< |
scalecolor(p.rcol, refl); /* color contribution */ |
229 |
> |
multcolor(p.rcol, p.rcoef); /* color contribution */ |
230 |
|
addcolor(r->rcol, p.rcol); |
231 |
|
/* virtual distance */ |
232 |
|
if (flatsurface) { |
257 |
|
COLOR abt |
258 |
|
) |
259 |
|
{ |
260 |
< |
RAY sray, *entray; |
260 |
> |
RAY sray; |
261 |
> |
const RAY *entray; |
262 |
|
FVECT v1, v2, n1, n2; |
263 |
|
FVECT dv, v2Xdv; |
264 |
|
double v2Xdvv2Xdv; |
313 |
|
VCOPY(n2, r->ron); |
314 |
|
|
315 |
|
/* first order dispersion approx. */ |
316 |
< |
dtmp1 = DOT(n1, v1); |
317 |
< |
dtmp2 = DOT(n2, v2); |
316 |
> |
dtmp1 = 1./DOT(n1, v1); |
317 |
> |
dtmp2 = 1./DOT(n2, v2); |
318 |
|
for (i = 0; i < 3; i++) |
319 |
< |
dv[i] = v1[i] + v2[i] - n1[i]/dtmp1 - n2[i]/dtmp2; |
319 |
> |
dv[i] = v1[i] + v2[i] - n1[i]*dtmp1 - n2[i]*dtmp2; |
320 |
|
|
321 |
|
if (DOT(dv, dv) <= FTINY) /* null effect */ |
322 |
|
return(0); |
359 |
|
dtmp1 = sqrt(si.dom / v2Xdvv2Xdv / PI); |
360 |
|
|
361 |
|
/* compute first ray */ |
362 |
< |
for (i = 0; i < 3; i++) |
354 |
< |
vtmp2[i] = sray.rdir[i] + dtmp1*vtmp1[i]; |
362 |
> |
VSUM(vtmp2, sray.rdir, vtmp1, dtmp1); |
363 |
|
|
364 |
|
l1 = lambda(m, v2, dv, vtmp2); /* first lambda */ |
365 |
|
if (l1 < 0) |
366 |
|
continue; |
367 |
|
/* compute second ray */ |
368 |
< |
for (i = 0; i < 3; i++) |
361 |
< |
vtmp2[i] = sray.rdir[i] - dtmp1*vtmp1[i]; |
368 |
> |
VSUM(vtmp2, sray.rdir, vtmp1, -dtmp1); |
369 |
|
|
370 |
|
l2 = lambda(m, v2, dv, vtmp2); /* second lambda */ |
371 |
|
if (l2 < 0) |
386 |
|
|
387 |
|
static int |
388 |
|
lambda( /* compute lambda for material */ |
389 |
< |
register OBJREC *m, |
389 |
> |
OBJREC *m, |
390 |
|
FVECT v2, |
391 |
|
FVECT dv, |
392 |
|
FVECT lr |
398 |
|
|
399 |
|
fcross(lrXdv, lr, dv); |
400 |
|
for (i = 0; i < 3; i++) |
401 |
< |
if (lrXdv[i] > FTINY || lrXdv[i] < -FTINY) |
401 |
> |
if ((lrXdv[i] > FTINY) | (lrXdv[i] < -FTINY)) |
402 |
|
break; |
403 |
|
if (i >= 3) |
404 |
|
return(-1); |