--- ray/src/rt/source.c 1995/12/08 18:22:28 2.19 +++ ray/src/rt/source.c 1996/03/21 15:33:09 2.23 @@ -22,6 +22,10 @@ static char SCCSid[] = "$SunId$ LBL"; extern double ssampdist; /* scatter sampling distance */ +#ifndef MAXSSAMP +#define MAXSSAMP 16 /* maximum samples per ray */ +#endif + /* * Structures used by direct() */ @@ -333,8 +337,7 @@ char *p; /* data for f */ ( sr.ro != source[scp->sno].so || source[scp->sno].sflags & SFOLLOW )) { /* follow entire path */ - if (!raycont(&sr)) - objerror(sr.ro, USER, "material not found"); + raycont(&sr); rayparticipate(&sr); if (trace != NULL) (*trace)(&sr); /* trace execution */ @@ -374,6 +377,7 @@ char *p; /* data for f */ srcscatter(r) /* compute source scattering into ray */ register RAY *r; { + int oldsampndx; int nsamps; RAY sr; SRCINDEX si; @@ -381,11 +385,17 @@ register RAY *r; COLOR cumval, ctmp; int i, j; - if (r->slights == NULL || r->slights[0] == 0 || r->gecc >= 1.-FTINY) + if (r->slights == NULL || r->slights[0] == 0 + || r->gecc >= 1.-FTINY || r->rot >= FHUGE) return; if (ssampdist <= FTINY || (nsamps = r->rot/ssampdist + .5) < 1) nsamps = 1; - initsrcindex(&si); +#if MAXSSAMP + else if (nsamps > MAXSSAMP) + nsamps = MAXSSAMP; +#endif + oldsampndx = samplendx; + samplendx = random()&0x7fff; /* randomize */ for (i = r->slights[0]; i > 0; i--) { /* for each source */ setcolor(cumval, 0., 0., 0.); lastt = r->rot; @@ -396,15 +406,12 @@ register RAY *r; sr.rorg[1] = r->rorg[1] + r->rdir[1]*t; sr.rorg[2] = r->rorg[2] + r->rdir[2]*t; sr.rmax = 0.; - /* sample ray to this source */ - if (si.sp >= si.np-1 || !srcray(&sr, NULL, &si) || - sr.rsrc != r->slights[i]) { - si.sn = r->slights[i]-1; /* reset */ - si.np = 0; - if (!srcray(&sr, NULL, &si) || - sr.rsrc != r->slights[i]) - continue; /* no path */ - } + initsrcindex(&si); /* sample ray to this source */ + si.sn = r->slights[i]; + nopart(&si, &sr); + if (!srcray(&sr, NULL, &si) || + sr.rsrc != r->slights[i]) + continue; /* no path */ copycolor(sr.cext, r->cext); sr.albedo = r->albedo; sr.gecc = r->gecc; @@ -438,6 +445,7 @@ register RAY *r; multcolor(cumval, ctmp); addcolor(r->rcol, cumval); /* sum into ray result */ } + samplendx = oldsampndx; }