1 |
< |
/* Copyright (c) 1986 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1998 Silicon Graphics, Inc. */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
4 |
> |
static char SCCSid[] = "$SunId$ SGI"; |
5 |
|
#endif |
6 |
|
|
7 |
|
/* |
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 COLOR salbedo; /* global scattering albedo */ |
55 |
|
|
56 |
< |
m_dielectric(m, r) /* color a ray which hit something transparent */ |
56 |
> |
|
57 |
> |
static double |
58 |
> |
mylog(x) /* special log for extinction coefficients */ |
59 |
> |
double x; |
60 |
> |
{ |
61 |
> |
if (x < 1e-40) |
62 |
> |
return(-100.); |
63 |
> |
if (x >= 1.) |
64 |
> |
return(0.); |
65 |
> |
return(log(x)); |
66 |
> |
} |
67 |
> |
|
68 |
> |
|
69 |
> |
m_dielectric(m, r) /* color a ray which hit a dielectric interface */ |
70 |
|
OBJREC *m; |
71 |
|
register RAY *r; |
72 |
|
{ |
56 |
– |
double sqrt(), pow(); |
73 |
|
double cos1, cos2, nratio; |
74 |
< |
COLOR mcolor; |
75 |
< |
double mabsorp; |
74 |
> |
COLOR ctrans; |
75 |
> |
COLOR talb; |
76 |
|
double refl, trans; |
77 |
|
FVECT dnorm; |
78 |
|
double d1, d2; |
82 |
|
if (m->oargs.nfargs != (m->otype==MAT_DIELECTRIC ? 5 : 8)) |
83 |
|
objerror(m, USER, "bad arguments"); |
84 |
|
|
69 |
– |
r->rt = r->rot; /* just use ray length */ |
70 |
– |
|
85 |
|
raytexture(r, m->omod); /* get modifiers */ |
86 |
|
|
87 |
|
cos1 = raynormal(dnorm, r); /* cosine of theta1 */ |
96 |
|
dnorm[0] = -dnorm[0]; |
97 |
|
dnorm[1] = -dnorm[1]; |
98 |
|
dnorm[2] = -dnorm[2]; |
99 |
< |
setcolor(mcolor, pow(m->oargs.farg[0], r->rot), |
100 |
< |
pow(m->oargs.farg[1], r->rot), |
101 |
< |
pow(m->oargs.farg[2], r->rot)); |
99 |
> |
setcolor(r->cext, -mylog(m->oargs.farg[0]*colval(r->pcol,RED)), |
100 |
> |
-mylog(m->oargs.farg[1]*colval(r->pcol,GRN)), |
101 |
> |
-mylog(m->oargs.farg[2]*colval(r->pcol,BLU))); |
102 |
> |
setcolor(r->albedo, 0., 0., 0.); |
103 |
> |
r->gecc = 0.; |
104 |
> |
if (m->otype == MAT_INTERFACE) { |
105 |
> |
setcolor(ctrans, |
106 |
> |
-mylog(m->oargs.farg[4]*colval(r->pcol,RED)), |
107 |
> |
-mylog(m->oargs.farg[5]*colval(r->pcol,GRN)), |
108 |
> |
-mylog(m->oargs.farg[6]*colval(r->pcol,BLU))); |
109 |
> |
setcolor(talb, 0., 0., 0.); |
110 |
> |
} else { |
111 |
> |
copycolor(ctrans, cextinction); |
112 |
> |
copycolor(talb, salbedo); |
113 |
> |
} |
114 |
|
} else { /* outside */ |
115 |
|
nratio = 1.0 / nratio; |
116 |
< |
if (m->otype == MAT_INTERFACE) |
117 |
< |
setcolor(mcolor, pow(m->oargs.farg[4], r->rot), |
118 |
< |
pow(m->oargs.farg[5], r->rot), |
119 |
< |
pow(m->oargs.farg[6], r->rot)); |
120 |
< |
else |
121 |
< |
setcolor(mcolor, 1.0, 1.0, 1.0); |
116 |
> |
|
117 |
> |
setcolor(ctrans, -mylog(m->oargs.farg[0]*colval(r->pcol,RED)), |
118 |
> |
-mylog(m->oargs.farg[1]*colval(r->pcol,GRN)), |
119 |
> |
-mylog(m->oargs.farg[2]*colval(r->pcol,BLU))); |
120 |
> |
setcolor(talb, 0., 0., 0.); |
121 |
> |
if (m->otype == MAT_INTERFACE) { |
122 |
> |
setcolor(r->cext, |
123 |
> |
-mylog(m->oargs.farg[4]*colval(r->pcol,RED)), |
124 |
> |
-mylog(m->oargs.farg[5]*colval(r->pcol,GRN)), |
125 |
> |
-mylog(m->oargs.farg[6]*colval(r->pcol,BLU))); |
126 |
> |
setcolor(r->albedo, 0., 0., 0.); |
127 |
> |
r->gecc = 0.; |
128 |
> |
} |
129 |
|
} |
97 |
– |
mabsorp = bright(mcolor); |
130 |
|
|
131 |
|
d2 = 1.0 - nratio*nratio*(1.0 - cos1*cos1); /* compute cos theta2 */ |
132 |
|
|
147 |
|
d1 = (d1 - d2) / (d1 + d2); |
148 |
|
refl += d1 * d1; |
149 |
|
|
150 |
< |
refl /= 2.0; |
150 |
> |
refl *= 0.5; |
151 |
|
trans = 1.0 - refl; |
152 |
|
|
153 |
< |
if (rayorigin(&p, r, REFRACTED, mabsorp*trans) == 0) { |
153 |
> |
if (rayorigin(&p, r, REFRACTED, trans) == 0) { |
154 |
|
|
155 |
|
/* compute refracted ray */ |
156 |
|
d1 = nratio*cos1 - cos2; |
161 |
|
if (m->otype != MAT_DIELECTRIC |
162 |
|
|| r->rod > 0.0 |
163 |
|
|| r->crtype & SHADOW |
164 |
< |
|| directinvis |
164 |
> |
|| !directvis |
165 |
|
|| m->oargs.farg[4] == 0.0 |
166 |
< |
|| !disperse(m, r, p.rdir, trans)) |
166 |
> |
|| !disperse(m, r, p.rdir, |
167 |
> |
trans, ctrans, talb)) |
168 |
|
#endif |
169 |
|
{ |
170 |
+ |
copycolor(p.cext, ctrans); |
171 |
+ |
copycolor(p.albedo, talb); |
172 |
|
rayvalue(&p); |
138 |
– |
multcolor(mcolor, r->pcol); /* modify */ |
173 |
|
scalecolor(p.rcol, trans); |
174 |
|
addcolor(r->rcol, p.rcol); |
175 |
+ |
if (nratio >= 1.0-FTINY && nratio <= 1.0+FTINY) |
176 |
+ |
r->rt = r->rot + p.rt; |
177 |
|
} |
178 |
|
} |
179 |
|
} |
180 |
|
|
181 |
|
if (!(r->crtype & SHADOW) && |
182 |
< |
rayorigin(&p, r, REFLECTED, mabsorp*refl) == 0) { |
182 |
> |
rayorigin(&p, r, REFLECTED, refl) == 0) { |
183 |
|
|
184 |
|
/* compute reflected ray */ |
185 |
|
for (i = 0; i < 3; i++) |
190 |
|
scalecolor(p.rcol, refl); /* color contribution */ |
191 |
|
addcolor(r->rcol, p.rcol); |
192 |
|
} |
193 |
< |
|
194 |
< |
multcolor(r->rcol, mcolor); /* multiply by transmittance */ |
193 |
> |
/* rayvalue() computes absorption */ |
194 |
> |
return(1); |
195 |
|
} |
196 |
|
|
197 |
|
|
198 |
|
#ifdef DISPERSE |
199 |
|
|
200 |
|
static |
201 |
< |
disperse(m, r, vt, tr) /* check light sources for dispersion */ |
201 |
> |
disperse(m, r, vt, tr, cet, abt) /* check light sources for dispersion */ |
202 |
|
OBJREC *m; |
203 |
|
RAY *r; |
204 |
|
FVECT vt; |
205 |
|
double tr; |
206 |
+ |
COLOR cet, abt; |
207 |
|
{ |
171 |
– |
double sqrt(); |
208 |
|
RAY sray, *entray; |
209 |
|
FVECT v1, v2, n1, n2; |
210 |
|
FVECT dv, v2Xdv; |
211 |
|
double v2Xdvv2Xdv; |
212 |
< |
int sn, success = 0; |
213 |
< |
double omega; |
212 |
> |
int success = 0; |
213 |
> |
SRCINDEX si; |
214 |
|
FVECT vtmp1, vtmp2; |
215 |
|
double dtmp1, dtmp2; |
216 |
|
int l1, l2; |
272 |
|
v2Xdvv2Xdv = DOT(v2Xdv, v2Xdv); |
273 |
|
|
274 |
|
/* check sources */ |
275 |
< |
for (sn = 0; sn < nsources; sn++) { |
275 |
> |
initsrcindex(&si); |
276 |
> |
while (srcray(&sray, r, &si)) { |
277 |
|
|
278 |
< |
if ((omega = srcray(&sray, r, sn)) == 0.0 || |
242 |
< |
DOT(sray.rdir, v2) < MINCOS) |
278 |
> |
if (DOT(sray.rdir, v2) < MINCOS) |
279 |
|
continue; /* bad source */ |
244 |
– |
|
280 |
|
/* adjust source ray */ |
281 |
|
|
282 |
|
dtmp1 = DOT(v2Xdv, sray.rdir) / v2Xdvv2Xdv; |
289 |
|
if (l1 > MAXLAMBDA || l1 < MINLAMBDA) /* not visible */ |
290 |
|
continue; |
291 |
|
/* trace source ray */ |
292 |
+ |
copycolor(sray.cext, cet); |
293 |
+ |
copycolor(sray.albedo, abt); |
294 |
|
normalize(sray.rdir); |
295 |
|
rayvalue(&sray); |
296 |
|
if (bright(sray.rcol) <= FTINY) /* missed it */ |
303 |
|
*/ |
304 |
|
|
305 |
|
fcross(vtmp1, v2Xdv, sray.rdir); |
306 |
< |
dtmp1 = sqrt(omega / v2Xdvv2Xdv / PI); |
306 |
> |
dtmp1 = sqrt(si.dom / v2Xdvv2Xdv / PI); |
307 |
|
|
308 |
|
/* compute first ray */ |
309 |
|
for (i = 0; i < 3; i++) |