--- ray/src/rt/ambcomp.c 2014/05/19 20:23:48 2.62 +++ ray/src/rt/ambcomp.c 2014/10/23 18:19:14 2.68 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: ambcomp.c,v 2.62 2014/05/19 20:23:48 greg Exp $"; +static const char RCSid[] = "$Id: ambcomp.c,v 2.68 2014/10/23 18:19:14 greg Exp $"; #endif /* * Routines to compute "ambient" values using Monte Carlo @@ -21,7 +21,7 @@ static const char RCSid[] = "$Id: ambcomp.c,v 2.62 201 #include "ambient.h" #include "random.h" -#ifdef NEWAMB +#ifndef OLDAMB extern void SDsquare2disk(double ds[2], double seedx, double seedy); @@ -78,7 +78,9 @@ ambsample( /* initial ambient division sample */ hlist[1] = j; hlist[2] = i; multisamp(spt, 2, urand(ilhash(hlist,3)+n)); - if (!n) { /* avoid border samples for n==0 */ + /* avoid coincident samples */ + if (!n && (0 < i) & (i < hp->ns-1) && + (0 < j) & (j < hp->ns-1)) { if ((spt[0] < 0.1) | (spt[0] >= 0.9)) spt[0] = 0.1 + 0.8*frandom(); if ((spt[1] < 0.1) | (spt[1] >= 0.9)) @@ -178,7 +180,6 @@ ambsupersamp(AMBHEMI *hp, int cnt) float *earr = getambdiffs(hp); double e2rem = 0; AMBSAMP *ap; - RAY ar; float *ep; int i, j, n, nss; @@ -608,8 +609,8 @@ static uint32 ambcorral(AMBHEMI *hp, FVECT uv[2], const double r0, const double r1) { const double max_d = 1.0/(minarad*ambacc + 0.001); - const double ang_res = 0.5*PI/(hp->ns-1); - const double ang_step = ang_res/((int)(16/PI*ang_res) + (1+FTINY)); + const double ang_res = 0.5*PI/hp->ns; + const double ang_step = ang_res/((int)(16/PI*ang_res) + 1.01); double avg_d = 0; uint32 flgs = 0; FVECT vec; @@ -640,7 +641,7 @@ ambcorral(AMBHEMI *hp, FVECT uv[2], const double r0, c if ((r0*r0*u*u + r1*r1*v*v) * ap->d*ap->d <= u*u + v*v) continue; /* occluder outside ellipse */ ang = atan2a(v, u); /* else set direction flags */ - for (a1 = ang-.5*ang_res; a1 <= ang+.5*ang_res; a1 += ang_step) + for (a1 = ang-ang_res; a1 <= ang+ang_res; a1 += ang_step) flgs |= 1L<<(int)(16/PI*(a1 + 2.*PI*(a1 < 0))); } /* add low-angle incident (< 20deg) */ @@ -693,7 +694,7 @@ doambient( /* compute ambient component */ return(0); if ((ra == NULL) & (pg == NULL) & (dg == NULL) || - (hp->sampOK < 0) | (hp->ns < 4)) { + (hp->sampOK < 0) | (hp->ns < 6)) { free(hp); /* Hessian not requested/possible */ return(-1); /* value-only return value */ }