| 16 |
|
#include "random.h" |
| 17 |
|
|
| 18 |
|
|
| 19 |
< |
int |
| 19 |
> |
void |
| 20 |
|
inithemi( /* initialize sampling hemisphere */ |
| 21 |
|
register AMBHEMI *hp, |
| 22 |
|
RAY *r, |
| 24 |
|
double wt |
| 25 |
|
) |
| 26 |
|
{ |
| 27 |
– |
int ns; |
| 28 |
– |
double d; |
| 27 |
|
register int i; |
| 28 |
|
/* set number of divisions */ |
| 29 |
< |
hp->nt = sqrt(ambdiv * wt / PI) + 0.5; |
| 29 |
> |
hp->nt = sqrt(ambdiv * wt * (1./PI/AVGREFL)) + 0.5; |
| 30 |
|
i = ambacc > FTINY ? 3 : 1; /* minimum number of samples */ |
| 31 |
|
if (hp->nt < i) |
| 32 |
|
hp->nt = i; |
| 33 |
|
hp->np = PI * hp->nt + 0.5; |
| 34 |
|
/* set number of super-samples */ |
| 35 |
< |
ns = ambssamp * wt + 0.5; |
| 36 |
< |
/* assign coefficient */ |
| 39 |
< |
d = 1.0/(hp->nt*hp->np + ns); /* XXX weight not uniform if ns > 0 */ |
| 35 |
> |
hp->ns = ambssamp * wt + 0.5; |
| 36 |
> |
/* assign coefficients */ |
| 37 |
|
copycolor(hp->acoef, ac); |
| 38 |
< |
scalecolor(hp->acoef, d); |
| 38 |
> |
if (wt >= r->rweight) |
| 39 |
> |
hp->drc = 1.; |
| 40 |
> |
else |
| 41 |
> |
hp->drc = wt / r->rweight; |
| 42 |
|
/* make axes */ |
| 43 |
|
VCOPY(hp->uz, r->ron); |
| 44 |
|
hp->uy[0] = hp->uy[1] = hp->uy[2] = 0.0; |
| 51 |
|
fcross(hp->ux, hp->uy, hp->uz); |
| 52 |
|
normalize(hp->ux); |
| 53 |
|
fcross(hp->uy, hp->uz, hp->ux); |
| 54 |
– |
return(ns); |
| 54 |
|
} |
| 55 |
|
|
| 56 |
|
|
| 68 |
|
double b2; |
| 69 |
|
double phi; |
| 70 |
|
register int i; |
| 71 |
< |
/* assign coefficient */ |
| 72 |
< |
if (ambacc <= FTINY) /* no storage, so report accurately */ |
| 74 |
< |
copycolor(ar.rcoef, h->acoef); |
| 75 |
< |
else /* else lie for sake of cache */ |
| 76 |
< |
setcolor(ar.rcoef, AVGREFL, AVGREFL, AVGREFL); |
| 71 |
> |
/* ambient coefficient for weight */ |
| 72 |
> |
setcolor(ar.rcoef, h->drc, h->drc, h->drc); |
| 73 |
|
if (rayorigin(&ar, AMBIENT, r, ar.rcoef) < 0) |
| 74 |
|
return(-1); |
| 75 |
< |
copycolor(ar.rcoef, h->acoef); /* correct coefficient rtrace output */ |
| 75 |
> |
copycolor(ar.rcoef, h->acoef); /* correct coefficient for trace */ |
| 76 |
> |
b2 = 1.0/(h->nt*h->np + h->ns); /* XXX not uniform if ns > 0 */ |
| 77 |
> |
scalecolor(ar.rcoef, b2); |
| 78 |
|
hlist[0] = r->rno; |
| 79 |
|
hlist[1] = dp->t; |
| 80 |
|
hlist[2] = dp->p; |
| 155 |
|
AMBSAMP dnew; |
| 156 |
|
register AMBSAMP *dp; |
| 157 |
|
double arad; |
| 158 |
< |
int ndivs, ns; |
| 158 |
> |
int ndivs; |
| 159 |
|
register int i, j; |
| 160 |
|
/* initialize color */ |
| 161 |
|
setcolor(acol, 0.0, 0.0, 0.0); |
| 162 |
|
/* initialize hemisphere */ |
| 163 |
< |
ns = inithemi(&hemi, r, ac, wt); |
| 163 |
> |
inithemi(&hemi, r, ac, wt); |
| 164 |
|
ndivs = hemi.nt * hemi.np; |
| 165 |
|
if (ndivs == 0) |
| 166 |
|
return(0.0); |
| 167 |
|
/* allocate super-samples */ |
| 168 |
< |
if (ns > 0 || pg != NULL || dg != NULL) { |
| 168 |
> |
if (hemi.ns > 0 || pg != NULL || dg != NULL) { |
| 169 |
|
div = (AMBSAMP *)malloc(ndivs*sizeof(AMBSAMP)); |
| 170 |
|
if (div == NULL) |
| 171 |
|
error(SYSTEM, "out of memory in doambient"); |
| 189 |
|
else |
| 190 |
|
addcolor(acol, dp->v); |
| 191 |
|
} |
| 192 |
< |
if (ns > 0 && arad > FTINY && ndivs/arad < minarad) |
| 193 |
< |
ns = 0; /* close enough */ |
| 194 |
< |
else if (ns > 0) { /* else perform super-sampling */ |
| 192 |
> |
if (hemi.ns > 0 && arad > FTINY && ndivs/arad < minarad) |
| 193 |
> |
hemi.ns = 0; /* close enough */ |
| 194 |
> |
else if (hemi.ns > 0) { /* else perform super-sampling */ |
| 195 |
|
comperrs(div, &hemi); /* compute errors */ |
| 196 |
|
qsort(div, ndivs, sizeof(AMBSAMP), ambcmp); /* sort divs */ |
| 197 |
|
/* super-sample */ |
| 198 |
< |
for (i = ns; i > 0; i--) { |
| 198 |
> |
for (i = hemi.ns; i > 0; i--) { |
| 199 |
|
dnew = *div; |
| 200 |
|
if (divsample(&dnew, &hemi, r) < 0) |
| 201 |
|
goto oopsy; |
| 252 |
|
if (arad <= FTINY) |
| 253 |
|
arad = maxarad; |
| 254 |
|
else |
| 255 |
< |
arad = (ndivs+ns)/arad; |
| 255 |
> |
arad = (ndivs+hemi.ns)/arad; |
| 256 |
|
if (pg != NULL) { /* reduce radius if gradient large */ |
| 257 |
|
d = DOT(pg,pg); |
| 258 |
|
if (d*arad*arad > 1.0) |