--- ray/src/rt/ambient.c 1991/08/29 11:13:14 1.17 +++ ray/src/rt/ambient.c 1992/04/10 16:14:34 2.4 @@ -47,17 +47,32 @@ static FILE *ambfp = NULL; /* ambient file pointer */ #define newambtree() (AMBTREE *)calloc(8, sizeof(AMBTREE)) +setambres(ar) /* set ambient resolution */ +int ar; +{ + /* set min & max radii */ + if (ar <= 0) { + minarad = 0.0; + maxarad = thescene.cusize / 2.0; + } else { + minarad = thescene.cusize / ar; + maxarad = 16.0 * minarad; /* heuristic */ + if (maxarad > thescene.cusize / 2.0) + maxarad = thescene.cusize / 2.0; + } + if (maxarad <= FTINY) + maxarad = .001; +} + + setambient(afile) /* initialize calculation */ char *afile; { long ftell(); AMBVAL amb; - - maxarad = thescene.cusize / 2.0; /* maximum radius */ - /* minimum radius */ - minarad = ambres > 0 ? thescene.cusize/ambres : 0.0; - - /* open ambient file */ + /* init ambient limits */ + setambres(ambres); + /* open ambient file */ if (afile != NULL) if ((ambfp = fopen(afile, "r+")) != NULL) { while (fread((char *)&amb,sizeof(AMBVAL),1,ambfp) == 1) @@ -186,13 +201,13 @@ double s; for (j = 0; j < 3; j++) d += (r->rop[j] - av->pos[j]) * (av->dir[j] + r->ron[j]); - if (d*0.5 < -minarad*ambacc) + if (d*0.5 < -minarad*ambacc-.001) continue; /* * Jittering final test reduces image artifacts. */ wt = sqrt(e1) + sqrt(e2); - wt *= .9 + .2*frandom(); + wt *= .9 + .2*urand(9015+samplendx); if (wt > ambacc) continue; if (wt <= 1e-3)