125 |
|
} |
126 |
|
} |
127 |
|
#if SHADCACHE |
128 |
< |
source[ns].obscache = NULL; |
128 |
> |
initobscache(ns); |
129 |
|
#endif |
130 |
|
if (!(source[ns].sflags & SSKIP)) |
131 |
|
foundsource++; |
250 |
|
} |
251 |
|
|
252 |
|
|
253 |
+ |
static int |
254 |
+ |
transillum( /* check if material is transparent illum */ |
255 |
+ |
OBJECT obj |
256 |
+ |
) |
257 |
+ |
{ |
258 |
+ |
OBJREC *m = findmaterial(objptr(obj)); |
259 |
+ |
|
260 |
+ |
if (m == NULL) |
261 |
+ |
return(1); |
262 |
+ |
if (m->otype != MAT_ILLUM) |
263 |
+ |
return(0); |
264 |
+ |
return(!m->oargs.nsargs || !strcmp(m->oargs.sarg[0], VOIDID)); |
265 |
+ |
} |
266 |
+ |
|
267 |
+ |
|
268 |
|
extern int |
269 |
|
sourcehit( /* check to see if ray hit distant source */ |
270 |
|
register RAY *r |
271 |
|
) |
272 |
|
{ |
273 |
+ |
int glowsrc = -1; |
274 |
+ |
int transrc = -1; |
275 |
|
int first, last; |
276 |
|
register int i; |
277 |
|
|
280 |
|
} else { /* otherwise check all */ |
281 |
|
first = 0; last = nsources-1; |
282 |
|
} |
283 |
< |
for (i = first; i <= last; i++) |
284 |
< |
if ((source[i].sflags & (SDISTANT|SVIRTUAL)) == SDISTANT) |
285 |
< |
/* |
286 |
< |
* Check to see if ray is within |
287 |
< |
* solid angle of source. |
288 |
< |
*/ |
289 |
< |
if (2.0*PI * (1.0 - DOT(source[i].sloc,r->rdir)) |
290 |
< |
<= source[i].ss2) { |
291 |
< |
r->ro = source[i].so; |
292 |
< |
if (!(source[i].sflags & SSKIP)) |
293 |
< |
break; |
294 |
< |
} |
295 |
< |
|
296 |
< |
if (r->ro != NULL) { |
297 |
< |
r->robj = objndx(r->ro); |
298 |
< |
for (i = 0; i < 3; i++) |
299 |
< |
r->ron[i] = -r->rdir[i]; |
300 |
< |
r->rod = 1.0; |
301 |
< |
r->pert[0] = r->pert[1] = r->pert[2] = 0.0; |
302 |
< |
r->uv[0] = r->uv[1] = 0.0; |
303 |
< |
r->rox = NULL; |
304 |
< |
return(1); |
283 |
> |
for (i = first; i <= last; i++) { |
284 |
> |
if ((source[i].sflags & (SDISTANT|SVIRTUAL)) != SDISTANT) |
285 |
> |
continue; |
286 |
> |
/* |
287 |
> |
* Check to see if ray is within |
288 |
> |
* solid angle of source. |
289 |
> |
*/ |
290 |
> |
if (2.*PI*(1. - DOT(source[i].sloc,r->rdir)) > source[i].ss2) |
291 |
> |
continue; |
292 |
> |
/* is it the only possibility? */ |
293 |
> |
if (first == last) { |
294 |
> |
r->ro = source[i].so; |
295 |
> |
break; |
296 |
> |
} |
297 |
> |
/* |
298 |
> |
* If it's a glow or transparent illum, just remember it. |
299 |
> |
*/ |
300 |
> |
if (source[i].sflags & SSKIP) { |
301 |
> |
glowsrc = i; |
302 |
> |
continue; |
303 |
> |
} |
304 |
> |
if (transillum(source[i].so->omod)) { |
305 |
> |
transrc = i; |
306 |
> |
continue; |
307 |
> |
} |
308 |
> |
r->ro = source[i].so; /* otherwise, use first hit */ |
309 |
> |
break; |
310 |
|
} |
311 |
< |
return(0); |
311 |
> |
/* |
312 |
> |
* Do we need fallback? |
313 |
> |
*/ |
314 |
> |
if (r->ro == NULL) { |
315 |
> |
if (transrc >= 0 && r->crtype & (AMBIENT|SPECULAR)) |
316 |
> |
return(0); /* avoid overcounting */ |
317 |
> |
if (glowsrc >= 0) |
318 |
> |
r->ro = source[glowsrc].so; |
319 |
> |
else |
320 |
> |
return(0); /* nothing usable */ |
321 |
> |
} |
322 |
> |
/* |
323 |
> |
* Make assignments. |
324 |
> |
*/ |
325 |
> |
r->robj = objndx(r->ro); |
326 |
> |
for (i = 0; i < 3; i++) |
327 |
> |
r->ron[i] = -r->rdir[i]; |
328 |
> |
r->rod = 1.0; |
329 |
> |
r->pert[0] = r->pert[1] = r->pert[2] = 0.0; |
330 |
> |
r->uv[0] = r->uv[1] = 0.0; |
331 |
> |
r->rox = NULL; |
332 |
> |
return(1); |
333 |
|
} |
334 |
|
|
335 |
|
|
542 |
|
if (!srcray(&sr, NULL, &si) || |
543 |
|
sr.rsrc != r->slights[i]) |
544 |
|
continue; /* no path */ |
545 |
+ |
#if SHADCACHE |
546 |
+ |
if (srcblocked(&sr)) /* check shadow cache */ |
547 |
+ |
continue; |
548 |
+ |
#endif |
549 |
|
copycolor(sr.cext, r->cext); |
550 |
|
copycolor(sr.albedo, r->albedo); |
551 |
|
sr.gecc = r->gecc; |
552 |
|
sr.slights = r->slights; |
553 |
|
rayvalue(&sr); /* eval. source ray */ |
554 |
< |
if (bright(sr.rcol) <= FTINY) |
554 |
> |
if (bright(sr.rcol) <= FTINY) { |
555 |
> |
#if SHADCACHE |
556 |
> |
srcblocker(&sr); /* add blocker to cache */ |
557 |
> |
#endif |
558 |
|
continue; |
559 |
+ |
} |
560 |
|
if (r->gecc <= FTINY) /* compute P(theta) */ |
561 |
|
d = 1.; |
562 |
|
else { |
596 |
|
static int |
597 |
|
weaksrcmat(OBJECT obj) /* identify material */ |
598 |
|
{ |
599 |
< |
OBJREC *o = findmaterial(objptr(obj)); |
599 |
> |
OBJREC *m = findmaterial(objptr(obj)); |
600 |
|
|
601 |
< |
if (o == NULL) return 0; |
602 |
< |
return((o->otype==MAT_ILLUM)|(o->otype==MAT_GLOW)); |
601 |
> |
if (m == NULL) return(0); |
602 |
> |
return((m->otype==MAT_ILLUM) | (m->otype==MAT_GLOW)); |
603 |
|
} |
604 |
|
|
605 |
|
#define illumblock(m, r) (!(source[r->rsrc].sflags&SVIRTUAL) && \ |