--- ray/src/rt/source.c 2007/07/25 04:12:36 2.56 +++ ray/src/rt/source.c 2011/08/02 22:47:30 2.61 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: source.c,v 2.56 2007/07/25 04:12:36 greg Exp $"; +static const char RCSid[] = "$Id: source.c,v 2.61 2011/08/02 22:47:30 greg Exp $"; #endif /* * source.c - routines dealing with illumination sources. @@ -99,14 +99,15 @@ marksources(void) /* find and mark source objects */ m->otype == MAT_SPOT ? 7 : 3)) objerror(m, USER, "bad # arguments"); - if (m->otype == MAT_GLOW && - o->otype != OBJ_SOURCE && - m->oargs.farg[3] <= FTINY) - continue; /* don't bother */ if (m->oargs.farg[0] <= FTINY && m->oargs.farg[1] <= FTINY && m->oargs.farg[2] <= FTINY) continue; /* don't bother */ - + if (m->otype == MAT_GLOW && + o->otype != OBJ_SOURCE && + m->oargs.farg[3] <= FTINY) { + foundsource += (ambounce > 0); + continue; /* don't track these */ + } if (sfun[o->otype].of == NULL || sfun[o->otype].of->setsrc == NULL) objerror(o, USER, "illegal material"); @@ -119,8 +120,10 @@ marksources(void) /* find and mark source objects */ if (m->otype == MAT_GLOW) { source[ns].sflags |= SPROX; source[ns].sl.prox = m->oargs.farg[3]; - if (source[ns].sflags & SDISTANT) + if (source[ns].sflags & SDISTANT) { source[ns].sflags |= SSKIP; + foundsource += (ambounce > 0); + } } else if (m->otype == MAT_SPOT) { source[ns].sflags |= SSPOT; if ((source[ns].sl.s = makespot(m)) == NULL) @@ -135,8 +138,7 @@ marksources(void) /* find and mark source objects */ #if SHADCACHE initobscache(ns); #endif - if (!(source[ns].sflags & SSKIP)) - foundsource++; + foundsource += !(source[ns].sflags & SSKIP); } if (!foundsource) { error(WARNING, "no light sources found"); @@ -167,6 +169,7 @@ freesources(void) /* free all source structures */ source = NULL; nsources = 0; } + markclip(NULL); if (maxcntr <= 0) return; free((void *)srccnt); @@ -184,35 +187,38 @@ srcray( /* send a ray to a source, return domega */ SRCINDEX *si /* source sample index */ ) { - double d; /* distance to source */ - register SRCREC *srcp; + double d; /* distance to source */ + register SRCREC *srcp; - rayorigin(sr, SHADOW, r, NULL); /* ignore limits */ + rayorigin(sr, SHADOW, r, NULL); /* ignore limits */ - while ((d = nextssamp(sr, si)) != 0.0) { - sr->rsrc = si->sn; /* remember source */ - srcp = source + si->sn; - if (srcp->sflags & SDISTANT) { - if (srcp->sflags & SSPOT && spotout(sr, srcp->sl.s)) - continue; - return(1); /* sample OK */ - } + if (r == NULL) + sr->rmax = 0.0; + + while ((d = nextssamp(sr, si)) != 0.0) { + sr->rsrc = si->sn; /* remember source */ + srcp = source + si->sn; + if (srcp->sflags & SDISTANT) { + if (srcp->sflags & SSPOT && spotout(sr, srcp->sl.s)) + continue; + return(1); /* sample OK */ + } /* local source */ /* check proximity */ - if (srcp->sflags & SPROX && d > srcp->sl.prox) - continue; - /* check angle */ - if (srcp->sflags & SSPOT) { - if (spotout(sr, srcp->sl.s)) + if (srcp->sflags & SPROX && d > srcp->sl.prox) continue; + /* check angle */ + if (srcp->sflags & SSPOT) { + if (spotout(sr, srcp->sl.s)) + continue; /* adjust solid angle */ - si->dom *= d*d; - d += srcp->sl.s->flen; - si->dom /= d*d; + si->dom *= d*d; + d += srcp->sl.s->flen; + si->dom /= d*d; + } + return(1); /* sample OK */ } - return(1); /* sample OK */ - } - return(0); /* no more samples */ + return(0); /* no more samples */ } @@ -306,11 +312,13 @@ sourcehit( /* check to see if ray hit distant source * If it's a glow or transparent illum, just remember it. */ if (source[i].sflags & SSKIP) { - glowsrc = i; + if (glowsrc < 0) + glowsrc = i; continue; } if (transillum(source[i].so->omod)) { - transrc = i; + if (transrc < 0) + transrc = i; continue; } r->ro = source[i].so; /* otherwise, use first hit */ @@ -409,7 +417,7 @@ direct( /* add direct component */ rayvalue(&sr); multcolor(sr.rcol, sr.rcoef); copycolor(scp->val, sr.rcol); - cntord[sn].brt = intens(sr.rcol); + cntord[sn].brt = bright(sr.rcol); } /* sort contributions */ qsort(cntord, sn, sizeof(CNTPTR), cntcmp); @@ -550,7 +558,6 @@ srcscatter( /* compute source scattering into ray */ sr.rorg[0] = r->rorg[0] + r->rdir[0]*t; sr.rorg[1] = r->rorg[1] + r->rdir[1]*t; sr.rorg[2] = r->rorg[2] + r->rdir[2]*t; - sr.rmax = 0.; initsrcindex(&si); /* sample ray to this source */ si.sn = r->slights[i]; nopart(&si, &sr);