--- ray/src/rt/srcobstr.c 2004/09/08 06:07:52 2.7 +++ 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.7 2004/09/08 06:07:52 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.7 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 */ @@ -50,7 +53,7 @@ castshadow(int sn, FVECT rorg, FVECT rdir) } -static void /* initialize occlusion cache */ +void /* initialize occlusion cache */ initobscache(int sn) { register SRCREC *srcp = &source[sn]; @@ -60,6 +63,8 @@ initobscache(int sn) int i, j, k; int ax, ax1, ax2; + if (srcp->sflags & (SSKIP|SPROX|SSPOT|SVIRTUAL)) + return; /* don't cache these */ if (srcp->sflags & SDISTANT) cachelen = 4*SHADCACHE*SHADCACHE; else if (srcp->sflags & SFLAT) @@ -67,8 +72,6 @@ initobscache(int sn) else /* spherical distribution */ cachelen = SHADCACHE*SHADCACHE*6; /* allocate cache */ - DCHECK(srcp->obscache != NULL, - CONSISTENCY, "initobscache() called twice"); srcp->obscache = (OBSCACHE *)malloc(sizeof(OBSCACHE) + sizeof(OBJECT)*(cachelen-1)); if (srcp->obscache == NULL) @@ -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; }