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