ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/ambcomp.c
(Generate patch)

Comparing ray/src/rt/ambcomp.c (file contents):
Revision 2.92 by greg, Fri Apr 5 01:10:26 2024 UTC vs.
Revision 2.98 by greg, Thu Apr 24 01:43:58 2025 UTC

# Line 64 | Line 64 | ambcollision(                          /* proposed direciton collides? */
64          int     ii, jj;
65                                          /* min. spacing = 1/4th division */
66          cos_thresh = (PI/4.)/(double)hp->ns;
67 +        if (cos_thresh > 7.*PI/180.)    /* 7 degrees is enough in any case */
68 +                cos_thresh = 7.*PI/180.;
69          cos_thresh = 1. - .5*cos_thresh*cos_thresh;
70                                          /* check existing neighbors */
71          for (ii = i-1; ii <= i+1; ii++) {
# Line 100 | Line 102 | ambsample(                             /* initial ambient division sample */
102          AMBSAMP *ap = &ambsam(hp,i,j);
103          RAY     ar;
104          int     hlist[3], ii;
105 +        double  ss[2];
106          RREAL   spt[2];
107          double  zd;
108                                          /* generate hemispherical sample */
# Line 115 | Line 118 | ambsample(                             /* initial ambient division sample */
118                  scalescolor(ar.rcoef, 1./AVGREFL);
119          }
120          hlist[0] = hp->rp->rno;
121 <        hlist[1] = j;
122 <        hlist[2] = i;
123 <        multisamp(spt, 2, urand(ilhash(hlist,3)+n));
121 >        hlist[1] = AI(hp,i,j);
122 >        hlist[2] = samplendx;
123 >        multisamp(ss, 2, urand(ilhash(hlist,3)+n));
124   resample:
125 <        square2disk(spt, (j+spt[1])/hp->ns, (i+spt[0])/hp->ns);
125 >        square2disk(spt, (j+ss[1])/hp->ns, (i+ss[0])/hp->ns);
126          zd = sqrt(1. - spt[0]*spt[0] - spt[1]*spt[1]);
127          for (ii = 3; ii--; )
128                  ar.rdir[ii] =   spt[0]*hp->ux[ii] +
129                                  spt[1]*hp->uy[ii] +
130                                  zd*hp->onrm[ii];
131          checknorm(ar.rdir);
132 <                                        /* avoid coincident samples */
133 <        if (!n && ambcollision(hp, i, j, ar.rdir)) {
134 <                spt[0] = frandom(); spt[1] = frandom();
132 >                                        /* avoid coincident samples? */
133 >        if (!n & (ambacc > FTINY) & (hp->ns >= 4) &&
134 >                        ambcollision(hp, i, j, ar.rdir)) {
135 >                ss[0] = frandom(); ss[1] = frandom();
136                  goto resample;          /* reject this sample */
137          }
138          dimlist[ndims++] = AI(hp,i,j) + 90171;
# Line 162 | Line 166 | resample:
166   static float *
167   getambdiffs(AMBHEMI *hp)
168   {
169 <        const double    normf = 1./bright(hp->acoef);
170 <        float   *earr = (float *)calloc(hp->ns*hp->ns, sizeof(float));
169 >        const double    normf = 1./(pbright(hp->acoef) + FTINY);
170 >        float   *earr = (float *)calloc(2*hp->ns*hp->ns, sizeof(float));
171          float   *ep;
172          AMBSAMP *ap;
173          double  b, b1, d2;
# Line 172 | Line 176 | getambdiffs(AMBHEMI *hp)
176          if (earr == NULL)               /* out of memory? */
177                  return(NULL);
178                                          /* sum squared neighbor diffs */
179 <        for (ap = hp->sa, ep = earr, i = 0; i < hp->ns; i++)
179 >        ap = hp->sa;
180 >        ep = earr + hp->ns*hp->ns;      /* original estimates to scratch */
181 >        for (i = 0; i < hp->ns; i++)
182              for (j = 0; j < hp->ns; j++, ap++, ep++) {
183                  b = pbright(ap[0].v);
184                  if (i) {                /* from above */
# Line 198 | Line 204 | getambdiffs(AMBHEMI *hp)
204                  ep[-hp->ns-1] += d2;
205              }
206                                          /* correct for number of neighbors */
207 <        earr[0] *= 8./3.;
208 <        earr[hp->ns-1] *= 8./3.;
209 <        earr[(hp->ns-1)*hp->ns] *= 8./3.;
210 <        earr[(hp->ns-1)*hp->ns + hp->ns-1] *= 8./3.;
207 >        ep = earr + hp->ns*hp->ns;
208 >        ep[0] *= 6./3.;
209 >        ep[hp->ns-1] *= 6./3.;
210 >        ep[(hp->ns-1)*hp->ns] *= 6./3.;
211 >        ep[(hp->ns-1)*hp->ns + hp->ns-1] *= 6./3.;
212          for (i = 1; i < hp->ns-1; i++) {
213 <                earr[i*hp->ns] *= 8./5.;
214 <                earr[i*hp->ns + hp->ns-1] *= 8./5.;
213 >                ep[i*hp->ns] *= 6./5.;
214 >                ep[i*hp->ns + hp->ns-1] *= 6./5.;
215          }
216          for (j = 1; j < hp->ns-1; j++) {
217 <                earr[j] *= 8./5.;
218 <                earr[(hp->ns-1)*hp->ns + j] *= 8./5.;
217 >                ep[j] *= 6./5.;
218 >                ep[(hp->ns-1)*hp->ns + j] *= 6./5.;
219          }
220 +                                        /* blur final map to reduce bias */
221 +        for (i = 0; i < hp->ns-1; i++) {
222 +            float  *ep2;
223 +            ep = earr + i*hp->ns;
224 +            ep2 = ep + hp->ns*hp->ns;
225 +            for (j = 0; j < hp->ns-1; j++, ep++, ep2++) {
226 +                ep[0] += .5*ep2[0] + .125*(ep2[1] + ep2[hp->ns]);
227 +                ep[1] += .125*ep2[0];
228 +                ep[hp->ns] += .125*ep2[0];
229 +            }
230 +        }
231          return(earr);
232   }
233  
# Line 261 | Line 279 | samp_hemi(                             /* sample indirect hemisphere */
279                                          /* set number of divisions */
280          if (backside) wt = -wt;
281          if (ambacc <= FTINY &&
282 <                        wt > (d *= 0.8*r->rweight/(ambdiv*minweight)))
282 >                        wt > (d *= 0.8*r->rweight/(ambdiv*minweight + 1e-20)))
283                  wt = d;                 /* avoid ray termination */
284          n = sqrt(ambdiv * wt) + 0.5;
285          i = 1 + (MINADIV-1)*(ambacc > FTINY);
# Line 310 | Line 328 | samp_hemi(                             /* sample indirect hemisphere */
328          if (hp->sampOK <= MINADIV*MINADIV)
329                  return(hp);             /* don't bother super-sampling */
330          n = ambssamp*wt + 0.5;
331 <        if (n > 8) {                    /* perform super-sampling? */
331 >        if (n >= 4*hp->ns) {            /* perform super-sampling? */
332                  ambsupersamp(hp, n);
333                  copyscolor(rcol, hp->acol);
334          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines