ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/ambient.c
(Generate patch)

Comparing ray/src/rt/ambient.c (file contents):
Revision 2.73 by greg, Wed Apr 16 20:32:00 2014 UTC vs.
Revision 2.81 by greg, Fri Apr 25 23:04:16 2014 UTC

# Line 51 | Line 51 | static int  nunflshed = 0;     /* number of unflushed ambi
51   #define MAX_SORT_INTVL  (SORT_INTVL<<6)
52   #endif
53  
54 +
55 + static double  qambacc = 0.;            /* ambient accuracy to the 1/4 power */
56   static double  avsum = 0.;              /* computed ambient value sum (log) */
57   static unsigned int  navsum = 0;        /* number of values in avsum */
58   static unsigned int  nambvals = 0;      /* total number of indirect values */
# Line 132 | Line 134 | setambacc(                             /* set ambient accuracy */
134          if (newa < 0.0)
135                  newa = 0.0;
136          ambdiff = fabs(newa - ambacc);
137 <        if (ambdiff >= .01 && (ambacc = newa) > FTINY && nambvals > 0)
138 <                sortambvals(1);                 /* rebuild tree */
137 >        if (ambdiff >= .01 && (ambacc = newa) > FTINY) {
138 >                qambacc = sqrt(sqrt(ambacc));
139 >                if (nambvals > 0)
140 >                        sortambvals(1);         /* rebuild tree */
141 >        }
142   }
143  
144  
# Line 147 | Line 152 | setambient(void)                               /* initialize calculation */
152          ambdone();
153                                                  /* init ambient limits */
154          setambres(ambres);
155 <        setambacc(ambacc);
155 >        qambacc = sqrt(sqrt(ambacc *= (ambacc > FTINY)));
156          if (ambfile == NULL || !ambfile[0])
157                  return;
158          if (ambacc <= FTINY) {
# Line 352 | Line 357 | sumambient(            /* get interpolated ambient value */
357          FVECT  c0,
358          double  s
359   )
360 < {                                       /* initial limit is ambacc radians */
361 <        const double    maxangle = (ambacc-PI/2.)*pow(r->rweight,0.13) + PI/2.;
360 > {                       /* initial limit is 10 degrees plus ambacc radians */
361 >        const double    minangle = 10.0 * PI/180.;
362 >        const double    maxangle = (minangle+ambacc-PI/2.)*pow(r->rweight,0.13)
363 >                                        + PI/2.;
364          double          wsum = 0.0;
365          FVECT           ck0;
366          int             i, j;
# Line 384 | Line 391 | sumambient(            /* get interpolated ambient value */
391                  if (delta_r2 >= maxangle*maxangle)
392                          continue;
393                  /*
394 +                 *  Modified ray behind test
395 +                 */
396 +                VSUB(ck0, av->pos, r->rop);
397 +                d = DOT(ck0, uvw[2]);
398 +                if (d < -minarad*qambacc-.001)
399 +                        continue;
400 +                d /= av->rad[0];
401 +                delta_t2 = d*d;
402 +                if (delta_t2 >= qambacc*qambacc)
403 +                        continue;
404 +                /*
405                   *  Elliptical radii test based on Hessian
406                   */
407                  decodedir(uvw[0], av->udir);
408                  VCROSS(uvw[1], uvw[2], uvw[0]);
391                VSUB(ck0, av->pos, r->rop);
409                  d = DOT(ck0, uvw[0]) / av->rad[0];
410 <                delta_t2 = d*d;
410 >                delta_t2 += d*d;
411                  d = DOT(ck0, uvw[1]) / av->rad[1];
412                  delta_t2 += d*d;
413 <                if (delta_t2 >= ambacc*ambacc)
413 >                if (delta_t2 >= qambacc*qambacc)
414                          continue;
415                  /*
399                 *  Intersection behind test
400                 */
401                d = 0.0;
402                for (j = 0; j < 3; j++)
403                        d += (r->rop[j] - av->pos[j])*(uvw[2][j] + r->ron[j]);
404                if (d*0.5 < -minarad*ambacc-.001)
405                        continue;
406                /*
416                   *  Extrapolate value and compute final weight (hat function)
417                   */
418                  extambient(ct, av, r->rop, rn, uvw);
419                  d = tfunc(maxangle, sqrt(delta_r2), 0.0) *
420 <                        tfunc(ambacc, sqrt(delta_t2), 0.0);
420 >                        tfunc(qambacc, sqrt(delta_t2), 0.0);
421                  scalecolor(ct, d);
422                  addcolor(acol, ct);
423                  wsum += d;
# Line 456 | Line 465 | makeambient(           /* make a new ambient value for storage
465                                                  /* compute ambient */
466          i = doambient(acol, r, amb.weight, uvw, amb.rad, amb.gpos, amb.gdir);
467          scalecolor(acol, 1./AVGREFL);           /* undo assumed reflectance */
468 <        if (i <= 0)                             /* no Hessian => no storage */
468 >        if (i <= 0 || amb.rad[0] <= FTINY)      /* no Hessian or zero radius */
469                  return(i);
470                                                  /* store value */
471          VCOPY(amb.pos, r->rop);
# Line 529 | Line 538 | avinsert(                              /* insert ambient value in our tree */
538          at = &atrunk;
539          VCOPY(ck0, thescene.cuorg);
540          s = thescene.cusize;
541 <        while (s*(OCTSCALE/2) > av->rad[1]*ambacc) {
541 >        while (s*(OCTSCALE/2) > av->rad[1]*qambacc) {
542                  if (at->kid == NULL)
543                          if ((at->kid = newambtree()) == NULL)
544                                  error(SYSTEM, "out of memory in avinsert");

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines