--- ray/src/rt/ambient.c 1989/05/30 20:06:09 1.5 +++ ray/src/rt/ambient.c 1991/05/22 12:44:39 1.12 @@ -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,8 @@ 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 */ +#define MAXASET 511 /* maximum number of elements in ambient set */ +OBJECT ambset[MAXASET+1]={0}; /* ambient include/exclude set */ double maxarad; /* maximum ambient radius */ double minarad; /* minimum ambient radius */ @@ -74,21 +77,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 +86,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 +99,28 @@ char *afile; } +ambnotify(obj) /* record new modifier */ +OBJECT obj; +{ + static int hitlimit = 0; + register OBJREC *o = objptr(obj); + register char **amblp; + + if (hitlimit || !ismodifier(o->otype)) + return; + for (amblp = amblist; *amblp != NULL; amblp++) + if (!strcmp(o->oname, *amblp)) { + if (ambset[0] >= MAXASET) { + error(WARNING, "too many modifiers in ambient list"); + hitlimit++; + return; /* should this be fatal? */ + } + insertelem(ambset, obj); + return; + } +} + + ambient(acol, r) /* compute ambient component for ray */ COLOR acol; register RAY *r; @@ -203,7 +215,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; @@ -265,6 +278,7 @@ register RAY *r; { extern int ambcmp(); extern double sin(), cos(), sqrt(); + int hlist[4]; double phi, xd, yd, zd; double b, b2; register AMBSAMP *div; @@ -299,20 +313,28 @@ register RAY *r; fcross(ux, r->ron, uy); normalize(ux); fcross(uy, ux, r->ron); + /* set up urand */ + hlist[0] = r->rno; /* sample divisions */ arad = 0.0; ne = 0; - for (i = 0; i < nt; i++) + for (i = 0; i < nt; i++) { + hlist[1] = i; for (j = 0; j < np; j++) { rayorigin(&ar, r, AMBIENT, 0.5); /* pretested */ - zd = sqrt((i+frandom())/nt); - phi = 2.0*PI * (j+frandom())/np; + hlist[2] = j; + hlist[3] = 0; + zd = sqrt((i+urand(ilhash(hlist,4)))/nt); + hlist[3] = 1; + phi = 2.0*PI * (j+urand(ilhash(hlist,4)))/np; xd = cos(phi) * zd; yd = sin(phi) * zd; zd = sqrt(1.0 - zd*zd); for (k = 0; k < 3; k++) ar.rdir[k] = xd*ux[k]+yd*uy[k]+zd*r->ron[k]; + dimlist[ndims++] = i*np + j + 38813; rayvalue(&ar); + ndims--; if (ar.rot < FHUGE) arad += 1.0 / ar.rot; if (ns > 0) { /* save division */ @@ -350,6 +372,7 @@ register RAY *r; } else addcolor(acol, ar.rcol); } + } for (k = 0; k < ne; k++) { /* compute errors */ if (div[k].n > 1) div[k].k /= div[k].n; @@ -365,14 +388,21 @@ register RAY *r; /* super-sample */ for (i = ns; i > 0; i--) { rayorigin(&ar, r, AMBIENT, 0.5); /* pretested */ - zd = sqrt((div[0].t+frandom())/nt); - phi = 2.0*PI * (div[0].p+frandom())/np; + hlist[1] = div[0].t; + hlist[2] = div[0].p; + hlist[3] = 0; + zd = sqrt((div[0].t+urand(ilhash(hlist,4)+div[0].n))/nt); + hlist[3] = 1; + phi = 2.0*PI * (div[0].p+urand(ilhash(hlist,4)+div[0].n))/np; xd = cos(phi) * zd; yd = sin(phi) * zd; zd = sqrt(1.0 - zd*zd); for (k = 0; k < 3; k++) ar.rdir[k] = xd*ux[k]+yd*uy[k]+zd*r->ron[k]; + dimlist[ndims++] = div[0].t*np + div[0].p + 38813; rayvalue(&ar); + ndims--; + rayvalue(&ar); if (ar.rot < FHUGE) arad += 1.0 / ar.rot; /* recompute error */ @@ -385,8 +415,8 @@ register RAY *r; 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 +461,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 +490,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)