--- ray/src/rt/source.c 1990/12/15 15:03:34 1.26 +++ ray/src/rt/source.c 1991/02/11 08:43:48 1.30 @@ -109,6 +109,7 @@ register OBJREC *so; register int i; src->sflags = 0; + src->aimsuccess = 2*AIMREQT-1; /* bitch on second failure */ src->nhits = 1; src->ntests = 2; /* start probability = 1/2 */ src->so = so; @@ -237,26 +238,24 @@ register int sn; /* source number */ /* domega constant */ return(source[sn].ss2); - else { /* check proximity */ - if (source[sn].sflags & SPROX && - d > source[sn].sl.prox) - return(0.0); - - if (norm != NULL) - ddot /= d; - else - ddot = 1.0; + if (source[sn].sflags & SPROX && + d > source[sn].sl.prox) + return(0.0); + /* compute dot product */ + if (norm != NULL) + ddot /= d; + else + ddot = 1.0; /* check angle */ - if (source[sn].sflags & SSPOT) { - if (source[sn].sl.s->siz < 2.0*PI * + if (source[sn].sflags & SSPOT) { + if (source[sn].sl.s->siz < 2.0*PI * (1.0 + DOT(source[sn].sl.s->aim,sr->rdir))) - return(0.0); - d += source[sn].sl.s->flen; - } - /* return domega */ - return(ddot*source[sn].ss2/(d*d)); + return(0.0); + d += source[sn].sl.s->flen; /* adjust length */ } + /* compute domega */ + return(ddot*source[sn].ss2/(d*d)); } @@ -315,7 +314,8 @@ char *p; /* data for f */ extern double pow(); register int sn; int nshadcheck, ncnts; - double prob, ourthresh, hwt, test2, hit2; + int nhits; + double prob, ourthresh, hwt; RAY sr; /* NOTE: srccnt and cntord global so no recursion */ if (nsources <= 0) @@ -338,10 +338,19 @@ char *p; /* data for f */ if (cntord[sn].brt <= 0.0) continue; /* compute intersection */ - if (!( source[sn].sflags & SDISTANT ? + if (source[sn].sflags & SDISTANT ? sourcehit(&sr) : (*ofun[source[sn].so->otype].funp) - (source[sn].so, &sr) )) { + (source[sn].so, &sr)) { + if (source[sn].aimsuccess >= 0) + source[sn].aimsuccess++; + } else { + cntord[sn].brt = 0.0; + if (source[sn].aimsuccess < 0) + continue; /* bitched already */ + source[sn].aimsuccess -= AIMREQT; + if (source[sn].aimsuccess >= 0) + continue; /* leniency */ sprintf(errmsg, "aiming failure for light source \"%s\"", source[sn].so->oname); @@ -370,19 +379,15 @@ char *p; /* data for f */ /* accumulate tail */ for (sn = ncnts-1; sn > 0; sn--) cntord[sn-1].brt += cntord[sn].brt; - /* start with prob=.5 */ - hit2 = 0.5; test2 = 1.0; /* test for shadows */ + nhits = 0; for (sn = 0; sn < ncnts; sn++) { /* check threshold */ if ((sn+nshadcheck>=ncnts ? cntord[sn].brt : - cntord[sn].brt-cntord[sn+nshadcheck].brt) < - ourthresh*bright(r->rcol)) + cntord[sn].brt-cntord[sn+nshadcheck].brt) + < ourthresh*bright(r->rcol)) break; /* get statistics */ - hwt = (double)source[cntord[sn].sno].nhits / - (double)source[cntord[sn].sno].ntests; - test2 += hwt; source[cntord[sn].sno].ntests++; /* test for hit */ rayorigin(&sr, r, SHADOW, 1.0); @@ -401,11 +406,14 @@ char *p; /* data for f */ } /* add contribution if hit */ addcolor(r->rcol, srccnt[cntord[sn].sno].val); - hit2 += hwt; + nhits++; source[cntord[sn].sno].nhits++; } - /* weighted hit rate */ - hwt = hit2 / test2; + /* surface hit rate */ + if (sn > 0) + hwt = (double)nhits / (double)sn; + else + hwt = 0.5; #ifdef DEBUG sprintf(errmsg, "%d tested, %d untested, %f hit rate\n", sn, ncnts-sn, hwt);