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; |
66 |
|
FVECT dnorm; |
71 |
|
if (m->oargs.nfargs != (m->otype==MAT_DIELECTRIC ? 5 : 8)) |
72 |
|
objerror(m, USER, "bad arguments"); |
73 |
|
|
69 |
– |
r->rt = r->rot; /* just use ray length */ |
70 |
– |
|
74 |
|
raytexture(r, m->omod); /* get modifiers */ |
75 |
|
|
76 |
|
cos1 = raynormal(dnorm, r); /* cosine of theta1 */ |
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; |
142 |
|
|
143 |
|
if (rayorigin(&p, r, REFRACTED, mabsorp*trans) == 0) { |
151 |
|
if (m->otype != MAT_DIELECTRIC |
152 |
|
|| r->rod > 0.0 |
153 |
|
|| r->crtype & SHADOW |
154 |
< |
|| directinvis |
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); |
138 |
– |
multcolor(mcolor, r->pcol); /* modify */ |
162 |
|
scalecolor(p.rcol, trans); |
163 |
|
addcolor(r->rcol, p.rcol); |
164 |
+ |
if (nratio >= 1.0-FTINY && nratio <= 1.0+FTINY) |
165 |
+ |
r->rt = r->rot + p.rt; |
166 |
|
} |
167 |
|
} |
168 |
|
} |
179 |
|
scalecolor(p.rcol, refl); /* color contribution */ |
180 |
|
addcolor(r->rcol, p.rcol); |
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 |
|
{ |
171 |
– |
double sqrt(); |
196 |
|
RAY sray, *entray; |
197 |
|
FVECT v1, v2, n1, n2; |
198 |
|
FVECT dv, v2Xdv; |