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.74 by greg, Fri Oct 14 19:15:34 2016 UTC vs.
Revision 2.78 by greg, Tue Jan 9 00:51:51 2018 UTC

# Line 20 | Line 20 | static const char      RCSid[] = "$Id$";
20   #include  "ray.h"
21   #include  "ambient.h"
22   #include  "random.h"
23 + #include  "source.h"
24 + #include  "otypes.h"
25 + #include  "otspecial.h"
26  
27   #ifndef OLDAMB
28  
# Line 60 | Line 63 | ambcollision(                          /* proposed direciton collides? */
63   {
64          double  cos_thresh;
65          int     ii, jj;
66 <                                        /* min. spacing = 1/10th division */
67 <        cos_thresh = (PI/10.)/(double)hp->ns;
66 >                                        /* min. spacing = 1/4th division */
67 >        cos_thresh = (PI/4.)/(double)hp->ns;
68          cos_thresh = 1. - .5*cos_thresh*cos_thresh;
69                                          /* check existing neighbors */
70          for (ii = i-1; ii <= i+1; ii++) {
# Line 126 | Line 129 | resample:
129                                          /* avoid coincident samples */
130          if (!n && ambcollision(hp, i, j, ar.rdir)) {
131                  spt[0] = frandom(); spt[1] = frandom();
132 <                goto resample;
132 >                goto resample;          /* reject this sample */
133          }
134          dimlist[ndims++] = AI(hp,i,j) + 90171;
135          rayvalue(&ar);                  /* evaluate ray */
# Line 137 | Line 140 | resample:
140          if (ar.rt*ap->d < 1.0)          /* new/closer distance? */
141                  ap->d = 1.0/ar.rt;
142          if (!n) {                       /* record first vertex & value */
143 <                if (ar.rt > 10.0*thescene.cusize)
144 <                        ar.rt = 10.0*thescene.cusize;
143 >                if (ar.rt > 10.0*thescene.cusize + 1000.)
144 >                        ar.rt = 10.0*thescene.cusize + 1000.;
145                  VSUM(ap->p, ar.rorg, ar.rdir, ar.rt);
146                  copycolor(ap->v, ar.rcol);
147          } else {                        /* else update recorded value */
# Line 160 | Line 163 | resample:
163   static float *
164   getambdiffs(AMBHEMI *hp)
165   {
166 +        const double    normf = 1./bright(hp->acoef);
167          float   *earr = (float *)calloc(hp->ns*hp->ns, sizeof(float));
168          float   *ep;
169          AMBSAMP *ap;
# Line 173 | Line 177 | getambdiffs(AMBHEMI *hp)
177              for (j = 0; j < hp->ns; j++, ap++, ep++) {
178                  b = bright(ap[0].v);
179                  if (i) {                /* from above */
180 <                        d2 = b - bright(ap[-hp->ns].v);
180 >                        d2 = normf*(b - bright(ap[-hp->ns].v));
181                          d2 *= d2;
182                          ep[0] += d2;
183                          ep[-hp->ns] += d2;
184                  }
185                  if (!j) continue;
186                                          /* from behind */
187 <                d2 = b - bright(ap[-1].v);
187 >                d2 = normf*(b - bright(ap[-1].v));
188                  d2 *= d2;
189                  ep[0] += d2;
190                  ep[-1] += d2;
191                  if (!i) continue;
192                                          /* diagonal */
193 <                d2 = b - bright(ap[-hp->ns-1].v);
193 >                d2 = normf*(b - bright(ap[-hp->ns-1].v));
194                  d2 *= d2;
195                  ep[0] += d2;
196                  ep[-hp->ns-1] += d2;
# Line 230 | Line 234 | ambsupersamp(AMBHEMI *hp, int cnt)
234                          goto done;      /* nothing left to do */
235                  nss = *ep/e2rem*cnt + frandom();
236                  for (n = 1; n <= nss && ambsample(hp,i,j,n); n++)
237 <                        --cnt;
237 >                        if (!--cnt) goto done;
238                  e2rem -= *ep++;         /* update remainder */
239          }
240   done:
# Line 248 | Line 252 | samp_hemi(                             /* sample indirect hemisphere */
252          AMBHEMI *hp;
253          double  d;
254          int     n, i, j;
255 +                                        /* insignificance check */
256 +        if (bright(rcol) <= FTINY)
257 +                return(NULL);
258                                          /* set number of divisions */
259          if (ambacc <= FTINY &&
260                          wt > (d = 0.8*intens(rcol)*r->rweight/(ambdiv*minweight)))
# Line 642 | Line 649 | ambcorral(AMBHEMI *hp, FVECT uv[2], const double r0, c
649          FVECT           vec;
650          double          u, v;
651          double          ang, a1;
652 +        OBJREC          *m;
653          int             i, j;
654                                          /* don't bother for a few samples */
655          if (hp->ns < 8)
# Line 671 | Line 679 | ambcorral(AMBHEMI *hp, FVECT uv[2], const double r0, c
679                          flgs |= 1L<<(int)(16/PI*(a1 + 2.*PI*(a1 < 0)));
680              }
681                                          /* add low-angle incident (< 20deg) */
682 <        if (fabs(hp->rp->rod) <= 0.342) {
682 >        if (fabs(hp->rp->rod) <= 0.342 && hp->rp->parent != NULL &&
683 >                        (m = findmaterial(hp->rp->parent->ro)) != NULL &&
684 >                        isopaque(m->otype)) {
685                  u = -DOT(hp->rp->rdir, uv[0]);
686                  v = -DOT(hp->rp->rdir, uv[1]);
687                  if ((r0*r0*u*u + r1*r1*v*v) > hp->rp->rot*hp->rp->rot) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines