--- ray/src/rt/source.c 2005/03/10 22:37:00 2.47 +++ ray/src/rt/source.c 2007/07/25 04:12:36 2.56 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: source.c,v 2.47 2005/03/10 22:37:00 greg Exp $"; +static const char RCSid[] = "$Id: source.c,v 2.56 2007/07/25 04:12:36 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; @@ -57,12 +55,16 @@ findmaterial(register OBJREC *o) ao = objptr(aobj); if (ismaterial(ao->otype)) return(ao); + if (ao->otype == MOD_ALIAS) { + o = ao; + continue; + } } if (o->omod == OVOID) return(NULL); o = objptr(o->omod); } - return(o); + return(o); /* mixtures will return NULL */ } @@ -84,7 +86,13 @@ marksources(void) /* find and mark source objects */ continue; /* find material */ m = findmaterial(objptr(o->omod)); - if (m == NULL || !islight(m->otype)) + if (m == NULL) + continue; + if (m->otype == MAT_CLIP) { + markclip(m); /* special case for antimatter */ + continue; + } + if (!islight(m->otype)) continue; /* not source modifier */ if (m->oargs.nfargs != (m->otype == MAT_GLOW ? 4 : @@ -179,7 +187,7 @@ srcray( /* send a ray to a source, return domega */ double d; /* distance to source */ register SRCREC *srcp; - rayorigin(sr, r, SHADOW, 1.0); /* ignore limits */ + rayorigin(sr, SHADOW, r, NULL); /* ignore limits */ while ((d = nextssamp(sr, si)) != 0.0) { sr->rsrc = si->sn; /* remember source */ @@ -384,7 +392,7 @@ direct( /* add direct component */ scp->sno = sr.rsrc; /* compute coefficient */ (*f)(scp->coef, p, sr.rdir, si.dom); - cntord[sn].brt = bright(scp->coef); + cntord[sn].brt = intens(scp->coef); if (cntord[sn].brt <= 0.0) continue; #if SHADCACHE @@ -395,12 +403,13 @@ direct( /* add direct component */ } #endif VCOPY(scp->dir, sr.rdir); + copycolor(sr.rcoef, scp->coef); /* compute potential */ sr.revf = srcvalue; rayvalue(&sr); + multcolor(sr.rcol, sr.rcoef); copycolor(scp->val, sr.rcol); - multcolor(scp->val, scp->coef); - cntord[sn].brt = bright(scp->val); + cntord[sn].brt = intens(sr.rcol); } /* sort contributions */ qsort(cntord, sn, sizeof(CNTPTR), cntcmp); @@ -438,7 +447,8 @@ direct( /* add direct component */ break; scp = srccnt + cntord[sn].sndx; /* test for hit */ - rayorigin(&sr, r, SHADOW, 1.0); + rayorigin(&sr, SHADOW, r, NULL); + copycolor(sr.rcoef, scp->coef); VCOPY(sr.rdir, scp->dir); sr.rsrc = scp->sno; /* keep statistics */ @@ -451,7 +461,6 @@ direct( /* add direct component */ source[scp->sno].sflags & SFOLLOW )) { /* follow entire path */ raycont(&sr); - rayparticipate(&sr); if (trace != NULL) (*trace)(&sr); /* trace execution */ if (bright(sr.rcol) <= FTINY) { @@ -463,8 +472,15 @@ direct( /* add direct component */ #endif continue; /* missed! */ } + rayparticipate(&sr); + multcolor(sr.rcol, sr.rcoef); copycolor(scp->val, sr.rcol); - multcolor(scp->val, scp->coef); + } else if (trace != NULL && + (source[scp->sno].sflags & (SDISTANT|SVIRTUAL|SFOLLOW)) + == (SDISTANT|SFOLLOW) && + sourcehit(&sr) && rayshade(&sr, sr.ro->omod)) { + (*trace)(&sr); /* trace execution */ + /* skip call to rayparticipate() & scp->val update */ } /* add contribution if hit */ addcolor(r->rcol, scp->val); @@ -486,9 +502,8 @@ direct( /* add direct component */ scp = srccnt + cntord[sn].sndx; prob = hwt * (double)source[scp->sno].nhits / (double)source[scp->sno].ntests; - if (prob > 1.0) - prob = 1.0; - scalecolor(scp->val, prob); + if (prob < 1.0) + scalecolor(scp->val, prob); addcolor(r->rcol, scp->val); } } @@ -667,10 +682,14 @@ m_light( /* ray hit a light source */ ) { /* check for over-counting */ - if (badcomponent(m, r)) + if (badcomponent(m, r)) { + setcolor(r->rcoef, 0.0, 0.0, 0.0); return(1); - if (wrongsource(m, r)) + } + if (wrongsource(m, r)) { + setcolor(r->rcoef, 0.0, 0.0, 0.0); return(1); + } /* check for passed illum */ if (passillum(m, r)) { if (m->oargs.nsargs && strcmp(m->oargs.sarg[0], VOIDID)) @@ -678,12 +697,14 @@ m_light( /* ray hit a light source */ raytrans(r); return(1); } + /* check for invisibility */ + if (srcignore(m, r)) { + setcolor(r->rcoef, 0.0, 0.0, 0.0); + return(1); + } /* otherwise treat as source */ /* check for behind */ if (r->rod < 0.0) - return(1); - /* check for invisibility */ - if (srcignore(m, r)) return(1); /* check for outside spot */ if (m->otype==MAT_SPOT && spotout(r, makespot(m)))