--- ray/src/rt/ambcomp.c 1992/10/02 16:14:38 2.4 +++ ray/src/rt/ambcomp.c 1998/12/16 18:14:57 2.8 @@ -1,7 +1,7 @@ -/* Copyright (c) 1991 Regents of the University of California */ +/* Copyright (c) 1998 Silicon Graphics, Inc. */ #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static char SCCSid[] = "$SunId$ SGI"; #endif /* @@ -73,8 +73,8 @@ RAY *r; multisamp(spt, 2, urand(ilhash(hlist,3)+dp->n)); zd = sqrt((dp->t + spt[0])/h->nt); phi = 2.0*PI * (dp->p + spt[1])/h->np; - xd = cos(phi) * zd; - yd = sin(phi) * zd; + xd = tcos(phi) * zd; + yd = tsin(phi) * zd; zd = sqrt(1.0 - zd*zd); for (i = 0; i < 3; i++) ar.rdir[i] = xd*h->ux[i] + @@ -84,8 +84,9 @@ RAY *r; rayvalue(&ar); ndims--; addcolor(dp->v, ar.rcol); - if (ar.rt > FTINY && ar.rt < FHUGE) - dp->r += 1.0/ar.rt; + /* be conservative and use rot */ + if (ar.rot > FTINY && ar.rot < FHUGE) + dp->r += 1.0/ar.rot; /* (re)initialize error */ if (dp->n++) { b2 = bright(dp->v)/dp->n - bright(ar.rcol); @@ -139,14 +140,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 */ @@ -168,6 +170,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) { @@ -355,7 +358,7 @@ register AMBHEMI *hp; } mag0 *= 2.0*PI / hp->np; phi = 2.0*PI * (double)j/hp->np; - cosp = cos(phi); sinp = sin(phi); + cosp = tcos(phi); sinp = tsin(phi); xd += mag0*cosp - mag1*sinp; yd += mag0*sinp + mag1*cosp; } @@ -389,8 +392,8 @@ register AMBHEMI *hp; dp += hp->np; } phi = 2.0*PI * (j+.5)/hp->np + PI/2.0; - xd += mag * cos(phi); - yd += mag * sin(phi); + xd += mag * tcos(phi); + yd += mag * tsin(phi); } for (i = 0; i < 3; i++) gv[i] = (xd*hp->ux[i] + yd*hp->uy[i])/(hp->nt*hp->np);