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.61 by greg, Sun May 18 18:59:55 2014 UTC vs.
Revision 2.65 by greg, Thu Aug 21 10:33:49 2014 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 68 | Line 68 | ambsample(                             /* initial ambient division sample */
68                  setcolor(ar.rcoef, AVGREFL, AVGREFL, AVGREFL);
69          else
70                  copycolor(ar.rcoef, hp->acoef);
71 <        if (rayorigin(&ar, AMBIENT, hp->rp, ar.rcoef) < 0) {
72 <                if (!n) memset(ap, 0, sizeof(AMBSAMP));
71 >        if (rayorigin(&ar, AMBIENT, hp->rp, ar.rcoef) < 0)
72                  return(0);
74        }
73          if (ambacc > FTINY) {
74                  multcolor(ar.rcoef, hp->acoef);
75                  scalecolor(ar.rcoef, 1./AVGREFL);
# Line 80 | Line 78 | ambsample(                             /* initial ambient division sample */
78          hlist[1] = j;
79          hlist[2] = i;
80          multisamp(spt, 2, urand(ilhash(hlist,3)+n));
81 <        if (!n) {                       /* avoid border samples for n==0 */
81 >                                        /* 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))
# Line 99 | Line 99 | ambsample(                             /* initial ambient division sample */
99          if (ar.rt <= FTINY)
100                  return(0);              /* should never happen */
101          multcolor(ar.rcol, ar.rcoef);   /* apply coefficient */
102 <        if (!n || ar.rt*ap->d < 1.0)    /* new/closer distance? */
102 >        if (ar.rt*ap->d < 1.0)          /* new/closer distance? */
103                  ap->d = 1.0/ar.rt;
104          if (!n) {                       /* record first vertex & value */
105                  if (ar.rt > 10.0*thescene.cusize)
# Line 195 | Line 195 | ambsupersamp(AMBHEMI *hp, int cnt)
195                  if (e2rem <= FTINY)
196                          goto done;      /* nothing left to do */
197                  nss = *ep/e2rem*cnt + frandom();
198 <                for (n = 1; n <= nss; n++)
199 <                        cnt -= ambsample(hp, i, j, n);
198 >                for (n = 1; n <= nss && ambsample(hp,i,j,n); n++)
199 >                        --cnt;
200                  e2rem -= *ep++;         /* update remainder */
201          }
202   done:
# Line 219 | Line 219 | samp_hemi(                             /* sample indirect hemisphere */
219                          wt > (d = 0.8*intens(rcol)*r->rweight/(ambdiv*minweight)))
220                  wt = d;                 /* avoid ray termination */
221          n = sqrt(ambdiv * wt) + 0.5;
222 <        i = 1 + 5*(ambacc > FTINY);     /* minimum number of samples */
222 >        i = 1 + 8*(ambacc > FTINY);     /* minimum number of samples */
223          if (n < i)
224                  n = i;
225                                          /* allocate sampling array */
# Line 229 | Line 229 | samp_hemi(                             /* sample indirect hemisphere */
229          hp->rp = r;
230          hp->ns = n;
231          hp->acol[RED] = hp->acol[GRN] = hp->acol[BLU] = 0.0;
232 +        memset(hp->sa, 0, sizeof(AMBSAMP)*n*n);
233          hp->sampOK = 0;
234                                          /* assign coefficient */
235          copycolor(hp->acoef, rcol);
# Line 614 | Line 615 | ambcorral(AMBHEMI *hp, FVECT uv[2], const double r0, c
615          double          avg_d = 0;
616          uint32          flgs = 0;
617          FVECT           vec;
618 <        double          d, u, v;
618 >        double          u, v;
619          double          ang, a1;
620          int             i, j;
621                                          /* don't bother for a few samples */
# Line 636 | Line 637 | ambcorral(AMBHEMI *hp, FVECT uv[2], const double r0, c
637                  if ((ap->d <= FTINY) | (ap->d >= max_d))
638                          continue;       /* too far or too near */
639                  VSUB(vec, ap->p, hp->rp->rop);
640 <                d = DOT(vec, hp->rp->ron);
641 <                d = 1.0/sqrt(DOT(vec,vec) - d*d);
642 <                u = DOT(vec, uv[0]) * d;
642 <                v = DOT(vec, uv[1]) * d;
643 <                if ((r0*r0*u*u + r1*r1*v*v) * ap->d*ap->d <= 1.0)
640 >                u = DOT(vec, uv[0]);
641 >                v = DOT(vec, uv[1]);
642 >                if ((r0*r0*u*u + r1*r1*v*v) * ap->d*ap->d <= u*u + v*v)
643                          continue;       /* occluder outside ellipse */
644                  ang = atan2a(v, u);     /* else set direction flags */
645                  for (a1 = ang-.5*ang_res; a1 <= ang+.5*ang_res; a1 += ang_step)
# Line 696 | Line 695 | doambient(                             /* compute ambient component */
695                  return(0);
696  
697          if ((ra == NULL) & (pg == NULL) & (dg == NULL) ||
698 <                        (hp->sampOK < 0) | (hp->ns < 4)) {
698 >                        (hp->sampOK < 0) | (hp->ns < 9)) {
699                  free(hp);               /* Hessian not requested/possible */
700                  return(-1);             /* value-only return value */
701          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines