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.62 by greg, Mon May 19 20:23:48 2014 UTC vs.
Revision 2.73 by greg, Fri Oct 14 00:54:21 2016 UTC

# Line 21 | Line 21 | static const char      RCSid[] = "$Id$";
21   #include  "ambient.h"
22   #include  "random.h"
23  
24 < #ifdef NEWAMB
24 > #ifndef OLDAMB
25  
26   extern void             SDsquare2disk(double ds[2], double seedx, double seedy);
27  
# 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 <        if (!n) {                       /* avoid border samples for n==0 */
82 <                if ((spt[0] < 0.1) | (spt[0] >= 0.9))
83 <                        spt[0] = 0.1 + 0.8*frandom();
84 <                if ((spt[1] < 0.1) | (spt[1] >= 0.9))
85 <                        spt[1] = 0.1 + 0.8*frandom();
86 <        }
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 91 | 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 178 | Line 211 | ambsupersamp(AMBHEMI *hp, int cnt)
211          float   *earr = getambdiffs(hp);
212          double  e2rem = 0;
213          AMBSAMP *ap;
181        RAY     ar;
214          float   *ep;
215          int     i, j, n, nss;
216  
# Line 234 | 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();
238 <        hp->uy[1] = 0.5 - frandom();
239 <        hp->uy[2] = 0.5 - frandom();
240 <        for (i = 3; i--; )
241 <                if ((-0.6 < r->ron[i]) & (r->ron[i] < 0.6))
242 <                        break;
243 <        if (i < 0)
269 >        if (!getperpendicular(hp->ux, r->ron, 1))
270                  error(CONSISTENCY, "bad ray direction in samp_hemi");
245        hp->uy[i] = 1.0;
246        VCROSS(hp->ux, hp->uy, r->ron);
247        normalize(hp->ux);
271          VCROSS(hp->uy, r->ron, hp->ux);
272                                          /* sample divisions */
273          for (i = hp->ns; i--; )
# Line 608 | Line 631 | static uint32
631   ambcorral(AMBHEMI *hp, FVECT uv[2], const double r0, const double r1)
632   {
633          const double    max_d = 1.0/(minarad*ambacc + 0.001);
634 <        const double    ang_res = 0.5*PI/(hp->ns-1);
635 <        const double    ang_step = ang_res/((int)(16/PI*ang_res) + (1+FTINY));
634 >        const double    ang_res = 0.5*PI/hp->ns;
635 >        const double    ang_step = ang_res/((int)(16/PI*ang_res) + 1.01);
636          double          avg_d = 0;
637          uint32          flgs = 0;
638          FVECT           vec;
# Line 617 | 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 640 | Line 663 | ambcorral(AMBHEMI *hp, FVECT uv[2], const double r0, c
663                  if ((r0*r0*u*u + r1*r1*v*v) * ap->d*ap->d <= u*u + v*v)
664                          continue;       /* occluder outside ellipse */
665                  ang = atan2a(v, u);     /* else set direction flags */
666 <                for (a1 = ang-.5*ang_res; a1 <= ang+.5*ang_res; a1 += ang_step)
666 >                for (a1 = ang-ang_res; a1 <= ang+ang_res; a1 += ang_step)
667                          flgs |= 1L<<(int)(16/PI*(a1 + 2.*PI*(a1 < 0)));
668              }
669                                          /* add low-angle incident (< 20deg) */
# Line 693 | Line 716 | doambient(                             /* compute ambient component */
716                  return(0);
717  
718          if ((ra == NULL) & (pg == NULL) & (dg == NULL) ||
719 <                        (hp->sampOK < 0) | (hp->ns < 4)) {
719 >                        (hp->sampOK < 0) | (hp->ns < 6)) {
720                  free(hp);               /* Hessian not requested/possible */
721                  return(-1);             /* value-only return value */
722          }
# Line 741 | 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