21 |
|
#include "ambient.h" |
22 |
|
#include "random.h" |
23 |
|
|
24 |
< |
extern void SDsquare2disk(double ds[2], double seedx, double seedy); |
24 |
> |
#ifndef MINADIV |
25 |
> |
#define MINADIV 7 /* minimum # divisions in each dimension */ |
26 |
> |
#endif |
27 |
|
|
28 |
|
typedef struct { |
29 |
|
COLOR v; /* hemisphere sample value */ |
98 |
|
AMBSAMP *ap = &ambsam(hp,i,j); |
99 |
|
RAY ar; |
100 |
|
int hlist[3], ii; |
101 |
< |
double spt[2], zd; |
101 |
> |
RREAL spt[2]; |
102 |
> |
double zd; |
103 |
|
/* generate hemispherical sample */ |
104 |
|
/* ambient coefficient for weight */ |
105 |
|
if (ambacc > FTINY) |
117 |
|
hlist[2] = i; |
118 |
|
multisamp(spt, 2, urand(ilhash(hlist,3)+n)); |
119 |
|
resample: |
120 |
< |
SDsquare2disk(spt, (j+spt[1])/hp->ns, (i+spt[0])/hp->ns); |
120 |
> |
square2disk(spt, (j+spt[1])/hp->ns, (i+spt[0])/hp->ns); |
121 |
|
zd = sqrt(1. - spt[0]*spt[0] - spt[1]*spt[1]); |
122 |
|
for (ii = 3; ii--; ) |
123 |
|
ar.rdir[ii] = spt[0]*hp->ux[ii] + |
261 |
|
wt > (d = 0.8*intens(rcol)*r->rweight/(ambdiv*minweight))) |
262 |
|
wt = d; /* avoid ray termination */ |
263 |
|
n = sqrt(ambdiv * wt) + 0.5; |
264 |
< |
i = 1 + 5*(ambacc > FTINY); /* minimum number of samples */ |
265 |
< |
if (n < i) |
264 |
> |
i = 1 + (MINADIV-1)*(ambacc > FTINY); |
265 |
> |
if (n < i) /* use minimum number of samples? */ |
266 |
|
n = i; |
267 |
|
/* allocate sampling array */ |
268 |
|
hp = (AMBHEMI *)malloc(sizeof(AMBHEMI) + sizeof(AMBSAMP)*(n*n - 1)); |
294 |
|
hp->sampOK *= -1; /* soft failure */ |
295 |
|
return(hp); |
296 |
|
} |
297 |
< |
if (hp->sampOK < 64) |
298 |
< |
return(hp); /* insufficient for super-sampling */ |
297 |
> |
if (hp->sampOK <= MINADIV*MINADIV) |
298 |
> |
return(hp); /* don't bother super-sampling */ |
299 |
|
n = ambssamp*wt + 0.5; |
300 |
|
if (n > 8) { /* perform super-sampling? */ |
301 |
|
ambsupersamp(hp, n); |
716 |
|
return(0); |
717 |
|
|
718 |
|
if ((ra == NULL) & (pg == NULL) & (dg == NULL) || |
719 |
< |
(hp->sampOK < 0) | (hp->ns < 6)) { |
719 |
> |
(hp->sampOK < 0) | (hp->ns < MINADIV)) { |
720 |
|
free(hp); /* Hessian not requested/possible */ |
721 |
|
return(-1); /* value-only return value */ |
722 |
|
} |
764 |
|
ra[0] = maxarad; |
765 |
|
} |
766 |
|
/* flag encroached directions */ |
767 |
< |
if (crlp != NULL) |
767 |
> |
if (crlp != NULL) /* XXX doesn't update with changes to ambacc */ |
768 |
|
*crlp = ambcorral(hp, uv, ra[0]*ambacc, ra[1]*ambacc); |
769 |
|
if (pg != NULL) { /* cap gradient if necessary */ |
770 |
|
d = pg[0]*pg[0]*ra[0]*ra[0] + pg[1]*pg[1]*ra[1]*ra[1]; |
778 |
|
free(hp); /* clean up and return */ |
779 |
|
return(1); |
780 |
|
} |
778 |
– |
|