1 |
< |
/* Copyright (c) 1995 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 |
|
/* |
27 |
|
extern COLOR ambval; /* ambient value */ |
28 |
|
|
29 |
|
extern COLOR cextinction; /* global extinction coefficient */ |
30 |
< |
extern double salbedo; /* global scattering albedo */ |
30 |
> |
extern COLOR salbedo; /* global scattering albedo */ |
31 |
|
extern double seccg; /* global scattering eccentricity */ |
32 |
|
extern double ssampdist; /* scatter sampling distance */ |
33 |
|
|
44 |
|
|
45 |
|
static int raymove(), checkset(), checkhit(); |
46 |
|
|
47 |
< |
#define MAXLOOP 128 /* modifier loop detection */ |
47 |
> |
#ifndef MAXLOOP |
48 |
> |
#define MAXLOOP 0 /* modifier loop detection */ |
49 |
> |
#endif |
50 |
|
|
51 |
|
#define RAYHIT (-1) /* return value for intercepted ray */ |
52 |
|
|
56 |
|
int rt; |
57 |
|
double rw; |
58 |
|
{ |
59 |
+ |
double re; |
60 |
+ |
|
61 |
|
if ((r->parent = ro) == NULL) { /* primary ray */ |
62 |
|
r->rlvl = 0; |
63 |
|
r->rweight = rw; |
66 |
|
r->clipset = NULL; |
67 |
|
r->revf = raytrace; |
68 |
|
copycolor(r->cext, cextinction); |
69 |
< |
r->albedo = salbedo; |
69 |
> |
copycolor(r->albedo, salbedo); |
70 |
|
r->gecc = seccg; |
71 |
|
r->slights = NULL; |
72 |
|
} else { /* spawned ray */ |
83 |
|
} |
84 |
|
r->revf = ro->revf; |
85 |
|
copycolor(r->cext, ro->cext); |
86 |
< |
r->albedo = ro->albedo; |
86 |
> |
copycolor(r->albedo, ro->albedo); |
87 |
|
r->gecc = ro->gecc; |
88 |
|
r->slights = ro->slights; |
85 |
– |
r->rweight = ro->rweight * rw; |
89 |
|
r->crtype = ro->crtype | (r->rtype = rt); |
90 |
|
VCOPY(r->rorg, ro->rop); |
91 |
+ |
r->rweight = ro->rweight * rw; |
92 |
+ |
/* estimate absorption */ |
93 |
+ |
re = colval(ro->cext,RED) < colval(ro->cext,GRN) ? |
94 |
+ |
colval(ro->cext,RED) : colval(ro->cext,GRN); |
95 |
+ |
if (colval(ro->cext,BLU) < re) re = colval(ro->cext,BLU); |
96 |
+ |
if (re > 0.) |
97 |
+ |
r->rweight *= exp(-re*ro->rot); |
98 |
|
} |
99 |
|
rayclear(r); |
100 |
|
return(r->rlvl <= maxdepth && r->rweight >= minweight ? 0 : -1); |
106 |
|
{ |
107 |
|
r->rno = raynum++; |
108 |
|
r->newcset = r->clipset; |
109 |
+ |
r->robj = OVOID; |
110 |
|
r->ro = NULL; |
111 |
< |
r->rot = FHUGE; |
111 |
> |
r->rt = r->rot = FHUGE; |
112 |
|
r->pert[0] = r->pert[1] = r->pert[2] = 0.0; |
113 |
|
setcolor(r->pcol, 1.0, 1.0, 1.0); |
114 |
|
setcolor(r->rcol, 0.0, 0.0, 0.0); |
104 |
– |
r->rt = 0.0; |
115 |
|
} |
116 |
|
|
117 |
|
|
119 |
|
RAY *r; |
120 |
|
{ |
121 |
|
extern int (*trace)(); |
112 |
– |
int gotmat; |
122 |
|
|
123 |
|
if (localhit(r, &thescene)) |
124 |
< |
gotmat = raycont(r); /* hit local surface, evaluate */ |
124 |
> |
raycont(r); /* hit local surface, evaluate */ |
125 |
|
else if (r->ro == &Aftplane) { |
126 |
|
r->ro = NULL; /* hit aft clipping plane */ |
127 |
|
r->rot = FHUGE; |
128 |
|
} else if (sourcehit(r)) |
129 |
< |
gotmat = rayshade(r, r->ro->omod); /* distant source */ |
129 |
> |
rayshade(r, r->ro->omod); /* distant source */ |
130 |
|
|
122 |
– |
if (r->ro != NULL && !gotmat) |
123 |
– |
objerror(r->ro, USER, "material not found"); |
124 |
– |
|
131 |
|
rayparticipate(r); /* for participating medium */ |
132 |
|
|
133 |
|
if (trace != NULL) |
139 |
|
register RAY *r; |
140 |
|
{ |
141 |
|
if ((r->clipset != NULL && inset(r->clipset, r->ro->omod)) || |
142 |
< |
r->ro->omod == OVOID) { |
142 |
> |
!rayshade(r, r->ro->omod)) |
143 |
|
raytrans(r); |
138 |
– |
return(1); |
139 |
– |
} |
140 |
– |
return(rayshade(r, r->ro->omod)); |
144 |
|
} |
145 |
|
|
146 |
|
|
162 |
|
register RAY *r; |
163 |
|
int mod; |
164 |
|
{ |
162 |
– |
static int depth = 0; |
165 |
|
int gotmat; |
166 |
|
register OBJREC *m; |
167 |
+ |
#if MAXLOOP |
168 |
+ |
static int depth = 0; |
169 |
|
/* check for infinite loop */ |
170 |
|
if (depth++ >= MAXLOOP) |
171 |
|
objerror(r->ro, USER, "possible modifier loop"); |
172 |
+ |
#endif |
173 |
|
r->rt = r->rot; /* set effective ray length */ |
174 |
|
for (gotmat = 0; !gotmat && mod != OVOID; mod = m->omod) { |
175 |
|
m = objptr(mod); |
182 |
|
/* hack for irradiance calculation */ |
183 |
|
if (do_irrad && !(r->crtype & ~(PRIMARY|TRANS))) { |
184 |
|
if (irr_ignore(m->otype)) { |
185 |
+ |
#if MAXLOOP |
186 |
|
depth--; |
187 |
+ |
#endif |
188 |
|
raytrans(r); |
189 |
|
return(1); |
190 |
|
} |
194 |
|
/* materials call raytexture */ |
195 |
|
gotmat = (*ofun[m->otype].funp)(m, r); |
196 |
|
} |
197 |
+ |
#if MAXLOOP |
198 |
|
depth--; |
199 |
+ |
#endif |
200 |
|
return(gotmat); |
201 |
|
} |
202 |
|
|
205 |
|
register RAY *r; |
206 |
|
{ |
207 |
|
COLOR ce, ca; |
199 |
– |
double dist; |
208 |
|
double re, ge, be; |
209 |
|
|
210 |
|
if (intens(r->cext) <= 1./FHUGE) |
211 |
|
return; /* no medium */ |
212 |
< |
if ((dist = r->rot) >= FHUGE) |
213 |
< |
dist = 2.*thescene.cusize; /* what to use for infinity? */ |
214 |
< |
if (r->crtype & SHADOW) |
215 |
< |
dist *= 1. - salbedo; /* no scattering for sources */ |
216 |
< |
if (dist <= FTINY) |
217 |
< |
return; /* no effective ray travel */ |
218 |
< |
re = dist*colval(r->cext,RED); |
219 |
< |
ge = dist*colval(r->cext,GRN); |
220 |
< |
be = dist*colval(r->cext,BLU); |
221 |
< |
setcolor(ce, re>92. ? 0. : exp(-re), |
222 |
< |
ge>92. ? 0. : exp(-ge), |
215 |
< |
be>92. ? 0. : exp(-be)); |
212 |
> |
re = r->rot*colval(r->cext,RED); |
213 |
> |
ge = r->rot*colval(r->cext,GRN); |
214 |
> |
be = r->rot*colval(r->cext,BLU); |
215 |
> |
if (r->crtype & SHADOW) { /* no scattering for sources */ |
216 |
> |
re *= 1. - colval(r->albedo,RED); |
217 |
> |
ge *= 1. - colval(r->albedo,GRN); |
218 |
> |
be *= 1. - colval(r->albedo,BLU); |
219 |
> |
} |
220 |
> |
setcolor(ce, re<=0. ? 1. : re>92. ? 0. : exp(-re), |
221 |
> |
ge<=0. ? 1. : ge>92. ? 0. : exp(-ge), |
222 |
> |
be<=0. ? 1. : be>92. ? 0. : exp(-be)); |
223 |
|
multcolor(r->rcol, ce); /* path absorption */ |
224 |
< |
if (r->albedo <= FTINY || r->crtype & SHADOW) |
224 |
> |
if (r->crtype & SHADOW || intens(r->albedo) <= FTINY) |
225 |
|
return; /* no scattering */ |
226 |
< |
setcolor(ca, salbedo*colval(ambval,RED)*(1.-colval(ce,RED)), |
227 |
< |
salbedo*colval(ambval,GRN)*(1.-colval(ce,GRN)), |
228 |
< |
salbedo*colval(ambval,BLU)*(1.-colval(ce,BLU))); |
226 |
> |
setcolor(ca, |
227 |
> |
colval(r->albedo,RED)*colval(ambval,RED)*(1.-colval(ce,RED)), |
228 |
> |
colval(r->albedo,GRN)*colval(ambval,GRN)*(1.-colval(ce,GRN)), |
229 |
> |
colval(r->albedo,BLU)*colval(ambval,BLU)*(1.-colval(ce,BLU))); |
230 |
|
addcolor(r->rcol, ca); /* ambient in scattering */ |
231 |
|
srcscatter(r); /* source in scattering */ |
232 |
|
} |
236 |
|
RAY *r; |
237 |
|
int mod; |
238 |
|
{ |
231 |
– |
static int depth = 0; |
239 |
|
register OBJREC *m; |
240 |
+ |
#if MAXLOOP |
241 |
+ |
static int depth = 0; |
242 |
|
/* check for infinite loop */ |
243 |
|
if (depth++ >= MAXLOOP) |
244 |
|
objerror(r->ro, USER, "modifier loop"); |
245 |
+ |
#endif |
246 |
|
/* execute textures and patterns */ |
247 |
|
for ( ; mod != OVOID; mod = m->omod) { |
248 |
|
m = objptr(mod); |
258 |
|
objerror(r->ro, USER, errmsg); |
259 |
|
} |
260 |
|
} |
261 |
+ |
#if MAXLOOP |
262 |
|
depth--; /* end here */ |
263 |
+ |
#endif |
264 |
|
} |
265 |
|
|
266 |
|
|
272 |
|
RAY fr, br; |
273 |
|
int foremat, backmat; |
274 |
|
register int i; |
275 |
< |
/* clip coefficient */ |
275 |
> |
/* bound coefficient */ |
276 |
|
if (coef > 1.0) |
277 |
|
coef = 1.0; |
278 |
|
else if (coef < 0.0) |
279 |
|
coef = 0.0; |
280 |
|
/* compute foreground and background */ |
281 |
< |
foremat = backmat = -1; |
281 |
> |
foremat = backmat = 0; |
282 |
|
/* foreground */ |
283 |
|
copystruct(&fr, r); |
284 |
< |
if (fore != OVOID && coef > FTINY) |
284 |
> |
if (coef > FTINY) |
285 |
|
foremat = rayshade(&fr, fore); |
286 |
|
/* background */ |
287 |
|
copystruct(&br, r); |
288 |
< |
if (back != OVOID && coef < 1.0-FTINY) |
288 |
> |
if (coef < 1.0-FTINY) |
289 |
|
backmat = rayshade(&br, back); |
290 |
< |
/* check */ |
291 |
< |
if (foremat < 0) |
292 |
< |
if (backmat < 0) |
293 |
< |
foremat = backmat = 0; |
294 |
< |
else |
295 |
< |
foremat = backmat; |
284 |
< |
else if (backmat < 0) |
285 |
< |
backmat = foremat; |
286 |
< |
if ((foremat==0) != (backmat==0)) |
287 |
< |
objerror(r->ro, USER, "mixing material with non-material"); |
290 |
> |
/* check for transparency */ |
291 |
> |
if (backmat ^ foremat) |
292 |
> |
if (backmat && coef > FTINY) |
293 |
> |
raytrans(&fr); |
294 |
> |
else if (foremat && coef < 1.0-FTINY) |
295 |
> |
raytrans(&br); |
296 |
|
/* mix perturbations */ |
297 |
|
for (i = 0; i < 3; i++) |
298 |
|
r->pert[i] = coef*fr.pert[i] + (1.0-coef)*br.pert[i]; |
301 |
|
scalecolor(br.pcol, 1.0-coef); |
302 |
|
copycolor(r->pcol, fr.pcol); |
303 |
|
addcolor(r->pcol, br.pcol); |
296 |
– |
/* mix returned ray values */ |
297 |
– |
if (foremat) { |
298 |
– |
scalecolor(fr.rcol, coef); |
299 |
– |
scalecolor(br.rcol, 1.0-coef); |
300 |
– |
copycolor(r->rcol, fr.rcol); |
301 |
– |
addcolor(r->rcol, br.rcol); |
302 |
– |
r->rt = bright(fr.rcol) > bright(br.rcol) ? fr.rt : br.rt; |
303 |
– |
} |
304 |
|
/* return value tells if material */ |
305 |
< |
return(foremat); |
305 |
> |
if (!foremat & !backmat) |
306 |
> |
return(0); |
307 |
> |
/* mix returned ray values */ |
308 |
> |
scalecolor(fr.rcol, coef); |
309 |
> |
scalecolor(br.rcol, 1.0-coef); |
310 |
> |
copycolor(r->rcol, fr.rcol); |
311 |
> |
addcolor(r->rcol, br.rcol); |
312 |
> |
r->rt = bright(fr.rcol) > bright(br.rcol) ? fr.rt : br.rt; |
313 |
> |
return(1); |
314 |
|
} |
315 |
|
|
316 |
|
|
574 |
|
checkset(oset, cxs); /* eliminate double-checking */ |
575 |
|
for (i = oset[0]; i > 0; i--) { |
576 |
|
o = objptr(oset[i]); |
577 |
< |
(*ofun[o->otype].funp)(o, r); |
577 |
> |
if ((*ofun[o->otype].funp)(o, r)) |
578 |
> |
r->robj = oset[i]; |
579 |
|
} |
580 |
|
if (r->ro == NULL) |
581 |
|
return(0); /* no scores yet */ |