--- ray/src/rt/ambcomp.c 1992/02/19 12:00:04 2.2 +++ ray/src/rt/ambcomp.c 1995/05/03 09:46:31 2.5 @@ -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; @@ -148,7 +146,9 @@ FVECT pg, dg; 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 */ @@ -207,11 +207,8 @@ FVECT pg, dg; scalecolor(acol, b); if (arad <= FTINY) arad = maxarad; - else { + else arad = (ndivs+ns)/arad; - if (arad > maxarad) - arad = maxarad; - } if (pg != NULL) { /* reduce radius if gradient large */ d = DOT(pg,pg); if (d*arad*arad > 1.0) @@ -225,7 +222,9 @@ FVECT pg, dg; pg[i] *= d; } } - return(arad/sqrt(wt)); + if ((arad /= sqrt(wt)) > maxarad) + arad = maxarad; + return(arad); oopsy: if (div != NULL) free((char *)div);