--- ray/src/rt/source.c 1989/06/13 10:57:52 1.12 +++ ray/src/rt/source.c 1989/11/29 14:35:27 1.18 @@ -329,7 +329,7 @@ char *p; /* data for f */ /* compute coefficient */ (*f)(srccnt[sn].val, p, srccnt[sn].dir, srccnt[sn].dom); cntord[sn].brt = bright(srccnt[sn].val); - if (cntord[sn].brt <= FTINY) + if (cntord[sn].brt <= 0.0) continue; /* compute intersection */ if (!( source[sn].sflags & SDISTANT ? @@ -344,16 +344,18 @@ char *p; /* data for f */ } /* sort contributions */ qsort(cntord, nsources, sizeof(CNTPTR), cntcmp); - /* find last */ - sn = 0; ncnts = nsources; - while (sn < ncnts-1) { - register int m; - m = (sn + ncnts) >> 1; - if (cntord[m].brt > 0.0) - sn = m; - else - ncnts = m; - } + { /* find last */ + register int l, m; + + sn = 0; ncnts = l = nsources; + while ((m = (sn + ncnts) >> 1) != l) { + if (cntord[m].brt > 0.0) + sn = m; + else + ncnts = m; + l = m; + } + } /* accumulate tail */ for (sn = ncnts-1; sn > 0; sn--) cntord[sn-1].brt += cntord[sn].brt; @@ -377,8 +379,8 @@ char *p; /* data for f */ if (localhit(&sr, &thescene) && sr.ro != source[cntord[sn].sno].so) { /* check for transmission */ - if (sr.clipset != NULL && inset(sr.clipset,sr.ro->omod)) - raytrans(&sr); /* object is clipped */ + if (sr.clipset != NULL && inset(sr.clipset, sr.ro->omod)) + raytrans(&sr); else rayshade(&sr, sr.ro->omod); if (bright(sr.rcol) <= FTINY) @@ -395,7 +397,7 @@ char *p; /* data for f */ } /* weighted hit rate */ hwt = hit2 / test2; -#ifdef DEBUG +#ifdef notdef sprintf(errmsg, "%d tested, %d untested, %f hit rate\n", sn, ncnts-sn, hwt); eputs(errmsg); @@ -429,9 +431,6 @@ m_light(m, r) /* ray hit a light source */ register OBJREC *m; register RAY *r; { - /* check for behind */ - if (r->rod < 0.0) - return; /* check for over-counting */ if (wrongsource(m, r) || badambient(m, r)) return; @@ -445,6 +444,9 @@ register RAY *r; /* otherwise treat as source */ } else { + /* check for behind */ + if (r->rod < 0.0) + return; /* get distribution pattern */ raytexture(r, m->omod); /* get source color */