34 |
|
* 8 red grn blu rspec u-rough v-rough trans tspec |
35 |
|
*/ |
36 |
|
|
37 |
– |
#define BSPEC(m) (6.0) /* specularity parameter b */ |
38 |
– |
|
37 |
|
/* specularity flags */ |
38 |
|
#define SP_REFL 01 /* has reflected specular component */ |
39 |
|
#define SP_TRAN 02 /* has transmitted specular */ |
40 |
< |
#define SP_PURE 010 /* purely specular (zero roughness) */ |
41 |
< |
#define SP_FLAT 020 /* reflecting surface is flat */ |
42 |
< |
#define SP_RBLT 040 /* reflection below sample threshold */ |
43 |
< |
#define SP_TBLT 0100 /* transmission below threshold */ |
46 |
< |
#define SP_BADU 0200 /* bad u direction calculation */ |
40 |
> |
#define SP_FLAT 04 /* reflecting surface is flat */ |
41 |
> |
#define SP_RBLT 010 /* reflection below sample threshold */ |
42 |
> |
#define SP_TBLT 020 /* transmission below threshold */ |
43 |
> |
#define SP_BADU 040 /* bad u direction calculation */ |
44 |
|
|
45 |
|
typedef struct { |
46 |
|
OBJREC *mp; /* material pointer */ |
91 |
|
scalecolor(ctmp, dtmp); |
92 |
|
addcolor(cval, ctmp); |
93 |
|
} |
94 |
< |
if (ldot > FTINY && (np->specfl&(SP_REFL|SP_PURE|SP_BADU)) == SP_REFL) { |
94 |
> |
if (ldot > FTINY && (np->specfl&(SP_REFL|SP_BADU)) == SP_REFL) { |
95 |
|
/* |
96 |
|
* Compute specular reflection coefficient using |
97 |
|
* anisotropic gaussian distribution model. |
133 |
|
scalecolor(ctmp, dtmp); |
134 |
|
addcolor(cval, ctmp); |
135 |
|
} |
136 |
< |
if (ldot < -FTINY && (np->specfl&(SP_TRAN|SP_PURE|SP_BADU)) == SP_TRAN) { |
136 |
> |
if (ldot < -FTINY && (np->specfl&(SP_TRAN|SP_BADU)) == SP_TRAN) { |
137 |
|
/* |
138 |
|
* Compute specular transmission. Specular transmission |
139 |
|
* is always modified by material color. |
157 |
|
register RAY *r; |
158 |
|
{ |
159 |
|
ANISODAT nd; |
163 |
– |
double transtest, transdist; |
160 |
|
double dtmp; |
161 |
|
COLOR ctmp; |
162 |
|
register int i; |
163 |
|
/* easy shadow test */ |
164 |
< |
if (r->crtype & SHADOW && m->otype != MAT_TRANS2) |
164 |
> |
if (r->crtype & SHADOW) |
165 |
|
return; |
166 |
|
|
167 |
|
if (m->oargs.nfargs != (m->otype == MAT_TRANS2 ? 8 : 6)) |
176 |
|
nd.specfl = 0; |
177 |
|
nd.u_alpha = m->oargs.farg[4]; |
178 |
|
nd.v_alpha = m->oargs.farg[5]; |
179 |
< |
if (nd.u_alpha <= FTINY || nd.v_alpha <= FTINY) |
180 |
< |
nd.specfl |= SP_PURE; |
179 |
> |
if (nd.u_alpha < 1e-6 || nd.v_alpha <= 1e-6) |
180 |
> |
objerror(m, USER, "roughness too small"); |
181 |
|
/* reorient if necessary */ |
182 |
|
if (r->rod < 0.0) |
183 |
|
flipsurface(r); |
187 |
|
if (nd.pdot < .001) |
188 |
|
nd.pdot = .001; /* non-zero for diraniso() */ |
189 |
|
multcolor(nd.mcolor, r->pcol); /* modify material color */ |
194 |
– |
transtest = 0; |
190 |
|
/* get specular component */ |
191 |
|
if ((nd.rspec = m->oargs.farg[3]) > FTINY) { |
192 |
|
nd.specfl |= SP_REFL; |
196 |
|
else |
197 |
|
setcolor(nd.scolor, 1.0, 1.0, 1.0); |
198 |
|
scalecolor(nd.scolor, nd.rspec); |
204 |
– |
/* improved model */ |
205 |
– |
dtmp = exp(-BSPEC(m)*nd.pdot); |
206 |
– |
for (i = 0; i < 3; i++) |
207 |
– |
colval(nd.scolor,i) += (1.0-colval(nd.scolor,i))*dtmp; |
208 |
– |
nd.rspec += (1.0-nd.rspec)*dtmp; |
199 |
|
/* check threshold */ |
200 |
|
if (specthresh > FTINY && |
201 |
< |
((specthresh >= 1.-FTINY || |
202 |
< |
specthresh + (.1 - .2*urand(8199+samplendx)) |
213 |
< |
> nd.rspec))) |
201 |
> |
(specthresh >= 1.-FTINY || |
202 |
> |
specthresh > nd.rspec)) |
203 |
|
nd.specfl |= SP_RBLT; |
204 |
|
/* compute refl. direction */ |
205 |
|
for (i = 0; i < 3; i++) |
207 |
|
if (DOT(nd.vrefl, r->ron) <= FTINY) /* penetration? */ |
208 |
|
for (i = 0; i < 3; i++) /* safety measure */ |
209 |
|
nd.vrefl[i] = r->rdir[i] + 2.*r->rod*r->ron[i]; |
221 |
– |
|
222 |
– |
if (!(r->crtype & SHADOW) && nd.specfl & SP_PURE) { |
223 |
– |
RAY lr; |
224 |
– |
if (rayorigin(&lr, r, REFLECTED, nd.rspec) == 0) { |
225 |
– |
VCOPY(lr.rdir, nd.vrefl); |
226 |
– |
rayvalue(&lr); |
227 |
– |
multcolor(lr.rcol, nd.scolor); |
228 |
– |
addcolor(r->rcol, lr.rcol); |
229 |
– |
} |
230 |
– |
} |
210 |
|
} |
211 |
|
/* compute transmission */ |
212 |
|
if (m->otype == MAT_TRANS) { |
217 |
|
nd.specfl |= SP_TRAN; |
218 |
|
/* check threshold */ |
219 |
|
if (specthresh > FTINY && |
220 |
< |
((specthresh >= 1.-FTINY || |
221 |
< |
specthresh + |
243 |
< |
(.1 - .2*urand(7241+samplendx)) |
244 |
< |
> nd.tspec))) |
220 |
> |
(specthresh >= 1.-FTINY || |
221 |
> |
specthresh > nd.tspec)) |
222 |
|
nd.specfl |= SP_TBLT; |
223 |
< |
if (r->crtype & SHADOW || |
247 |
< |
DOT(r->pert,r->pert) <= FTINY*FTINY) { |
223 |
> |
if (DOT(r->pert,r->pert) <= FTINY*FTINY) { |
224 |
|
VCOPY(nd.prdir, r->rdir); |
249 |
– |
transtest = 2; |
225 |
|
} else { |
226 |
|
for (i = 0; i < 3; i++) /* perturb */ |
227 |
|
nd.prdir[i] = r->rdir[i] - |
234 |
|
} |
235 |
|
} else |
236 |
|
nd.tdiff = nd.tspec = nd.trans = 0.0; |
262 |
– |
/* transmitted ray */ |
263 |
– |
if ((nd.specfl&(SP_TRAN|SP_PURE)) == (SP_TRAN|SP_PURE)) { |
264 |
– |
RAY lr; |
265 |
– |
if (rayorigin(&lr, r, TRANS, nd.tspec) == 0) { |
266 |
– |
VCOPY(lr.rdir, nd.prdir); |
267 |
– |
rayvalue(&lr); |
268 |
– |
scalecolor(lr.rcol, nd.tspec); |
269 |
– |
multcolor(lr.rcol, nd.mcolor); /* modified by color */ |
270 |
– |
addcolor(r->rcol, lr.rcol); |
271 |
– |
transtest *= bright(lr.rcol); |
272 |
– |
transdist = r->rot + lr.rt; |
273 |
– |
} |
274 |
– |
} |
237 |
|
|
276 |
– |
if (r->crtype & SHADOW) /* the rest is shadow */ |
277 |
– |
return; |
238 |
|
/* diffuse reflection */ |
239 |
|
nd.rdiff = 1.0 - nd.trans - nd.rspec; |
240 |
|
|
241 |
< |
if (nd.specfl & SP_PURE && nd.rdiff <= FTINY && nd.tdiff <= FTINY) |
242 |
< |
return; /* 100% pure specular */ |
283 |
< |
|
284 |
< |
if (r->ro->otype == OBJ_FACE || r->ro->otype == OBJ_RING) |
241 |
> |
if (r->ro != NULL && (r->ro->otype == OBJ_FACE || |
242 |
> |
r->ro->otype == OBJ_RING)) |
243 |
|
nd.specfl |= SP_FLAT; |
244 |
|
|
245 |
|
getacoords(r, &nd); /* set up coordinates */ |
246 |
|
|
247 |
< |
if (nd.specfl & (SP_REFL|SP_TRAN) && !(nd.specfl & (SP_PURE|SP_BADU))) |
247 |
> |
if (nd.specfl & (SP_REFL|SP_TRAN) && !(nd.specfl & SP_BADU)) |
248 |
|
agaussamp(r, &nd); |
249 |
|
|
250 |
|
if (nd.rdiff > FTINY) { /* ambient from this side */ |
269 |
|
} |
270 |
|
/* add direct component */ |
271 |
|
direct(r, diraniso, &nd); |
314 |
– |
/* check distance */ |
315 |
– |
if (transtest > bright(r->rcol)) |
316 |
– |
r->rt = transdist; |
272 |
|
} |
273 |
|
|
274 |
|
|
367 |
|
else |
368 |
|
VCOPY(sr.rdir, np->prdir); /* else no jitter */ |
369 |
|
rayvalue(&sr); |
370 |
< |
multcolor(sr.rcol, np->scolor); |
370 |
> |
scalecolor(sr.rcol, np->tspec); |
371 |
> |
multcolor(sr.rcol, np->mcolor); /* modify by color */ |
372 |
|
addcolor(r->rcol, sr.rcol); |
373 |
|
ndims--; |
374 |
|
} |