--- ray/src/rt/ambcomp.c 1991/07/11 16:39:00 1.9 +++ ray/src/rt/ambcomp.c 1991/08/26 10:11:39 1.14 @@ -60,21 +60,21 @@ AMBHEMI *h; RAY *r; { RAY ar; - int hlist[4]; + int hlist[3]; + double spt[2]; double xd, yd, zd; double b2; double phi; register int i; - if (rayorigin(&ar, r, AMBIENT, 0.5) < 0) + if (rayorigin(&ar, r, AMBIENT, AVGREFL) < 0) return(-1); hlist[0] = r->rno; hlist[1] = dp->t; hlist[2] = dp->p; - hlist[3] = 0; - zd = sqrt((dp->t+urand(urind(ilhash(hlist,4),dp->n)))/h->nt); - hlist[3] = 1; - phi = 2.0*PI * (dp->p+urand(urind(ilhash(hlist,4),dp->n)))/h->np; + 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; zd = sqrt(1.0 - zd*zd); @@ -100,9 +100,10 @@ RAY *r; double -doambient(acol, r, pg, dg) /* compute ambient component */ +doambient(acol, r, wt, pg, dg) /* compute ambient component */ COLOR acol; RAY *r; +double wt; FVECT pg, dg; { double b, d; @@ -116,12 +117,12 @@ FVECT pg, dg; /* initialize color */ setcolor(acol, 0.0, 0.0, 0.0); /* initialize hemisphere */ - inithemi(&hemi, r); + inithemi(&hemi, r, wt); ndivs = hemi.nt * hemi.np; if (ndivs == 0) return(0.0); /* set number of super-samples */ - ns = ambssamp * r->rweight + 0.5; + ns = ambssamp * wt + 0.5; if (ns > 0 || pg != NULL || dg != NULL) { div = (AMBSAMP *)malloc(ndivs*sizeof(AMBSAMP)); if (div == NULL) @@ -212,7 +213,7 @@ FVECT pg, dg; arad = maxarad; else if (arad < minarad) arad = minarad; - arad /= sqrt(r->rweight); + arad /= sqrt(wt); if (pg != NULL) { /* clip pos. gradient if too large */ d = 4.0*DOT(pg,pg)*arad*arad; if (d > 1.0) { @@ -229,14 +230,19 @@ oopsy: } -inithemi(hp, r) /* initialize sampling hemisphere */ +inithemi(hp, r, wt) /* initialize sampling hemisphere */ register AMBHEMI *hp; RAY *r; +double wt; { register int i; /* set number of divisions */ - hp->nt = sqrt(ambdiv * r->rweight * 0.5) + 0.5; - hp->np = 2 * hp->nt; + if (wt < (.25*PI)/ambdiv+FTINY) { + hp->nt = hp->np = 0; + return; /* zero samples */ + } + hp->nt = sqrt(ambdiv * wt / PI) + 0.5; + hp->np = PI * hp->nt + 0.5; /* make axes */ VCOPY(hp->uz, r->ron); hp->uy[0] = hp->uy[1] = hp->uy[2] = 0.0;