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.49 by greg, Wed May 7 01:16:02 2014 UTC vs.
Revision 2.52 by greg, Wed May 7 21:45:13 2014 UTC

# Line 272 | Line 272 | static void
272   ambsupersamp(double acol[3], AMBHEMI *hp, int cnt)
273   {
274          float   *earr = getambdiffs(hp);
275 <        double  e2sum = 0;
275 >        double  e2sum = 0.0;
276          AMBSAMP *ap;
277          RAY     ar;
278 <        COLOR   asum;
278 >        double  asum[3];
279          float   *ep;
280          int     i, j, n;
281  
# Line 288 | Line 288 | ambsupersamp(double acol[3], AMBHEMI *hp, int cnt)
288          for (ap = hp->sa, i = 0; i < hp->ns; i++)
289              for (j = 0; j < hp->ns; j++, ap++) {
290                  int     nss = *ep/e2sum*cnt + frandom();
291 <                setcolor(asum, 0., 0., 0.);
291 >                asum[0] = asum[1] = asum[2] = 0.0;
292                  for (n = 1; n <= nss; n++) {
293                          if (!getambsamp(&ar, hp, i, j, n)) {
294                                  nss = n-1;
# Line 299 | Line 299 | ambsupersamp(double acol[3], AMBHEMI *hp, int cnt)
299                  if (nss) {              /* update returned ambient value */
300                          const double    ssf = 1./(nss + 1);
301                          for (n = 3; n--; )
302 <                                acol[n] += ssf*colval(asum,n) +
302 >                                acol[n] += ssf*asum[n] +
303                                                  (ssf - 1.)*colval(ap->v,n);
304                  }
305                  e2sum -= *ep++;         /* update remainders */
# Line 722 | Line 722 | ambdirgrad(AMBHEMI *hp, FVECT uv[2], float dg[2])
722   static uint32
723   ambcorral(AMBHEMI *hp, FVECT uv[2], const double r0, const double r1)
724   {
725 <        uint32  flgs = 0;
726 <        int     i, j;
727 <                                        /* circle around perimeter */
725 >        const double    max_d = 1.0/(minarad*ambacc + 0.001);
726 >        const double    ang_res = 0.5*PI/(hp->ns-1);
727 >        const double    ang_step = ang_res/((int)(16/PI*ang_res) + (1+FTINY));
728 >        double          avg_d = 0;
729 >        uint32          flgs = 0;
730 >        int             i, j;
731 >                                        /* don't bother for a few samples */
732 >        if (hp->ns < 12)
733 >                return(0);
734 >                                        /* check distances overhead */
735 >        for (i = hp->ns*3/4; i-- > hp->ns>>2; )
736 >            for (j = hp->ns*3/4; j-- > hp->ns>>2; )
737 >                avg_d += ambsam(hp,i,j).d;
738 >        avg_d *= 4.0/(hp->ns*hp->ns);
739 >        if (avg_d*r0 >= 1.0)            /* ceiling too low for corral? */
740 >                return(0);
741 >        if (avg_d >= max_d)             /* insurance */
742 >                return(0);
743 >                                        /* else circle around perimeter */
744          for (i = 0; i < hp->ns; i++)
745              for (j = 0; j < hp->ns; j += !i|(i==hp->ns-1) ? 1 : hp->ns-1) {
746                  AMBSAMP *ap = &ambsam(hp,i,j);
747                  FVECT   vec;
748                  double  u, v;
749 <                double  ang;
749 >                double  ang, a1;
750                  int     abp;
751 <                if (ap->d <= FTINY)
752 <                        continue;
751 >                if ((ap->d <= FTINY) | (ap->d >= max_d))
752 >                        continue;       /* too far or too near */
753                  VSUB(vec, ap->p, hp->rp->rop);
754                  u = DOT(vec, uv[0]) * ap->d;
755                  v = DOT(vec, uv[1]) * ap->d;
756                  if ((r0*r0*u*u + r1*r1*v*v) * ap->d*ap->d <= 1.0)
757                          continue;       /* occluder outside ellipse */
758                  ang = atan2a(v, u);     /* else set direction flags */
759 <                ang += 2.0*PI*(ang < 0);
760 <                ang *= 16./PI;
745 <                if ((ang < .5) | (ang >= 31.5))
746 <                        flgs |= 0x80000001;
747 <                else
748 <                        flgs |= 3L<<(int)(ang-.5);
759 >                for (a1 = ang-.5*ang_res; a1 <= ang+.5*ang_res; a1 += ang_step)
760 >                        flgs |= 1L<<(int)(16/PI*(a1 + 2.*PI*(a1 < 0)));
761              }
762          return(flgs);
763   }
# Line 802 | Line 814 | doambient(                             /* compute ambient component */
814                  return(-1);             /* return value w/o Hessian */
815          }
816          cnt = ambssamp*wt + 0.5;        /* perform super-sampling? */
817 <        if (cnt > 0)
817 >        if (cnt > 8)
818                  ambsupersamp(acol, hp, cnt);
819          copycolor(rcol, acol);          /* final indirect irradiance/PI */
820          if ((ra == NULL) & (pg == NULL) & (dg == NULL)) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines