1 |
< |
/* Copyright (c) 1992 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1995 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
23 |
|
extern double specthresh; /* specular sampling threshold */ |
24 |
|
extern double specjitter; /* specular sampling jitter */ |
25 |
|
|
26 |
+ |
extern int backvis; /* back faces visible? */ |
27 |
+ |
|
28 |
|
static gaussamp(); |
29 |
|
|
30 |
|
/* |
156 |
|
{ |
157 |
|
NORMDAT nd; |
158 |
|
double transtest, transdist; |
159 |
+ |
double mirtest, mirdist; |
160 |
+ |
int hastexture; |
161 |
+ |
double d; |
162 |
|
COLOR ctmp; |
163 |
|
register int i; |
164 |
|
/* easy shadow test */ |
165 |
|
if (r->crtype & SHADOW && m->otype != MAT_TRANS) |
166 |
< |
return; |
166 |
> |
return(1); |
167 |
|
|
168 |
|
if (m->oargs.nfargs != (m->otype == MAT_TRANS ? 7 : 5)) |
169 |
|
objerror(m, USER, "bad number of arguments"); |
170 |
+ |
/* check for back side */ |
171 |
+ |
if (r->rod < 0.0) { |
172 |
+ |
if (!backvis && m->otype != MAT_TRANS) { |
173 |
+ |
raytrans(r); |
174 |
+ |
return(1); |
175 |
+ |
} |
176 |
+ |
flipsurface(r); /* reorient if backvis */ |
177 |
+ |
} |
178 |
|
nd.mp = m; |
179 |
|
nd.rp = r; |
180 |
|
/* get material color */ |
186 |
|
nd.alpha2 = m->oargs.farg[4]; |
187 |
|
if ((nd.alpha2 *= nd.alpha2) <= FTINY) |
188 |
|
nd.specfl |= SP_PURE; |
189 |
< |
/* reorient if necessary */ |
190 |
< |
if (r->rod < 0.0) |
178 |
< |
flipsurface(r); |
189 |
> |
if (r->ro != NULL && isflat(r->ro->otype)) |
190 |
> |
nd.specfl |= SP_FLAT; |
191 |
|
/* get modifiers */ |
192 |
|
raytexture(r, m->omod); |
193 |
< |
nd.pdot = raynormal(nd.pnorm, r); /* perturb normal */ |
193 |
> |
if (hastexture = DOT(r->pert,r->pert) > FTINY*FTINY) |
194 |
> |
nd.pdot = raynormal(nd.pnorm, r); /* perturb normal */ |
195 |
> |
else { |
196 |
> |
VCOPY(nd.pnorm, r->ron); |
197 |
> |
nd.pdot = r->rod; |
198 |
> |
} |
199 |
|
if (nd.pdot < .001) |
200 |
|
nd.pdot = .001; /* non-zero for dirnorm() */ |
201 |
|
multcolor(nd.mcolor, r->pcol); /* modify material color */ |
202 |
< |
transtest = 0; |
203 |
< |
transdist = r->rot; |
204 |
< |
/* get specular component */ |
188 |
< |
if ((nd.rspec = m->oargs.farg[3]) > FTINY) { |
189 |
< |
nd.specfl |= SP_REFL; |
190 |
< |
/* compute specular color */ |
191 |
< |
if (m->otype == MAT_METAL) |
192 |
< |
copycolor(nd.scolor, nd.mcolor); |
193 |
< |
else |
194 |
< |
setcolor(nd.scolor, 1.0, 1.0, 1.0); |
195 |
< |
scalecolor(nd.scolor, nd.rspec); |
196 |
< |
/* check threshold */ |
197 |
< |
if (!(nd.specfl & SP_PURE) && specthresh >= nd.rspec-FTINY) |
198 |
< |
nd.specfl |= SP_RBLT; |
199 |
< |
/* compute reflected ray */ |
200 |
< |
for (i = 0; i < 3; i++) |
201 |
< |
nd.vrefl[i] = r->rdir[i] + 2.0*nd.pdot*nd.pnorm[i]; |
202 |
< |
if (DOT(nd.vrefl, r->ron) <= FTINY) /* penetration? */ |
203 |
< |
for (i = 0; i < 3; i++) /* safety measure */ |
204 |
< |
nd.vrefl[i] = r->rdir[i] + 2.*r->rod*r->ron[i]; |
205 |
< |
|
206 |
< |
if (!(r->crtype & SHADOW) && nd.specfl & SP_PURE) { |
207 |
< |
RAY lr; |
208 |
< |
if (rayorigin(&lr, r, REFLECTED, nd.rspec) == 0) { |
209 |
< |
VCOPY(lr.rdir, nd.vrefl); |
210 |
< |
rayvalue(&lr); |
211 |
< |
multcolor(lr.rcol, nd.scolor); |
212 |
< |
addcolor(r->rcol, lr.rcol); |
213 |
< |
} |
214 |
< |
} |
215 |
< |
} |
202 |
> |
mirtest = transtest = 0; |
203 |
> |
mirdist = transdist = r->rot; |
204 |
> |
nd.rspec = m->oargs.farg[3]; |
205 |
|
/* compute transmission */ |
206 |
|
if (m->otype == MAT_TRANS) { |
207 |
|
nd.trans = m->oargs.farg[5]*(1.0 - nd.rspec); |
213 |
|
if (!(nd.specfl & SP_PURE) && |
214 |
|
specthresh >= nd.tspec-FTINY) |
215 |
|
nd.specfl |= SP_TBLT; |
216 |
< |
if (r->crtype & SHADOW || |
228 |
< |
DOT(r->pert,r->pert) <= FTINY*FTINY) { |
216 |
> |
if (!hastexture || r->crtype & SHADOW) { |
217 |
|
VCOPY(nd.prdir, r->rdir); |
218 |
|
transtest = 2; |
219 |
|
} else { |
242 |
|
} else |
243 |
|
transtest = 0; |
244 |
|
|
245 |
< |
if (r->crtype & SHADOW) /* the rest is shadow */ |
246 |
< |
return; |
245 |
> |
if (r->crtype & SHADOW) { /* the rest is shadow */ |
246 |
> |
r->rt = transdist; |
247 |
> |
return(1); |
248 |
> |
} |
249 |
> |
/* get specular reflection */ |
250 |
> |
if (nd.rspec > FTINY) { |
251 |
> |
nd.specfl |= SP_REFL; |
252 |
> |
/* compute specular color */ |
253 |
> |
if (m->otype == MAT_METAL) |
254 |
> |
copycolor(nd.scolor, nd.mcolor); |
255 |
> |
else |
256 |
> |
setcolor(nd.scolor, 1.0, 1.0, 1.0); |
257 |
> |
scalecolor(nd.scolor, nd.rspec); |
258 |
> |
/* check threshold */ |
259 |
> |
if (!(nd.specfl & SP_PURE) && specthresh >= nd.rspec-FTINY) |
260 |
> |
nd.specfl |= SP_RBLT; |
261 |
> |
/* compute reflected ray */ |
262 |
> |
for (i = 0; i < 3; i++) |
263 |
> |
nd.vrefl[i] = r->rdir[i] + 2.*nd.pdot*nd.pnorm[i]; |
264 |
> |
/* penetration? */ |
265 |
> |
if (hastexture && DOT(nd.vrefl, r->ron) <= FTINY) |
266 |
> |
for (i = 0; i < 3; i++) /* safety measure */ |
267 |
> |
nd.vrefl[i] = r->rdir[i] + 2.*r->rod*r->ron[i]; |
268 |
> |
|
269 |
> |
if (!(r->crtype & SHADOW) && nd.specfl & SP_PURE) { |
270 |
> |
RAY lr; |
271 |
> |
if (rayorigin(&lr, r, REFLECTED, nd.rspec) == 0) { |
272 |
> |
VCOPY(lr.rdir, nd.vrefl); |
273 |
> |
rayvalue(&lr); |
274 |
> |
multcolor(lr.rcol, nd.scolor); |
275 |
> |
addcolor(r->rcol, lr.rcol); |
276 |
> |
if (!hastexture && nd.specfl & SP_FLAT) { |
277 |
> |
mirtest = 2.*bright(lr.rcol); |
278 |
> |
mirdist = r->rot + lr.rt; |
279 |
> |
} |
280 |
> |
} |
281 |
> |
} |
282 |
> |
} |
283 |
|
/* diffuse reflection */ |
284 |
|
nd.rdiff = 1.0 - nd.trans - nd.rspec; |
285 |
|
|
286 |
|
if (nd.specfl & SP_PURE && nd.rdiff <= FTINY && nd.tdiff <= FTINY) |
287 |
< |
return; /* 100% pure specular */ |
287 |
> |
return(1); /* 100% pure specular */ |
288 |
|
|
265 |
– |
if (r->ro != NULL && (r->ro->otype == OBJ_FACE || |
266 |
– |
r->ro->otype == OBJ_RING)) |
267 |
– |
nd.specfl |= SP_FLAT; |
268 |
– |
|
289 |
|
if (nd.specfl & (SP_REFL|SP_TRAN) && !(nd.specfl & SP_PURE)) |
290 |
|
gaussamp(r, &nd); |
291 |
|
|
312 |
|
/* add direct component */ |
313 |
|
direct(r, dirnorm, &nd); |
314 |
|
/* check distance */ |
315 |
< |
if (transtest > bright(r->rcol)) |
315 |
> |
d = bright(r->rcol); |
316 |
> |
if (transtest > d) |
317 |
|
r->rt = transdist; |
318 |
+ |
else if (mirtest > d) |
319 |
+ |
r->rt = mirdist; |
320 |
+ |
|
321 |
+ |
return(1); |
322 |
|
} |
323 |
|
|
324 |
|
|