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.71 by greg, Fri Apr 11 20:31:37 2014 UTC vs.
Revision 2.74 by greg, Sat Apr 19 02:39:44 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 263 | Line 268 | ambnotify(                     /* record new modifier */
268  
269   #ifdef NEWAMB
270  
271 < #define tfunc(lwr, x, upr)      (((x)-(lwr)/((upr)-(lwr)))
271 > #define tfunc(lwr, x, upr)      (((x)-(lwr))/((upr)-(lwr)))
272  
273 + static double   sumambient(COLOR acol, RAY *r, FVECT rn, int al,
274 +                                AMBTREE *at, FVECT c0, double s);
275 + static int      makeambient(COLOR acol, RAY *r, FVECT rn, int al);
276 + static void     extambient(COLOR cr, AMBVAL *ap, FVECT pv, FVECT nv,
277 +                                FVECT uvw[3]);
278  
279   void
280   multambient(            /* compute ambient component & multiply by coef. */
# Line 315 | Line 325 | multambient(           /* compute ambient component & multiply
325          ok = makeambient(acol, r, nrm, rdepth-1);
326          rdepth--;
327          if (ok) {
328 <                multcolor(aval, acol);          /* got new value */
328 >                multcolor(aval, acol);          /* computed new value */
329                  return;
330          }
331   dumbamb:                                        /* return global value */
# Line 338 | Line 348 | dumbamb:                                       /* return global value */
348  
349  
350   double
351 < sumambient(     /* get interpolated ambient value */
351 > sumambient(             /* get interpolated ambient value */
352          COLOR  acol,
353          RAY  *r,
354          FVECT  rn,
# Line 362 | Line 372 | sumambient(    /* get interpolated ambient value */
372                  if (tracktime)
373                          av->latick = ambclock;
374                  /*
375 <                 *  Ambient level test.
375 >                 *  Ambient level test
376                   */
377                  if (av->lvl > al)       /* list sorted, so this works */
378                          break;
379                  if (av->weight < 0.9*r->rweight)
380                          continue;
381                  /*
382 <                 *  Direction test using unperturbed normal.
382 >                 *  Direction test using unperturbed normal
383                   */
384                  decodedir(uvw[2], av->ndir);
385                  d = DOT(uvw[2], r->ron);
# Line 379 | Line 389 | sumambient(    /* get interpolated ambient value */
389                  if (delta_r2 >= maxangle*maxangle)
390                          continue;
391                  /*
392 <                 *  Ambient radius test.
392 >                 *  Elliptical radii test based on Hessian
393                   */
394                  decodedir(uvw[0], av->udir);
395                  VCROSS(uvw[1], uvw[2], uvw[0]);
# Line 391 | Line 401 | sumambient(    /* get interpolated ambient value */
401                  if (delta_t2 >= ambacc*ambacc)
402                          continue;
403                  /*
404 <                 *  Ray behind test.
404 >                 *  Intersection behind test
405                   */
406                  d = 0.0;
407                  for (j = 0; j < 3; j++)
# Line 399 | Line 409 | sumambient(    /* get interpolated ambient value */
409                  if (d*0.5 < -minarad*ambacc-.001)
410                          continue;
411                  /*
412 <                 *  Convert to final weight (hat function)
412 >                 *  Extrapolate value and compute final weight (hat function)
413                   */
414 +                extambient(ct, av, r->rop, rn, uvw);
415                  d = tfunc(maxangle, sqrt(delta_r2), 0.0) *
416                          tfunc(ambacc, sqrt(delta_t2), 0.0);
406                wsum += d;
407                extambient(ct, av, uvw, r->rop, rn);
417                  scalecolor(ct, d);
418                  addcolor(acol, ct);
419 +                wsum += d;
420          }
421          if (at->kid == NULL)
422                  return(wsum);
# Line 439 | Line 449 | makeambient(           /* make a new ambient value for storage
449   )
450   {
451          AMBVAL  amb;
452 <        FVECT   uv[2];
452 >        FVECT   uvw[3];
453          int     i;
454  
455          amb.weight = 1.0;                       /* compute weight */
# Line 449 | Line 459 | makeambient(           /* make a new ambient value for storage
459                  amb.weight = 1.25*r->rweight;
460          setcolor(acol, AVGREFL, AVGREFL, AVGREFL);
461                                                  /* compute ambient */
462 <        if (!doambient(acol, r, amb.weight, uv, amb.rad, amb.gpos, amb.gdir)) {
453 <                setcolor(acol, 0.0, 0.0, 0.0);
454 <                return(0);
455 <        }
462 >        i = doambient(acol, r, amb.weight, uvw, amb.rad, amb.gpos, amb.gdir);
463          scalecolor(acol, 1./AVGREFL);           /* undo assumed reflectance */
464 +        if (i <= 0)                             /* no Hessian => no storage */
465 +                return(i);
466                                                  /* store value */
467          VCOPY(amb.pos, r->rop);
468          amb.ndir = encodedir(r->ron);
469 <        amb.udir = encodedir(uv[0]);
469 >        amb.udir = encodedir(uvw[0]);
470          amb.lvl = al;
471          copycolor(amb.val, acol);
472                                                  /* insert into tree */
473          avsave(&amb);                           /* and save to file */
474 <        if (rn != r->ron)
475 <                extambient(acol, &amb, r->rop, rn);     /* texture */
474 >        if (rn != r->ron) {                     /* texture */
475 >                VCOPY(uvw[2], r->ron);
476 >                extambient(acol, &amb, r->rop, rn, uvw);
477 >        }
478          return(1);
479   }
480  
# Line 472 | Line 483 | void
483   extambient(             /* extrapolate value at pv, nv */
484          COLOR  cr,
485          AMBVAL   *ap,
475        FVECT  uvw[3],
486          FVECT  pv,
487 <        FVECT  nv
487 >        FVECT  nv,
488 >        FVECT  uvw[3]
489   )
490   {
491 <        FVECT  v1;
492 <        int  i;
493 <        double  d = 1.0;                /* zeroeth order */
491 >        static FVECT    my_uvw[3];
492 >        FVECT           v1;
493 >        int             i;
494 >        double          d = 1.0;        /* zeroeth order */
495  
496 +        if (uvw == NULL) {              /* need local coordinates? */
497 +                decodedir(my_uvw[2], ap->ndir);
498 +                decodedir(my_uvw[0], ap->udir);
499 +                VCROSS(my_uvw[1], my_uvw[2], my_uvw[0]);
500 +                uvw = my_uvw;
501 +        }
502          for (i = 3; i--; )              /* gradient due to translation */
503                  d += (pv[i] - ap->pos[i]) *
504                          (ap->gpos[0]*uvw[0][i] + ap->gpos[1]*uvw[1][i]);
# Line 516 | Line 534 | avinsert(                              /* insert ambient value in our tree */
534          at = &atrunk;
535          VCOPY(ck0, thescene.cuorg);
536          s = thescene.cusize;
537 <        while (s*(OCTSCALE/2) > av->rad[1]*ambacc) {
537 >        while (s*(OCTSCALE/2) > av->rad[1]*qambacc) {
538                  if (at->kid == NULL)
539                          if ((at->kid = newambtree()) == NULL)
540                                  error(SYSTEM, "out of memory in avinsert");
# Line 541 | Line 559 | avinsert(                              /* insert ambient value in our tree */
559  
560   #else /* ! NEWAMB */
561  
562 + static double   sumambient(COLOR acol, RAY *r, FVECT rn, int al,
563 +                                AMBTREE *at, FVECT c0, double s);
564 + static double   makeambient(COLOR acol, RAY *r, FVECT rn, int al);
565 + static void     extambient(COLOR cr, AMBVAL *ap, FVECT pv, FVECT nv);
566  
567 +
568   void
569   multambient(            /* compute ambient component & multiply by coef. */
570          COLOR  aval,
# Line 612 | Line 635 | dumbamb:                                       /* return global value */
635   }
636  
637  
638 < double
638 > static double
639   sumambient(     /* get interpolated ambient value */
640          COLOR  acol,
641          RAY  *r,
# Line 723 | Line 746 | sumambient(    /* get interpolated ambient value */
746   }
747  
748  
749 < double
749 > static double
750   makeambient(            /* make a new ambient value for storage */
751          COLOR  acol,
752          RAY  *r,
# Line 763 | Line 786 | makeambient(           /* make a new ambient value for storage
786   }
787  
788  
789 < void
789 > static void
790   extambient(             /* extrapolate value at pv, nv */
791          COLOR  cr,
792          AMBVAL   *ap,

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines