1 |
< |
/* Copyright (c) 1991 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1994 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
91 |
|
RAY *r; |
92 |
|
{ |
93 |
|
extern int (*trace)(); |
94 |
+ |
int gotmat; |
95 |
|
|
96 |
|
if (localhit(r, &thescene)) |
97 |
< |
raycont(r); |
97 |
> |
gotmat = raycont(r); |
98 |
|
else if (sourcehit(r)) |
99 |
< |
rayshade(r, r->ro->omod); |
99 |
> |
gotmat = rayshade(r, r->ro->omod); |
100 |
|
|
101 |
+ |
if (!gotmat) |
102 |
+ |
objerror(r->ro, USER, "material not found"); |
103 |
+ |
|
104 |
|
if (trace != NULL) |
105 |
|
(*trace)(r); /* trace execution */ |
106 |
|
} |
109 |
|
raycont(r) /* check for clipped object and continue */ |
110 |
|
register RAY *r; |
111 |
|
{ |
112 |
< |
if (r->clipset != NULL && inset(r->clipset, r->ro->omod)) |
112 |
> |
if ((r->clipset != NULL && inset(r->clipset, r->ro->omod)) || |
113 |
> |
r->ro->omod == OVOID) { |
114 |
|
raytrans(r); |
115 |
< |
else |
116 |
< |
rayshade(r, r->ro->omod); |
115 |
> |
return(1); |
116 |
> |
} |
117 |
> |
return(rayshade(r, r->ro->omod)); |
118 |
|
} |
119 |
|
|
120 |
|
|
137 |
|
int mod; |
138 |
|
{ |
139 |
|
static int depth = 0; |
140 |
+ |
int gotmat; |
141 |
|
register OBJREC *m; |
142 |
|
/* check for infinite loop */ |
143 |
|
if (depth++ >= MAXLOOP) |
144 |
|
objerror(r->ro, USER, "possible modifier loop"); |
145 |
|
r->rt = r->rot; /* set effective ray length */ |
146 |
< |
for ( ; mod != OVOID; mod = m->omod) { |
146 |
> |
for (gotmat = 0; !gotmat && mod != OVOID; mod = m->omod) { |
147 |
|
m = objptr(mod); |
148 |
|
/****** unnecessary test since modifier() is always called |
149 |
|
if (!ismodifier(m->otype)) { |
161 |
|
if (!islight(m->otype)) |
162 |
|
m = &Lamb; |
163 |
|
} |
164 |
< |
(*ofun[m->otype].funp)(m, r); /* execute function */ |
165 |
< |
if (ismaterial(m->otype)) { /* materials call raytexture */ |
159 |
< |
depth--; |
160 |
< |
return; /* we're done */ |
161 |
< |
} |
164 |
> |
/* materials call raytexture */ |
165 |
> |
gotmat = (*ofun[m->otype].funp)(m, r); |
166 |
|
} |
167 |
< |
objerror(r->ro, USER, "material not found"); |
167 |
> |
depth--; |
168 |
> |
return(gotmat); |
169 |
|
} |
170 |
|
|
171 |
|
|
181 |
|
/* execute textures and patterns */ |
182 |
|
for ( ; mod != OVOID; mod = m->omod) { |
183 |
|
m = objptr(mod); |
184 |
< |
if (!istexture(m->otype)) { |
184 |
> |
/****** unnecessary test since modifier() is always called |
185 |
> |
if (!ismodifier(m->otype)) { |
186 |
|
sprintf(errmsg, "illegal modifier \"%s\"", m->oname); |
187 |
|
error(USER, errmsg); |
188 |
|
} |
189 |
< |
(*ofun[m->otype].funp)(m, r); |
189 |
> |
******/ |
190 |
> |
if ((*ofun[m->otype].funp)(m, r)) |
191 |
> |
objerror(USER, r->ro, "conflicting materials"); |
192 |
|
} |
193 |
|
depth--; /* end here */ |
194 |
|
} |
199 |
|
OBJECT fore, back; |
200 |
|
double coef; |
201 |
|
{ |
202 |
< |
FVECT curpert, forepert, backpert; |
203 |
< |
COLOR curpcol, forepcol, backpcol; |
202 |
> |
RAY fr, br; |
203 |
> |
COLOR ctmp; |
204 |
> |
int foremat, backmat; |
205 |
|
register int i; |
206 |
|
/* clip coefficient */ |
207 |
|
if (coef > 1.0) |
208 |
|
coef = 1.0; |
209 |
|
else if (coef < 0.0) |
210 |
|
coef = 0.0; |
211 |
< |
/* save current mods */ |
212 |
< |
VCOPY(curpert, r->pert); |
213 |
< |
copycolor(curpcol, r->pcol); |
214 |
< |
/* compute new mods */ |
215 |
< |
/* foreground */ |
207 |
< |
r->pert[0] = r->pert[1] = r->pert[2] = 0.0; |
208 |
< |
setcolor(r->pcol, 1.0, 1.0, 1.0); |
211 |
> |
/* foreground */ |
212 |
> |
copystruct(&fr, r); |
213 |
> |
fr.pert[0] = fr.pert[1] = fr.pert[2] = 0.0; |
214 |
> |
setcolor(fr.pcol, 1.0, 1.0, 1.0); |
215 |
> |
setcolor(fr.rcol, 0.0, 0.0, 0.0); |
216 |
|
if (fore != OVOID && coef > FTINY) |
217 |
< |
raytexture(r, fore); |
218 |
< |
VCOPY(forepert, r->pert); |
219 |
< |
copycolor(forepcol, r->pcol); |
220 |
< |
/* background */ |
221 |
< |
r->pert[0] = r->pert[1] = r->pert[2] = 0.0; |
222 |
< |
setcolor(r->pcol, 1.0, 1.0, 1.0); |
217 |
> |
foremat = rayshade(&fr, fore); |
218 |
> |
else |
219 |
> |
foremat = 0; |
220 |
> |
/* background */ |
221 |
> |
copystruct(&br, r); |
222 |
> |
br.pert[0] = br.pert[1] = br.pert[2] = 0.0; |
223 |
> |
setcolor(br.pcol, 1.0, 1.0, 1.0); |
224 |
> |
setcolor(br.rcol, 0.0, 0.0, 0.0); |
225 |
|
if (back != OVOID && coef < 1.0-FTINY) |
226 |
< |
raytexture(r, back); |
227 |
< |
VCOPY(backpert, r->pert); |
228 |
< |
copycolor(backpcol, r->pcol); |
226 |
> |
backmat = rayshade(&br, back); |
227 |
> |
else |
228 |
> |
backmat = foremat; |
229 |
> |
/* check */ |
230 |
> |
if (backmat != foremat) |
231 |
> |
objerror(USER, r->ro, "mixing material with non-material"); |
232 |
|
/* sum perturbations */ |
233 |
|
for (i = 0; i < 3; i++) |
234 |
< |
r->pert[i] = curpert[i] + coef*forepert[i] + |
235 |
< |
(1.0-coef)*backpert[i]; |
236 |
< |
/* multiply colors */ |
237 |
< |
setcolor(r->pcol, coef*colval(forepcol,RED) + |
238 |
< |
(1.0-coef)*colval(backpcol,RED), |
239 |
< |
coef*colval(forepcol,GRN) + |
240 |
< |
(1.0-coef)*colval(backpcol,GRN), |
241 |
< |
coef*colval(forepcol,BLU) + |
242 |
< |
(1.0-coef)*colval(backpcol,BLU)); |
243 |
< |
multcolor(r->pcol, curpcol); |
234 |
> |
r->pert[i] += coef*fr.pert[i] + (1.0-coef)*br.pert[i]; |
235 |
> |
/* multiply pattern colors */ |
236 |
> |
scalecolor(fr.pcol, coef); |
237 |
> |
scalecolor(br.pcol, 1.0-coef); |
238 |
> |
copycolor(ctmp, fr.pcol); |
239 |
> |
addcolor(ctmp, br.pcol); |
240 |
> |
multcolor(r->pcol, ctmp); |
241 |
> |
/* sum returned ray values */ |
242 |
> |
scalecolor(fr.rcol, coef); |
243 |
> |
scalecolor(br.rcol, 1.0-coef); |
244 |
> |
addcolor(r->rcol, fr.rcol); |
245 |
> |
addcolor(r->rcol, br.rcol); |
246 |
> |
/* return value tells if material */ |
247 |
> |
return(foremat); |
248 |
|
} |
249 |
|
|
250 |
|
|
346 |
|
sflags = 0; |
347 |
|
for (i = 0; i < 3; i++) { |
348 |
|
curpos[i] = r->rorg[i]; |
349 |
< |
if (r->rdir[i] > FTINY) |
349 |
> |
if (r->rdir[i] > 1e-7) |
350 |
|
sflags |= 1 << i; |
351 |
< |
else if (r->rdir[i] < -FTINY) |
351 |
> |
else if (r->rdir[i] < -1e-7) |
352 |
|
sflags |= 0x10 << i; |
353 |
|
} |
354 |
|
if (sflags == 0) |
479 |
|
checkset(oset, cxs); /* eliminate double-checking */ |
480 |
|
for (i = oset[0]; i > 0; i--) { |
481 |
|
o = objptr(oset[i]); |
466 |
– |
if (o->omod == OVOID && issurface(o->otype)) |
467 |
– |
continue; /* ignore void surfaces */ |
482 |
|
(*ofun[o->otype].funp)(o, r); |
483 |
|
} |
484 |
|
if (r->ro == NULL) |