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.72 by greg, Fri Apr 11 22:54:34 2014 UTC

# Line 263 | Line 263 | ambnotify(                     /* record new modifier */
263  
264   #ifdef NEWAMB
265  
266 < #define tfunc(lwr, x, upr)      (((x)-(lwr)/((upr)-(lwr)))
266 > #define tfunc(lwr, x, upr)      (((x)-(lwr))/((upr)-(lwr)))
267  
268 + static double   sumambient(COLOR acol, RAY *r, FVECT rn, int al,
269 +                                AMBTREE *at, FVECT c0, double s);
270 + static int      makeambient(COLOR acol, RAY *r, FVECT rn, int al);
271 + static void     extambient(COLOR cr, AMBVAL *ap, FVECT pv, FVECT nv,
272 +                                FVECT uvw[3]);
273  
274   void
275   multambient(            /* compute ambient component & multiply by coef. */
# Line 338 | Line 343 | dumbamb:                                       /* return global value */
343  
344  
345   double
346 < sumambient(     /* get interpolated ambient value */
346 > sumambient(             /* get interpolated ambient value */
347          COLOR  acol,
348          RAY  *r,
349          FVECT  rn,
# Line 362 | Line 367 | sumambient(    /* get interpolated ambient value */
367                  if (tracktime)
368                          av->latick = ambclock;
369                  /*
370 <                 *  Ambient level test.
370 >                 *  Ambient level test
371                   */
372                  if (av->lvl > al)       /* list sorted, so this works */
373                          break;
374                  if (av->weight < 0.9*r->rweight)
375                          continue;
376                  /*
377 <                 *  Direction test using unperturbed normal.
377 >                 *  Direction test using unperturbed normal
378                   */
379                  decodedir(uvw[2], av->ndir);
380                  d = DOT(uvw[2], r->ron);
# Line 379 | Line 384 | sumambient(    /* get interpolated ambient value */
384                  if (delta_r2 >= maxangle*maxangle)
385                          continue;
386                  /*
387 <                 *  Ambient radius test.
387 >                 *  Elliptical radii test based on Hessian
388                   */
389                  decodedir(uvw[0], av->udir);
390                  VCROSS(uvw[1], uvw[2], uvw[0]);
# Line 391 | Line 396 | sumambient(    /* get interpolated ambient value */
396                  if (delta_t2 >= ambacc*ambacc)
397                          continue;
398                  /*
399 <                 *  Ray behind test.
399 >                 *  Intersection behind test
400                   */
401                  d = 0.0;
402                  for (j = 0; j < 3; j++)
# Line 399 | Line 404 | sumambient(    /* get interpolated ambient value */
404                  if (d*0.5 < -minarad*ambacc-.001)
405                          continue;
406                  /*
407 <                 *  Convert to final weight (hat function)
407 >                 *  Extrapolate value and compute final weight (hat function)
408                   */
409 +                extambient(ct, av, r->rop, rn, uvw);
410                  d = tfunc(maxangle, sqrt(delta_r2), 0.0) *
411                          tfunc(ambacc, sqrt(delta_t2), 0.0);
406                wsum += d;
407                extambient(ct, av, uvw, r->rop, rn);
412                  scalecolor(ct, d);
413                  addcolor(acol, ct);
414 +                wsum += d;
415          }
416          if (at->kid == NULL)
417                  return(wsum);
# Line 439 | Line 444 | makeambient(           /* make a new ambient value for storage
444   )
445   {
446          AMBVAL  amb;
447 <        FVECT   uv[2];
447 >        FVECT   uvw[3];
448          int     i;
449  
450          amb.weight = 1.0;                       /* compute weight */
# Line 449 | Line 454 | makeambient(           /* make a new ambient value for storage
454                  amb.weight = 1.25*r->rweight;
455          setcolor(acol, AVGREFL, AVGREFL, AVGREFL);
456                                                  /* compute ambient */
457 <        if (!doambient(acol, r, amb.weight, uv, amb.rad, amb.gpos, amb.gdir)) {
457 >        if (!doambient(acol, r, amb.weight, uvw, amb.rad, amb.gpos, amb.gdir)) {
458                  setcolor(acol, 0.0, 0.0, 0.0);
459                  return(0);
460          }
# Line 457 | Line 462 | makeambient(           /* make a new ambient value for storage
462                                                  /* store value */
463          VCOPY(amb.pos, r->rop);
464          amb.ndir = encodedir(r->ron);
465 <        amb.udir = encodedir(uv[0]);
465 >        amb.udir = encodedir(uvw[0]);
466          amb.lvl = al;
467          copycolor(amb.val, acol);
468                                                  /* insert into tree */
469          avsave(&amb);                           /* and save to file */
470 <        if (rn != r->ron)
471 <                extambient(acol, &amb, r->rop, rn);     /* texture */
470 >        if (rn != r->ron) {                     /* texture */
471 >                VCOPY(uvw[2], r->ron);
472 >                extambient(acol, &amb, r->rop, rn, uvw);
473 >        }
474          return(1);
475   }
476  
# Line 472 | Line 479 | void
479   extambient(             /* extrapolate value at pv, nv */
480          COLOR  cr,
481          AMBVAL   *ap,
475        FVECT  uvw[3],
482          FVECT  pv,
483 <        FVECT  nv
483 >        FVECT  nv,
484 >        FVECT  uvw[3]
485   )
486   {
487 <        FVECT  v1;
488 <        int  i;
489 <        double  d = 1.0;                /* zeroeth order */
487 >        static FVECT    my_uvw[3];
488 >        FVECT           v1;
489 >        int             i;
490 >        double          d = 1.0;        /* zeroeth order */
491  
492 +        if (uvw == NULL) {              /* need local coordinates? */
493 +                decodedir(my_uvw[2], ap->ndir);
494 +                decodedir(my_uvw[0], ap->udir);
495 +                VCROSS(my_uvw[1], my_uvw[2], my_uvw[0]);
496 +                uvw = my_uvw;
497 +        }
498          for (i = 3; i--; )              /* gradient due to translation */
499                  d += (pv[i] - ap->pos[i]) *
500                          (ap->gpos[0]*uvw[0][i] + ap->gpos[1]*uvw[1][i]);
# Line 541 | Line 555 | avinsert(                              /* insert ambient value in our tree */
555  
556   #else /* ! NEWAMB */
557  
558 + static double   sumambient(COLOR acol, RAY *r, FVECT rn, int al,
559 +                                AMBTREE *at, FVECT c0, double s);
560 + static double   makeambient(COLOR acol, RAY *r, FVECT rn, int al);
561 + static void     extambient(COLOR cr, AMBVAL *ap, FVECT pv, FVECT nv);
562  
563 +
564   void
565   multambient(            /* compute ambient component & multiply by coef. */
566          COLOR  aval,
# Line 612 | Line 631 | dumbamb:                                       /* return global value */
631   }
632  
633  
634 < double
634 > static double
635   sumambient(     /* get interpolated ambient value */
636          COLOR  acol,
637          RAY  *r,
# Line 723 | Line 742 | sumambient(    /* get interpolated ambient value */
742   }
743  
744  
745 < double
745 > static double
746   makeambient(            /* make a new ambient value for storage */
747          COLOR  acol,
748          RAY  *r,
# Line 763 | Line 782 | makeambient(           /* make a new ambient value for storage
782   }
783  
784  
785 < void
785 > static void
786   extambient(             /* extrapolate value at pv, nv */
787          COLOR  cr,
788          AMBVAL   *ap,

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines