1 |
< |
/* Copyright (c) 1995 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1996 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
24 |
|
extern int maxdepth; /* maximum recursion depth */ |
25 |
|
extern double minweight; /* minimum ray weight */ |
26 |
|
extern int do_irrad; /* compute irradiance? */ |
27 |
+ |
extern COLOR ambval; /* ambient value */ |
28 |
|
|
29 |
+ |
extern COLOR cextinction; /* global extinction coefficient */ |
30 |
+ |
extern COLOR salbedo; /* global scattering albedo */ |
31 |
+ |
extern double seccg; /* global scattering eccentricity */ |
32 |
+ |
extern double ssampdist; /* scatter sampling distance */ |
33 |
+ |
|
34 |
|
unsigned long raynum = 0; /* next unique ray number */ |
35 |
|
unsigned long nrays = 0; /* number of calls to localhit */ |
36 |
|
|
61 |
|
r->rsrc = -1; |
62 |
|
r->clipset = NULL; |
63 |
|
r->revf = raytrace; |
64 |
+ |
copycolor(r->cext, cextinction); |
65 |
+ |
copycolor(r->albedo, salbedo); |
66 |
+ |
r->gecc = seccg; |
67 |
+ |
r->slights = NULL; |
68 |
|
} else { /* spawned ray */ |
69 |
|
r->rlvl = ro->rlvl; |
70 |
|
if (rt & RAYREFL) { |
71 |
|
r->rlvl++; |
72 |
|
r->rsrc = -1; |
73 |
|
r->clipset = ro->clipset; |
74 |
+ |
r->rmax = 0.0; |
75 |
|
} else { |
76 |
|
r->rsrc = ro->rsrc; |
77 |
|
r->clipset = ro->newcset; |
78 |
+ |
r->rmax = ro->rmax <= FTINY ? 0.0 : ro->rmax - ro->rot; |
79 |
|
} |
80 |
|
r->revf = ro->revf; |
81 |
+ |
copycolor(r->cext, ro->cext); |
82 |
+ |
copycolor(r->albedo, ro->albedo); |
83 |
+ |
r->gecc = ro->gecc; |
84 |
+ |
r->slights = ro->slights; |
85 |
|
r->rweight = ro->rweight * rw; |
86 |
|
r->crtype = ro->crtype | (r->rtype = rt); |
87 |
|
VCOPY(r->rorg, ro->rop); |
72 |
– |
r->rmax = 0.0; |
88 |
|
} |
89 |
|
rayclear(r); |
90 |
|
return(r->rlvl <= maxdepth && r->rweight >= minweight ? 0 : -1); |
96 |
|
{ |
97 |
|
r->rno = raynum++; |
98 |
|
r->newcset = r->clipset; |
99 |
+ |
r->robj = OVOID; |
100 |
|
r->ro = NULL; |
101 |
|
r->rot = FHUGE; |
102 |
|
r->pert[0] = r->pert[1] = r->pert[2] = 0.0; |
110 |
|
RAY *r; |
111 |
|
{ |
112 |
|
extern int (*trace)(); |
97 |
– |
int gotmat; |
113 |
|
|
114 |
|
if (localhit(r, &thescene)) |
115 |
< |
gotmat = raycont(r); |
115 |
> |
raycont(r); /* hit local surface, evaluate */ |
116 |
|
else if (r->ro == &Aftplane) { |
117 |
< |
r->ro = NULL; |
117 |
> |
r->ro = NULL; /* hit aft clipping plane */ |
118 |
|
r->rot = FHUGE; |
119 |
|
} else if (sourcehit(r)) |
120 |
< |
gotmat = rayshade(r, r->ro->omod); |
120 |
> |
rayshade(r, r->ro->omod); /* distant source */ |
121 |
|
|
122 |
< |
if (r->ro != NULL && !gotmat) |
108 |
< |
objerror(r->ro, USER, "material not found"); |
122 |
> |
rayparticipate(r); /* for participating medium */ |
123 |
|
|
124 |
|
if (trace != NULL) |
125 |
|
(*trace)(r); /* trace execution */ |
130 |
|
register RAY *r; |
131 |
|
{ |
132 |
|
if ((r->clipset != NULL && inset(r->clipset, r->ro->omod)) || |
133 |
< |
r->ro->omod == OVOID) { |
133 |
> |
!rayshade(r, r->ro->omod)) |
134 |
|
raytrans(r); |
121 |
– |
return(1); |
122 |
– |
} |
123 |
– |
return(rayshade(r, r->ro->omod)); |
135 |
|
} |
136 |
|
|
137 |
|
|
142 |
|
|
143 |
|
if (rayorigin(&tr, r, TRANS, 1.0) == 0) { |
144 |
|
VCOPY(tr.rdir, r->rdir); |
134 |
– |
if (r->rmax > FTINY) |
135 |
– |
tr.rmax = r->rmax - r->rot; |
145 |
|
rayvalue(&tr); |
146 |
|
copycolor(r->rcol, tr.rcol); |
147 |
|
r->rt = r->rot + tr.rt; |
186 |
|
} |
187 |
|
|
188 |
|
|
189 |
+ |
rayparticipate(r) /* compute ray medium participation */ |
190 |
+ |
register RAY *r; |
191 |
+ |
{ |
192 |
+ |
COLOR ce, ca; |
193 |
+ |
double re, ge, be; |
194 |
+ |
|
195 |
+ |
if (intens(r->cext) <= 1./FHUGE) |
196 |
+ |
return; /* no medium */ |
197 |
+ |
re = r->rot*colval(r->cext,RED); |
198 |
+ |
ge = r->rot*colval(r->cext,GRN); |
199 |
+ |
be = r->rot*colval(r->cext,BLU); |
200 |
+ |
if (r->crtype & SHADOW) { /* no scattering for sources */ |
201 |
+ |
re *= 1. - colval(r->albedo,RED); |
202 |
+ |
ge *= 1. - colval(r->albedo,GRN); |
203 |
+ |
be *= 1. - colval(r->albedo,BLU); |
204 |
+ |
} |
205 |
+ |
setcolor(ce, re<=0. ? 1. : re>92. ? 0. : exp(-re), |
206 |
+ |
ge<=0. ? 1. : ge>92. ? 0. : exp(-ge), |
207 |
+ |
be<=0. ? 1. : be>92. ? 0. : exp(-be)); |
208 |
+ |
multcolor(r->rcol, ce); /* path absorption */ |
209 |
+ |
if (r->crtype & SHADOW || intens(r->albedo) <= FTINY) |
210 |
+ |
return; /* no scattering */ |
211 |
+ |
setcolor(ca, |
212 |
+ |
colval(r->albedo,RED)*colval(ambval,RED)*(1.-colval(ce,RED)), |
213 |
+ |
colval(r->albedo,GRN)*colval(ambval,GRN)*(1.-colval(ce,GRN)), |
214 |
+ |
colval(r->albedo,BLU)*colval(ambval,BLU)*(1.-colval(ce,BLU))); |
215 |
+ |
addcolor(r->rcol, ca); /* ambient in scattering */ |
216 |
+ |
srcscatter(r); /* source in scattering */ |
217 |
+ |
} |
218 |
+ |
|
219 |
+ |
|
220 |
|
raytexture(r, mod) /* get material modifiers */ |
221 |
|
RAY *r; |
222 |
|
int mod; |
253 |
|
RAY fr, br; |
254 |
|
int foremat, backmat; |
255 |
|
register int i; |
256 |
< |
/* clip coefficient */ |
256 |
> |
/* bound coefficient */ |
257 |
|
if (coef > 1.0) |
258 |
|
coef = 1.0; |
259 |
|
else if (coef < 0.0) |
260 |
|
coef = 0.0; |
261 |
|
/* compute foreground and background */ |
262 |
< |
foremat = backmat = -1; |
262 |
> |
foremat = backmat = 0; |
263 |
|
/* foreground */ |
264 |
|
copystruct(&fr, r); |
265 |
< |
if (fore != OVOID && coef > FTINY) |
265 |
> |
if (coef > FTINY) |
266 |
|
foremat = rayshade(&fr, fore); |
267 |
|
/* background */ |
268 |
|
copystruct(&br, r); |
269 |
< |
if (back != OVOID && coef < 1.0-FTINY) |
269 |
> |
if (coef < 1.0-FTINY) |
270 |
|
backmat = rayshade(&br, back); |
271 |
< |
/* check */ |
272 |
< |
if (foremat < 0) |
273 |
< |
if (backmat < 0) |
274 |
< |
foremat = backmat = 0; |
271 |
> |
/* check for transparency */ |
272 |
> |
if (backmat ^ foremat) |
273 |
> |
if (backmat) |
274 |
> |
raytrans(&fr); |
275 |
|
else |
276 |
< |
foremat = backmat; |
237 |
< |
else if (backmat < 0) |
238 |
< |
backmat = foremat; |
239 |
< |
if ((foremat==0) != (backmat==0)) |
240 |
< |
objerror(r->ro, USER, "mixing material with non-material"); |
276 |
> |
raytrans(&br); |
277 |
|
/* mix perturbations */ |
278 |
|
for (i = 0; i < 3; i++) |
279 |
|
r->pert[i] = coef*fr.pert[i] + (1.0-coef)*br.pert[i]; |
282 |
|
scalecolor(br.pcol, 1.0-coef); |
283 |
|
copycolor(r->pcol, fr.pcol); |
284 |
|
addcolor(r->pcol, br.pcol); |
249 |
– |
/* mix returned ray values */ |
250 |
– |
if (foremat) { |
251 |
– |
scalecolor(fr.rcol, coef); |
252 |
– |
scalecolor(br.rcol, 1.0-coef); |
253 |
– |
copycolor(r->rcol, fr.rcol); |
254 |
– |
addcolor(r->rcol, br.rcol); |
255 |
– |
r->rt = bright(fr.rcol) > bright(br.rcol) ? fr.rt : br.rt; |
256 |
– |
} |
285 |
|
/* return value tells if material */ |
286 |
< |
return(foremat); |
286 |
> |
if (!foremat & !backmat) |
287 |
> |
return(0); |
288 |
> |
/* mix returned ray values */ |
289 |
> |
scalecolor(fr.rcol, coef); |
290 |
> |
scalecolor(br.rcol, 1.0-coef); |
291 |
> |
copycolor(r->rcol, fr.rcol); |
292 |
> |
addcolor(r->rcol, br.rcol); |
293 |
> |
r->rt = bright(fr.rcol) > bright(br.rcol) ? fr.rt : br.rt; |
294 |
> |
return(1); |
295 |
|
} |
296 |
|
|
297 |
|
|
555 |
|
checkset(oset, cxs); /* eliminate double-checking */ |
556 |
|
for (i = oset[0]; i > 0; i--) { |
557 |
|
o = objptr(oset[i]); |
558 |
< |
(*ofun[o->otype].funp)(o, r); |
558 |
> |
if ((*ofun[o->otype].funp)(o, r)) |
559 |
> |
r->robj = oset[i]; |
560 |
|
} |
561 |
|
if (r->ro == NULL) |
562 |
|
return(0); /* no scores yet */ |