--- ray/src/rt/ambient.c 1989/05/30 11:06:29 1.4 +++ ray/src/rt/ambient.c 1989/08/08 17:31:23 1.6 @@ -21,6 +21,8 @@ static char SCCSid[] = "$SunId$ LBL"; #define OCTSCALE 0.5 /* ceil((valid rad.)/(cube size)) */ +#define WDONE 4 /* stop if wsum/wmin is at or above */ + extern CUBE thescene; /* contains space boundaries */ extern COLOR ambval; /* global ambient component */ @@ -164,8 +166,28 @@ double s; int i; register int j; register AMBVAL *av; - /* do this node */ + wsum = 0.0; + /* check children first */ + if (at->kid != NULL) { + s *= 0.5; + for (i = 0; i < 8; i++) { + for (j = 0; j < 3; j++) { + ck0[j] = c0[j]; + if (1<rop[j] < ck0[j] - OCTSCALE*s) + break; + if (r->rop[j] > ck0[j] + (1.0+OCTSCALE)*s) + break; + } + if (j == 3) + wsum += sumambient(acol, r, at->kid+i, ck0, s); + } + if (wsum*ambacc >= WDONE) + return(wsum); /* close enough */ + } + /* check this node */ for (av = at->alist; av != NULL; av = av->next) { /* * Ray strength test. @@ -203,7 +225,8 @@ double s; * Jittering final test reduces image artifacts. */ wt = sqrt(e1) + sqrt(e2); - if (wt > ambacc*(0.9 + 0.2*frandom())) + wt *= 0.9 + 0.2*frandom(); + if (wt > ambacc) continue; if (wt <= 1e-3) wt = 1e3; @@ -214,23 +237,6 @@ double s; scalecolor(ct, wt); addcolor(acol, ct); } - if (at->kid == NULL) - return(wsum); - /* do children */ - s *= 0.5; - for (i = 0; i < 8; i++) { - for (j = 0; j < 3; j++) { - ck0[j] = c0[j]; - if (1<rop[j] < ck0[j] - OCTSCALE*s) - break; - if (r->rop[j] > ck0[j] + (1.0+OCTSCALE)*s) - break; - } - if (j == 3) - wsum += sumambient(acol, r, at->kid+i, ck0, s); - } return(wsum); } @@ -381,8 +387,8 @@ register RAY *r; dnew.n = div[0].n + 1; dnew.t = div[0].t; dnew.p = div[0].p; b2 = bright(dnew.v)/dnew.n - bright(ar.rcol); - b2 = b2*b2 + div[0].k*div[0].n; - dnew.k = b2/dnew.n; + b2 = b2*b2 + div[0].k*(div[0].n*div[0].n); + dnew.k = b2/(dnew.n*dnew.n); /* reinsert */ for (k = 0; k < ne-1 && dnew.k < div[k+1].k; k++) bcopy(&div[k+1], &div[k], sizeof(AMBSAMP));