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.93 by greg, Tue Apr 16 23:32:20 2024 UTC vs.
Revision 2.96 by greg, Fri Nov 15 20:47:42 2024 UTC

# Line 100 | Line 100 | ambsample(                             /* initial ambient division sample */
100          AMBSAMP *ap = &ambsam(hp,i,j);
101          RAY     ar;
102          int     hlist[3], ii;
103 +        double  ss[2];
104          RREAL   spt[2];
105          double  zd;
106                                          /* generate hemispherical sample */
# Line 111 | Line 112 | ambsample(                             /* initial ambient division sample */
112          if (rayorigin(&ar, hp->atyp, hp->rp, ar.rcoef) < 0)
113                  return(0);
114          if (ambacc > FTINY) {
115 + #ifdef SSKIPOPT
116 +                ar.rsrc = -1;           /* protect cache from source opt. */
117 +                ar.scorr = 1.f;
118 + #endif
119                  smultscolor(ar.rcoef, hp->acoef);
120                  scalescolor(ar.rcoef, 1./AVGREFL);
121          }
122          hlist[0] = hp->rp->rno;
123 <        hlist[1] = j;
124 <        hlist[2] = i;
125 <        multisamp(spt, 2, urand(ilhash(hlist,3)+n));
123 >        hlist[1] = AI(hp,i,j);
124 >        hlist[2] = samplendx;
125 >        multisamp(ss, 2, urand(ilhash(hlist,3)+n));
126   resample:
127 <        square2disk(spt, (j+spt[1])/hp->ns, (i+spt[0])/hp->ns);
127 >        square2disk(spt, (j+ss[1])/hp->ns, (i+ss[0])/hp->ns);
128          zd = sqrt(1. - spt[0]*spt[0] - spt[1]*spt[1]);
129          for (ii = 3; ii--; )
130                  ar.rdir[ii] =   spt[0]*hp->ux[ii] +
# Line 127 | Line 132 | resample:
132                                  zd*hp->onrm[ii];
133          checknorm(ar.rdir);
134                                          /* avoid coincident samples */
135 <        if (!n && ambcollision(hp, i, j, ar.rdir)) {
136 <                spt[0] = frandom(); spt[1] = frandom();
135 >        if (!n && hp->ns >= 4 && ambcollision(hp, i, j, ar.rdir)) {
136 >                ss[0] = frandom(); ss[1] = frandom();
137                  goto resample;          /* reject this sample */
138          }
139          dimlist[ndims++] = AI(hp,i,j) + 90171;
# Line 163 | Line 168 | static float *
168   getambdiffs(AMBHEMI *hp)
169   {
170          const double    normf = 1./(pbright(hp->acoef) + FTINY);
171 <        float   *earr = (float *)calloc(hp->ns*hp->ns, sizeof(float));
172 <        float   *ep, *earr2;
171 >        float   *earr = (float *)calloc(2*hp->ns*hp->ns, sizeof(float));
172 >        float   *ep;
173          AMBSAMP *ap;
174          double  b, b1, d2;
175          int     i, j;
# Line 172 | Line 177 | getambdiffs(AMBHEMI *hp)
177          if (earr == NULL)               /* out of memory? */
178                  return(NULL);
179                                          /* sum squared neighbor diffs */
180 <        for (ap = hp->sa, ep = earr, i = 0; i < hp->ns; i++)
180 >        ap = hp->sa;
181 >        ep = earr + hp->ns*hp->ns;      /* original estimates to scratch */
182 >        for (i = 0; i < hp->ns; i++)
183              for (j = 0; j < hp->ns; j++, ap++, ep++) {
184                  b = pbright(ap[0].v);
185                  if (i) {                /* from above */
# Line 198 | Line 205 | getambdiffs(AMBHEMI *hp)
205                  ep[-hp->ns-1] += d2;
206              }
207                                          /* correct for number of neighbors */
208 <        earr[0] *= 6./3.;
209 <        earr[hp->ns-1] *= 6./3.;
210 <        earr[(hp->ns-1)*hp->ns] *= 6./3.;
211 <        earr[(hp->ns-1)*hp->ns + hp->ns-1] *= 6./3.;
208 >        ep = earr + hp->ns*hp->ns;
209 >        ep[0] *= 6./3.;
210 >        ep[hp->ns-1] *= 6./3.;
211 >        ep[(hp->ns-1)*hp->ns] *= 6./3.;
212 >        ep[(hp->ns-1)*hp->ns + hp->ns-1] *= 6./3.;
213          for (i = 1; i < hp->ns-1; i++) {
214 <                earr[i*hp->ns] *= 6./5.;
215 <                earr[i*hp->ns + hp->ns-1] *= 6./5.;
214 >                ep[i*hp->ns] *= 6./5.;
215 >                ep[i*hp->ns + hp->ns-1] *= 6./5.;
216          }
217          for (j = 1; j < hp->ns-1; j++) {
218 <                earr[j] *= 6./5.;
219 <                earr[(hp->ns-1)*hp->ns + j] *= 6./5.;
218 >                ep[j] *= 6./5.;
219 >                ep[(hp->ns-1)*hp->ns + j] *= 6./5.;
220          }
221 <                                        /* preen map to avoid cliffs */
214 <        earr2 = (float *)malloc(hp->ns*hp->ns*sizeof(float));
215 <        if (earr2 == NULL)
216 <                return(earr);
217 <        memcpy(earr2, earr, hp->ns*hp->ns*sizeof(float));
221 >                                        /* blur final map to reduce bias */
222          for (i = 0; i < hp->ns-1; i++) {
223 <            float  *ep2 = earr2 + i*hp->ns;
223 >            float  *ep2;
224              ep = earr + i*hp->ns;
225 <            for (j = 0; j < hp->ns-1; j++, ep2++, ep++) {
226 <                if (ep2[1] < .5*ep2[0]) {
227 <                        ep[0] -= .125*ep2[0];
228 <                        ep[1] += .125*ep2[0];
229 <                } else if (ep2[1] > 2.*ep2[0]) {
226 <                        ep[1] -= .125*ep2[1];
227 <                        ep[0] += .125*ep2[1];
228 <                }
229 <                if (ep2[hp->ns] < .5*ep2[0]) {
230 <                        ep[0] -= .125*ep2[0];
231 <                        ep[hp->ns] += .125*ep2[0];
232 <                } else if (ep2[hp->ns] > 2.*ep2[0]) {
233 <                        ep[hp->ns] -= .125*ep2[hp->ns];
234 <                        ep[0] += .125*ep2[hp->ns];
235 <                }
225 >            ep2 = ep + hp->ns*hp->ns;
226 >            for (j = 0; j < hp->ns-1; j++, ep++, ep2++) {
227 >                ep[0] += .5*ep2[0] + .125*(ep2[1] + ep2[hp->ns]);
228 >                ep[1] += .125*ep2[0];
229 >                ep[hp->ns] += .125*ep2[0];
230              }
231          }
238        free(earr2);
232          return(earr);
233   }
234  
# Line 287 | Line 280 | samp_hemi(                             /* sample indirect hemisphere */
280                                          /* set number of divisions */
281          if (backside) wt = -wt;
282          if (ambacc <= FTINY &&
283 <                        wt > (d *= 0.8*r->rweight/(ambdiv*minweight)))
283 >                        wt > (d *= 0.8*r->rweight/(ambdiv*minweight + 1e-20)))
284                  wt = d;                 /* avoid ray termination */
285          n = sqrt(ambdiv * wt) + 0.5;
286          i = 1 + (MINADIV-1)*(ambacc > FTINY);
# Line 336 | Line 329 | samp_hemi(                             /* sample indirect hemisphere */
329          if (hp->sampOK <= MINADIV*MINADIV)
330                  return(hp);             /* don't bother super-sampling */
331          n = ambssamp*wt + 0.5;
332 <        if (n > 8) {                    /* perform super-sampling? */
332 >        if (n >= 4*hp->ns) {            /* perform super-sampling? */
333                  ambsupersamp(hp, n);
334                  copyscolor(rcol, hp->acol);
335          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines