--- ray/src/rt/ambient.c 1989/02/02 10:41:17 1.1 +++ ray/src/rt/ambient.c 1990/06/26 09:00:07 1.10 @@ -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,8 @@ 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; @@ -96,7 +85,7 @@ char *afile; /* open ambient file */ if (afile != NULL) if ((ambfp = fopen(afile, "r+")) != NULL) { - while (fread(&amb, sizeof(AMBVAL), 1, ambfp) == 1) + while (fread((char *)&amb,sizeof(AMBVAL),1,ambfp) == 1) avinsert(&amb, &atrunk, thescene.cuorg, thescene.cusize); /* align */ @@ -109,6 +98,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 +208,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; @@ -221,13 +227,12 @@ double s; 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; - } else - if (r->rop[j] > ck0[j] + (1.0+OCTSCALE)*s) - break; + if (r->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); @@ -267,6 +272,7 @@ register RAY *r; extern int ambcmp(); extern double sin(), cos(), sqrt(); double phi, xd, yd, zd; + double b, b2; register AMBSAMP *div; AMBSAMP dnew; RAY ar; @@ -321,29 +327,29 @@ register RAY *r; div[ne].n = 0; div[ne].t = i; div[ne].p = j; /* sum errors */ - xd = bright(ar.rcol); + b = bright(ar.rcol); if (i > 0) { /* from above */ - yd = bright(div[ne-np].v) - xd; - yd *= yd * 0.25; - div[ne].k += yd; + b2 = bright(div[ne-np].v) - b; + b2 *= b2 * 0.25; + div[ne].k += b2; div[ne].n++; - div[ne-np].k += yd; + div[ne-np].k += b2; div[ne-np].n++; } if (j > 0) { /* from behind */ - yd = bright(div[ne-1].v) - xd; - yd *= yd * 0.25; - div[ne].k += yd; + b2 = bright(div[ne-1].v) - b; + b2 *= b2 * 0.25; + div[ne].k += b2; div[ne].n++; - div[ne-1].k += yd; + div[ne-1].k += b2; div[ne-1].n++; } if (j == np-1) { /* around */ - yd = bright(div[ne-(np-1)].v) - xd; - yd *= yd * 0.25; - div[ne].k += yd; + b2 = bright(div[ne-(np-1)].v) - b; + b2 *= b2 * 0.25; + div[ne].k += b2; div[ne].n++; - div[ne-(np-1)].k += yd; + div[ne-(np-1)].k += b2; div[ne-(np-1)].n++; } ne++; @@ -380,13 +386,13 @@ register RAY *r; addcolor(dnew.v, ar.rcol); dnew.n = div[0].n + 1; dnew.t = div[0].t; dnew.p = div[0].p; - yd = bright(dnew.v)/dnew.n - bright(ar.rcol); - yd = yd*yd + div[0].k*(div[0].n*div[0].n); - dnew.k = yd/(dnew.n*dnew.n); + b2 = bright(dnew.v)/dnew.n - bright(ar.rcol); + 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)); - bcopy(&dnew, &div[k], sizeof(AMBSAMP)); + copystruct(&div[k], &div[k+1]); + copystruct(&div[k], &dnew); if (ne >= i) { /* extract darkest division */ ne--; @@ -431,7 +437,7 @@ AMBVAL *av; #endif if (ambfp == NULL) return; - if (fwrite(av, sizeof(AMBVAL), 1, ambfp) != 1) + if (fwrite((char *)av, sizeof(AMBVAL), 1, ambfp) != 1) goto writerr; #ifdef AMBFLUSH if (++nunflshed >= AMBFLUSH) { @@ -460,7 +466,7 @@ double s; if ((av = newambval()) == NULL) goto memerr; - bcopy(aval, av, sizeof(AMBVAL)); + copystruct(av, aval); VCOPY(ck0, c0); while (s*(OCTSCALE/2) > av->rad*ambacc) { if (at->kid == NULL)