--- ray/src/rt/source.c 1990/12/17 14:38:12 1.27 +++ ray/src/rt/source.c 1991/06/14 14:58:49 1.32 @@ -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; @@ -214,9 +215,13 @@ register int sn; /* source number */ } if (dstrsrc > FTINY) { /* distribute source direction */ - for (i = 0; i < 3; i++) - vd[i] = dstrsrc * source[sn].ss * (1.0 - 2.0*frandom()); - + dimlist[ndims++] = sn; + for (i = 0; i < 3; i++) { + dimlist[ndims] = i + 8831; + vd[i] = dstrsrc * source[sn].ss * + (1.0 - 2.0*urand(ilhash(dimlist,ndims+1)+samplendx)); + } + ndims--; if (norm != NULL) { /* project offset */ d = DOT(vd, norm); for (i = 0; i < 3; i++) @@ -313,7 +318,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) @@ -336,10 +342,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); @@ -368,9 +383,8 @@ 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 : @@ -378,9 +392,6 @@ char *p; /* data for f */ < 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); @@ -399,11 +410,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); @@ -459,7 +473,5 @@ register RAY *r; m->oargs.farg[2]); /* modify value */ multcolor(r->rcol, r->pcol); - /* assign distance */ - r->rt = r->rot; } }