| 60 |
|
RAY *r; |
| 61 |
|
{ |
| 62 |
|
RAY ar; |
| 63 |
< |
int hlist[4]; |
| 63 |
> |
int hlist[3]; |
| 64 |
> |
double spt[2]; |
| 65 |
|
double xd, yd, zd; |
| 66 |
|
double b2; |
| 67 |
|
double phi; |
| 68 |
|
register int i; |
| 69 |
|
|
| 70 |
< |
if (rayorigin(&ar, r, AMBIENT, 0.5) < 0) |
| 70 |
> |
if (rayorigin(&ar, r, AMBIENT, AVGREFL) < 0) |
| 71 |
|
return(-1); |
| 72 |
|
hlist[0] = r->rno; |
| 73 |
|
hlist[1] = dp->t; |
| 74 |
|
hlist[2] = dp->p; |
| 75 |
< |
hlist[3] = 0; |
| 76 |
< |
zd = sqrt((dp->t+urand(urind(ilhash(hlist,4),dp->n)))/h->nt); |
| 77 |
< |
hlist[3] = 1; |
| 77 |
< |
phi = 2.0*PI * (dp->p+urand(urind(ilhash(hlist,4),dp->n)))/h->np; |
| 75 |
> |
multisamp(spt, 2, urand(ilhash(hlist,3)+dp->n)); |
| 76 |
> |
zd = sqrt((dp->t + spt[0])/h->nt); |
| 77 |
> |
phi = 2.0*PI * (dp->p + spt[1])/h->np; |
| 78 |
|
xd = cos(phi) * zd; |
| 79 |
|
yd = sin(phi) * zd; |
| 80 |
|
zd = sqrt(1.0 - zd*zd); |
| 100 |
|
|
| 101 |
|
|
| 102 |
|
double |
| 103 |
< |
doambient(acol, r, pg, dg) /* compute ambient component */ |
| 103 |
> |
doambient(acol, r, wt, pg, dg) /* compute ambient component */ |
| 104 |
|
COLOR acol; |
| 105 |
|
RAY *r; |
| 106 |
+ |
double wt; |
| 107 |
|
FVECT pg, dg; |
| 108 |
|
{ |
| 109 |
|
double b, d; |
| 117 |
|
/* initialize color */ |
| 118 |
|
setcolor(acol, 0.0, 0.0, 0.0); |
| 119 |
|
/* initialize hemisphere */ |
| 120 |
< |
inithemi(&hemi, r); |
| 120 |
> |
inithemi(&hemi, r, wt); |
| 121 |
|
ndivs = hemi.nt * hemi.np; |
| 122 |
|
if (ndivs == 0) |
| 123 |
|
return(0.0); |
| 124 |
|
/* set number of super-samples */ |
| 125 |
< |
ns = ambssamp * r->rweight + 0.5; |
| 125 |
> |
ns = ambssamp * wt + 0.5; |
| 126 |
|
if (ns > 0 || pg != NULL || dg != NULL) { |
| 127 |
|
div = (AMBSAMP *)malloc(ndivs*sizeof(AMBSAMP)); |
| 128 |
|
if (div == NULL) |
| 213 |
|
arad = maxarad; |
| 214 |
|
else if (arad < minarad) |
| 215 |
|
arad = minarad; |
| 216 |
< |
arad /= sqrt(r->rweight); |
| 216 |
> |
arad /= sqrt(wt); |
| 217 |
|
if (pg != NULL) { /* clip pos. gradient if too large */ |
| 218 |
|
d = 4.0*DOT(pg,pg)*arad*arad; |
| 219 |
|
if (d > 1.0) { |
| 230 |
|
} |
| 231 |
|
|
| 232 |
|
|
| 233 |
< |
inithemi(hp, r) /* initialize sampling hemisphere */ |
| 233 |
> |
inithemi(hp, r, wt) /* initialize sampling hemisphere */ |
| 234 |
|
register AMBHEMI *hp; |
| 235 |
|
RAY *r; |
| 236 |
+ |
double wt; |
| 237 |
|
{ |
| 238 |
|
register int i; |
| 239 |
|
/* set number of divisions */ |
| 240 |
< |
hp->nt = sqrt(ambdiv * r->rweight / PI) + 0.5; |
| 240 |
> |
hp->nt = sqrt(ambdiv * wt / PI) + 0.5; |
| 241 |
|
hp->np = PI * hp->nt; |
| 242 |
|
/* make axes */ |
| 243 |
|
VCOPY(hp->uz, r->ron); |