--- ray/src/rt/ambcomp.c 1992/03/04 16:28:25 2.3 +++ ray/src/rt/ambcomp.c 1996/04/23 11:06:54 2.6 @@ -27,9 +27,7 @@ typedef struct { short nt, np; /* number of theta and phi directions */ } AMBHEMI; /* ambient sample hemisphere */ -extern double sin(), cos(), sqrt(); - static int ambcmp(d1, d2) /* decreasing order */ AMBSAMP *d1, *d2; @@ -141,14 +139,15 @@ FVECT pg, dg; dp->n = 0; if (divsample(dp, &hemi, r) < 0) goto oopsy; + arad += dp->r; if (div != NULL) dp++; - else { + else addcolor(acol, dp->v); - arad += dp->r; - } } - if (ns > 0) { /* perform super-sampling */ + if (ns > 0 && arad > FTINY && ndivs/arad < minarad) + ns = 0; /* close enough */ + else if (ns > 0) { /* else perform super-sampling */ comperrs(div, &hemi); /* compute errors */ qsort(div, ndivs, sizeof(AMBSAMP), ambcmp); /* sort divs */ /* super-sample */ @@ -170,6 +169,7 @@ FVECT pg, dg; } /* compute returned values */ if (div != NULL) { + arad = 0.0; for (i = ndivs, dp = div; i-- > 0; dp++) { arad += dp->r; if (dp->n > 1) {