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.66 by greg, Thu Sep 4 09:09:08 2014 UTC vs.
Revision 2.73 by greg, Fri Oct 14 00:54:21 2016 UTC

# Line 51 | Line 51 | typedef struct {
51  
52  
53   static int
54 + ambcollision(                           /* proposed direciton collides? */
55 +        AMBHEMI *hp,
56 +        int     i,
57 +        int     j,
58 +        FVECT   dv
59 + )
60 + {
61 +        const double    cos_thresh = 0.9999995; /* about 3.44 arcminutes */
62 +        int             ii, jj;
63 +
64 +        for (ii = i-1; ii <= i+1; ii++) {
65 +                if (ii < 0) continue;
66 +                if (ii >= hp->ns) break;
67 +                for (jj = j-1; jj <= j+1; jj++) {
68 +                        AMBSAMP *ap;
69 +                        FVECT   avec;
70 +                        double  dprod;
71 +                        if (jj < 0) continue;
72 +                        if (jj >= hp->ns) break;
73 +                        if ((ii==i) & (jj==j)) continue;
74 +                        ap = &ambsam(hp,ii,jj);
75 +                        if (ap->d <= .5/FHUGE) continue;
76 +                        VSUB(avec, ap->p, hp->rp->rop);
77 +                        dprod = DOT(avec, dv);
78 +                        if (dprod >= cos_thresh*VLEN(avec))
79 +                                return(1);      /* collision */
80 +                }
81 +        }
82 +        return(0);
83 + }
84 +
85 +
86 + static int
87   ambsample(                              /* initial ambient division sample */
88          AMBHEMI *hp,
89          int     i,
# Line 78 | Line 111 | ambsample(                             /* initial ambient division sample */
111          hlist[1] = j;
112          hlist[2] = i;
113          multisamp(spt, 2, urand(ilhash(hlist,3)+n));
114 <                                        /* avoid coincident samples */
82 <        if (!n && (0 < i) & (i < hp->ns-1) &&
83 <                        (0 < j) & (j < hp->ns-1)) {
84 <                if ((spt[0] < 0.1) | (spt[0] >= 0.9))
85 <                        spt[0] = 0.1 + 0.8*frandom();
86 <                if ((spt[1] < 0.1) | (spt[1] >= 0.9))
87 <                        spt[1] = 0.1 + 0.8*frandom();
88 <        }
114 > resample:
115          SDsquare2disk(spt, (j+spt[1])/hp->ns, (i+spt[0])/hp->ns);
116          zd = sqrt(1. - spt[0]*spt[0] - spt[1]*spt[1]);
117          for (ii = 3; ii--; )
# Line 93 | Line 119 | ambsample(                             /* initial ambient division sample */
119                                  spt[1]*hp->uy[ii] +
120                                  zd*hp->rp->ron[ii];
121          checknorm(ar.rdir);
122 +                                        /* avoid coincident samples */
123 +        if (!n && ambcollision(hp, i, j, ar.rdir)) {
124 +                spt[0] = frandom(); spt[1] = frandom();
125 +                goto resample;
126 +        }
127          dimlist[ndims++] = AI(hp,i,j) + 90171;
128          rayvalue(&ar);                  /* evaluate ray */
129          ndims--;
# Line 180 | Line 211 | ambsupersamp(AMBHEMI *hp, int cnt)
211          float   *earr = getambdiffs(hp);
212          double  e2rem = 0;
213          AMBSAMP *ap;
183        RAY     ar;
214          float   *ep;
215          int     i, j, n, nss;
216  
# Line 219 | Line 249 | samp_hemi(                             /* sample indirect hemisphere */
249                          wt > (d = 0.8*intens(rcol)*r->rweight/(ambdiv*minweight)))
250                  wt = d;                 /* avoid ray termination */
251          n = sqrt(ambdiv * wt) + 0.5;
252 <        i = 1 + 8*(ambacc > FTINY);     /* minimum number of samples */
252 >        i = 1 + 5*(ambacc > FTINY);     /* minimum number of samples */
253          if (n < i)
254                  n = i;
255                                          /* allocate sampling array */
# Line 236 | Line 266 | samp_hemi(                             /* sample indirect hemisphere */
266          d = 1.0/(n*n);
267          scalecolor(hp->acoef, d);
268                                          /* make tangent plane axes */
269 <        hp->uy[0] = 0.5 - frandom();
240 <        hp->uy[1] = 0.5 - frandom();
241 <        hp->uy[2] = 0.5 - frandom();
242 <        for (i = 3; i--; )
243 <                if ((-0.6 < r->ron[i]) & (r->ron[i] < 0.6))
244 <                        break;
245 <        if (i < 0)
269 >        if (!getperpendicular(hp->ux, r->ron, 1))
270                  error(CONSISTENCY, "bad ray direction in samp_hemi");
247        hp->uy[i] = 1.0;
248        VCROSS(hp->ux, hp->uy, r->ron);
249        normalize(hp->ux);
271          VCROSS(hp->uy, r->ron, hp->ux);
272                                          /* sample divisions */
273          for (i = hp->ns; i--; )
# Line 619 | Line 640 | ambcorral(AMBHEMI *hp, FVECT uv[2], const double r0, c
640          double          ang, a1;
641          int             i, j;
642                                          /* don't bother for a few samples */
643 <        if (hp->ns < 12)
643 >        if (hp->ns < 8)
644                  return(0);
645                                          /* check distances overhead */
646          for (i = hp->ns*3/4; i-- > hp->ns>>2; )
# Line 695 | Line 716 | doambient(                             /* compute ambient component */
716                  return(0);
717  
718          if ((ra == NULL) & (pg == NULL) & (dg == NULL) ||
719 <                        (hp->sampOK < 0) | (hp->ns < 9)) {
719 >                        (hp->sampOK < 0) | (hp->ns < 6)) {
720                  free(hp);               /* Hessian not requested/possible */
721                  return(-1);             /* value-only return value */
722          }
# Line 743 | Line 764 | doambient(                             /* compute ambient component */
764                                  ra[0] = maxarad;
765                  }
766                                          /* flag encroached directions */
767 <                if ((wt >= 0.89*AVGREFL) & (crlp != NULL))
767 >                if (crlp != NULL)
768                          *crlp = ambcorral(hp, uv, ra[0]*ambacc, ra[1]*ambacc);
769                  if (pg != NULL) {       /* cap gradient if necessary */
770                          d = pg[0]*pg[0]*ra[0]*ra[0] + pg[1]*pg[1]*ra[1]*ra[1];

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines