--- ray/src/rt/ambient.c 1989/05/30 11:06:29 1.4 +++ ray/src/rt/ambient.c 1990/01/12 11:30:59 1.8 @@ -17,6 +17,8 @@ static char SCCSid[] = "$SunId$ LBL"; #include "octree.h" +#include "otypes.h" + #include "random.h" #define OCTSCALE 0.5 /* ceil((valid rad.)/(cube size)) */ @@ -32,7 +34,7 @@ extern int ambounce; /* number of ambient bounces */ extern char *amblist[]; /* ambient include/exclude list */ extern int ambincl; /* include == 1, exclude == 0 */ -OBJECT ambset[128]; /* ambient include/exclude set */ +OBJECT ambset[256]={0}; /* ambient include/exclude set */ double maxarad; /* maximum ambient radius */ double minarad; /* minimum ambient radius */ @@ -74,21 +76,9 @@ setambient(afile) /* initialize calculation */ char *afile; { long ftell(); - char **amblp; OBJECT obj; AMBVAL amb; - /* set up ambient set */ - ambset[0] = 0; - for (amblp = amblist; *amblp != NULL; amblp++) { - if ((obj = modifier(*amblp)) == OVOID) { - sprintf(errmsg, "unknown %s modifier \"%s\"", - ambincl ? "include" : "exclude", *amblp); - error(WARNING, errmsg); - continue; - } - if (!inset(ambset, obj)) - insertelem(ambset, obj); - } + maxarad = thescene.cusize / 2.0; /* maximum radius */ /* minimum radius */ minarad = ambres > 0 ? thescene.cusize/ambres : 0.0; @@ -109,6 +99,22 @@ char *afile; } +ambnotify(obj) /* record new modifier */ +OBJECT obj; +{ + register OBJREC *o = objptr(obj); + register char **amblp; + + if (!ismodifier(o->otype)) + return; + for (amblp = amblist; *amblp != NULL; amblp++) + if (!strcmp(o->oname, *amblp)) { + insertelem(ambset, obj); + return; + } +} + + ambient(acol, r) /* compute ambient component for ray */ COLOR acol; register RAY *r; @@ -203,7 +209,8 @@ double s; * Jittering final test reduces image artifacts. */ wt = sqrt(e1) + sqrt(e2); - if (wt > ambacc*(0.9 + 0.2*frandom())) + wt *= .9 + .2*frandom(); + if (wt > ambacc) continue; if (wt <= 1e-3) wt = 1e3; @@ -381,8 +388,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));