--- ray/src/rt/source.c 2004/03/30 16:13:01 2.44 +++ ray/src/rt/source.c 2005/04/14 17:43:43 2.48 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: source.c,v 2.44 2004/03/30 16:13:01 schorsch Exp $"; +static const char RCSid[] = "$Id: source.c,v 2.48 2005/04/14 17:43:43 greg Exp $"; #endif /* * source.c - routines dealing with illumination sources. @@ -46,8 +46,6 @@ extern OBJREC * /* find an object's actual material findmaterial(register OBJREC *o) { while (!ismaterial(o->otype)) { - if (ismixture(o->otype)) - return(NULL); /* reject mixed materials */ if (o->otype == MOD_ALIAS && o->oargs.nsargs) { OBJECT aobj; OBJREC *ao; @@ -62,7 +60,7 @@ findmaterial(register OBJREC *o) return(NULL); o = objptr(o->omod); } - return(o); + return(o); /* mixtures will return NULL */ } @@ -125,7 +123,7 @@ marksources(void) /* find and mark source objects */ } } #if SHADCACHE - source[ns].obscache = NULL; + initobscache(ns); #endif if (!(source[ns].sflags & SSKIP)) foundsource++; @@ -250,11 +248,28 @@ nomat: } +static int +transillum( /* check if material is transparent illum */ + OBJECT obj +) +{ + OBJREC *m = findmaterial(objptr(obj)); + + if (m == NULL) + return(1); + if (m->otype != MAT_ILLUM) + return(0); + return(!m->oargs.nsargs || !strcmp(m->oargs.sarg[0], VOIDID)); +} + + extern int sourcehit( /* check to see if ray hit distant source */ register RAY *r ) { + int glowsrc = -1; + int transrc = -1; int first, last; register int i; @@ -263,30 +278,56 @@ sourcehit( /* check to see if ray hit distant source } else { /* otherwise check all */ first = 0; last = nsources-1; } - for (i = first; i <= last; i++) - if ((source[i].sflags & (SDISTANT|SVIRTUAL)) == SDISTANT) - /* - * Check to see if ray is within - * solid angle of source. - */ - if (2.0*PI * (1.0 - DOT(source[i].sloc,r->rdir)) - <= source[i].ss2) { - r->ro = source[i].so; - if (!(source[i].sflags & SSKIP)) - break; - } - - if (r->ro != NULL) { - r->robj = objndx(r->ro); - for (i = 0; i < 3; i++) - r->ron[i] = -r->rdir[i]; - r->rod = 1.0; - r->pert[0] = r->pert[1] = r->pert[2] = 0.0; - r->uv[0] = r->uv[1] = 0.0; - r->rox = NULL; - return(1); + for (i = first; i <= last; i++) { + if ((source[i].sflags & (SDISTANT|SVIRTUAL)) != SDISTANT) + continue; + /* + * Check to see if ray is within + * solid angle of source. + */ + if (2.*PI*(1. - DOT(source[i].sloc,r->rdir)) > source[i].ss2) + continue; + /* is it the only possibility? */ + if (first == last) { + r->ro = source[i].so; + break; + } + /* + * If it's a glow or transparent illum, just remember it. + */ + if (source[i].sflags & SSKIP) { + glowsrc = i; + continue; + } + if (transillum(source[i].so->omod)) { + transrc = i; + continue; + } + r->ro = source[i].so; /* otherwise, use first hit */ + break; } - return(0); + /* + * Do we need fallback? + */ + if (r->ro == NULL) { + if (transrc >= 0 && r->crtype & (AMBIENT|SPECULAR)) + return(0); /* avoid overcounting */ + if (glowsrc >= 0) + r->ro = source[glowsrc].so; + else + return(0); /* nothing usable */ + } + /* + * Make assignments. + */ + r->robj = objndx(r->ro); + for (i = 0; i < 3; i++) + r->ron[i] = -r->rdir[i]; + r->rod = 1.0; + r->pert[0] = r->pert[1] = r->pert[2] = 0.0; + r->uv[0] = r->uv[1] = 0.0; + r->rox = NULL; + return(1); } @@ -499,13 +540,21 @@ srcscatter( /* compute source scattering into ray */ if (!srcray(&sr, NULL, &si) || sr.rsrc != r->slights[i]) continue; /* no path */ +#if SHADCACHE + if (srcblocked(&sr)) /* check shadow cache */ + continue; +#endif copycolor(sr.cext, r->cext); copycolor(sr.albedo, r->albedo); sr.gecc = r->gecc; sr.slights = r->slights; rayvalue(&sr); /* eval. source ray */ - if (bright(sr.rcol) <= FTINY) + if (bright(sr.rcol) <= FTINY) { +#if SHADCACHE + srcblocker(&sr); /* add blocker to cache */ +#endif continue; + } if (r->gecc <= FTINY) /* compute P(theta) */ d = 1.; else { @@ -545,10 +594,10 @@ srcscatter( /* compute source scattering into ray */ static int weaksrcmat(OBJECT obj) /* identify material */ { - OBJREC *o = findmaterial(objptr(obj)); + OBJREC *m = findmaterial(objptr(obj)); - if (o == NULL) return 0; - return((o->otype==MAT_ILLUM)|(o->otype==MAT_GLOW)); + if (m == NULL) return(0); + return((m->otype==MAT_ILLUM) | (m->otype==MAT_GLOW)); } #define illumblock(m, r) (!(source[r->rsrc].sflags&SVIRTUAL) && \