--- ray/src/rt/virtuals.c 1991/06/25 13:11:53 1.9 +++ ray/src/rt/virtuals.c 1991/06/26 08:55:10 1.13 @@ -19,7 +19,10 @@ static char SCCSid[] = "$SunId$ LBL"; #include "random.h" +#define MINSAMPLES 3 /* minimum number of pretest samples */ +#define STESTMAX 30 /* maximum seeks per sample */ + double getdisk(); static OBJECT *vobject; /* virtual source objects */ @@ -179,7 +182,7 @@ MAT4 pm; } if (source[sn].sflags & SFLAT) { /* behind source? */ multv3(nsnorm, source[sn].snorm, pm); - if (checkspot(&ourspot, nsnorm) < 0) + if (!checkspot(&ourspot, nsnorm)) return(-1); } } @@ -254,7 +257,7 @@ register int sn; /* target source number */ double or, d; int infront; int ssn; - int nhit; + int nhit, nok; register int i, n; /* return if pretesting disabled */ if (vspretest <= 0) @@ -272,15 +275,15 @@ register int sn; /* target source number */ n = or2/DOT(offsdir,offsdir)*vspretest + .5; infront = DOT(onorm, offsdir) > 0.; } - if (n < 1) n = 1; + if (n < MINSAMPLES) n = MINSAMPLES; #ifdef DEBUG fprintf(stderr, "pretesting source %d in object %s with %d rays\n", sn, o->oname, n); #endif /* sample */ or = sqrt(or2); - ssn = 25*n; - nhit = 0; + ssn = STESTMAX*n; + nhit = nok = 0; while (n-- > 0) { /* get sample point */ do { @@ -316,16 +319,18 @@ register int sn; /* target source number */ rayvalue(&sr); if (bright(sr.rcol) <= FTINY) continue; + nok++; /* check against obstructions */ srcray(&sr, NULL, sn); rayvalue(&sr); - if (bright(sr.rcol) <= FTINY) { + if (bright(sr.rcol) > FTINY) + nhit++; + if (nhit > 0 && nhit < nok) { #ifdef DEBUG - fprintf(stderr, "\tfound an occlusion\n"); + fprintf(stderr, "\tpartially occluded\n"); #endif - return(f); /* need to shadow test */ + return(f); /* need to shadow test */ } - nhit++; } if (nhit == 0) { #ifdef DEBUG