--- ray/src/rt/srcobstr.c 2004/09/08 17:10:16 2.8 +++ ray/src/rt/srcobstr.c 2007/07/25 04:12:36 2.13 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: srcobstr.c,v 2.8 2004/09/08 17:10:16 greg Exp $"; +static const char RCSid[] = "$Id: srcobstr.c,v 2.13 2007/07/25 04:12:36 greg Exp $"; #endif /* * Source occlusion caching routines @@ -19,6 +19,9 @@ static const char RCSid[] = "$Id: srcobstr.c,v 2.8 200 #if SHADCACHE /* preemptive shadow checking */ +OBJECT * antimodlist = NULL; /* set of clipped materials */ + + static int /* cast source ray to first blocker */ castshadow(int sn, FVECT rorg, FVECT rdir) { @@ -27,7 +30,7 @@ castshadow(int sn, FVECT rorg, FVECT rdir) VCOPY(rt.rorg, rorg); VCOPY(rt.rdir, rdir); rt.rmax = 0; - rayorigin(&rt, NULL, PRIMARY, 1.0); + rayorigin(&rt, PRIMARY, NULL, NULL); /* check for intersection */ while (localhit(&rt, &thescene)) { RAY rt1 = rt; /* pretend we were aimed at source */ @@ -290,6 +293,10 @@ srcblocker(register RAY *r) if (r->robj == OVOID || objptr(r->robj) != r->ro || isvolume(r->ro->otype)) return(0); /* don't record complex blockers */ + if (r->rsrc < 0 || source[r->rsrc].so == r->ro) + return(0); /* just a mistake, that's all */ + if (antimodlist != NULL && inset(antimodlist, r->ro->omod)) + return(0); /* could be clipped */ m = findmaterial(r->ro); if (m == NULL) return(0); /* no material?! */ @@ -308,8 +315,49 @@ srcblocked(RAY *r) if (obs == OVOID) return(0); - op = objptr(obs); /* check for intersection */ - return((*ofun[op->otype].funp)(op, r)); + op = objptr(obs); /* check blocker intersection */ + if (!(*ofun[op->otype].funp)(op, r)) + return(0); + if (source[r->rsrc].sflags & SDISTANT) + return(1); + op = source[r->rsrc].so; /* check source intersection */ + if (!(*ofun[op->otype].funp)(op, r)) + return(1); + rayclear(r); + return(0); /* source in front */ +} + + +void /* record potentially clipped materials */ +markclip(OBJREC *m) +{ + OBJECT *set2add, *oldset; + + m_clip(m, NULL); /* initialize modifier list */ + if ((set2add = (OBJECT *)m->os) == NULL || !set2add[0]) + return; + + if (antimodlist == NULL) { /* start of list */ + antimodlist = setsave(set2add); + return; + } + /* else add to previous list */ + oldset = antimodlist; + antimodlist = (OBJECT *)malloc((oldset[0]+set2add[0]+1)*sizeof(OBJECT)); + if (antimodlist == NULL) + error(SYSTEM, "out of memory in markclip"); + setunion(antimodlist, oldset, set2add); + free((void *)oldset); +} + + +#else /* SHADCACHE */ + + +void /* no-op also avoids linker warning */ +markclip(OBJREC *m) +{ + (void)m; }