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.73 by greg, Wed Apr 16 20:32:00 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 315 | Line 320 | multambient(           /* compute ambient component & multiply
320          ok = makeambient(acol, r, nrm, rdepth-1);
321          rdepth--;
322          if (ok) {
323 <                multcolor(aval, acol);          /* got new value */
323 >                multcolor(aval, acol);          /* computed new value */
324                  return;
325          }
326   dumbamb:                                        /* return global value */
# 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)) {
453 <                setcolor(acol, 0.0, 0.0, 0.0);
454 <                return(0);
455 <        }
457 >        i = doambient(acol, r, amb.weight, uvw, amb.rad, amb.gpos, amb.gdir);
458          scalecolor(acol, 1./AVGREFL);           /* undo assumed reflectance */
459 +        if (i <= 0)                             /* no Hessian => no storage */
460 +                return(i);
461                                                  /* store value */
462          VCOPY(amb.pos, r->rop);
463          amb.ndir = encodedir(r->ron);
464 <        amb.udir = encodedir(uv[0]);
464 >        amb.udir = encodedir(uvw[0]);
465          amb.lvl = al;
466          copycolor(amb.val, acol);
467                                                  /* insert into tree */
468          avsave(&amb);                           /* and save to file */
469 <        if (rn != r->ron)
470 <                extambient(acol, &amb, r->rop, rn);     /* texture */
469 >        if (rn != r->ron) {                     /* texture */
470 >                VCOPY(uvw[2], r->ron);
471 >                extambient(acol, &amb, r->rop, rn, uvw);
472 >        }
473          return(1);
474   }
475  
# Line 472 | Line 478 | void
478   extambient(             /* extrapolate value at pv, nv */
479          COLOR  cr,
480          AMBVAL   *ap,
475        FVECT  uvw[3],
481          FVECT  pv,
482 <        FVECT  nv
482 >        FVECT  nv,
483 >        FVECT  uvw[3]
484   )
485   {
486 <        FVECT  v1;
487 <        int  i;
488 <        double  d = 1.0;                /* zeroeth order */
486 >        static FVECT    my_uvw[3];
487 >        FVECT           v1;
488 >        int             i;
489 >        double          d = 1.0;        /* zeroeth order */
490  
491 +        if (uvw == NULL) {              /* need local coordinates? */
492 +                decodedir(my_uvw[2], ap->ndir);
493 +                decodedir(my_uvw[0], ap->udir);
494 +                VCROSS(my_uvw[1], my_uvw[2], my_uvw[0]);
495 +                uvw = my_uvw;
496 +        }
497          for (i = 3; i--; )              /* gradient due to translation */
498                  d += (pv[i] - ap->pos[i]) *
499                          (ap->gpos[0]*uvw[0][i] + ap->gpos[1]*uvw[1][i]);
# Line 541 | Line 554 | avinsert(                              /* insert ambient value in our tree */
554  
555   #else /* ! NEWAMB */
556  
557 + static double   sumambient(COLOR acol, RAY *r, FVECT rn, int al,
558 +                                AMBTREE *at, FVECT c0, double s);
559 + static double   makeambient(COLOR acol, RAY *r, FVECT rn, int al);
560 + static void     extambient(COLOR cr, AMBVAL *ap, FVECT pv, FVECT nv);
561  
562 +
563   void
564   multambient(            /* compute ambient component & multiply by coef. */
565          COLOR  aval,
# Line 612 | Line 630 | dumbamb:                                       /* return global value */
630   }
631  
632  
633 < double
633 > static double
634   sumambient(     /* get interpolated ambient value */
635          COLOR  acol,
636          RAY  *r,
# Line 723 | Line 741 | sumambient(    /* get interpolated ambient value */
741   }
742  
743  
744 < double
744 > static double
745   makeambient(            /* make a new ambient value for storage */
746          COLOR  acol,
747          RAY  *r,
# Line 763 | Line 781 | makeambient(           /* make a new ambient value for storage
781   }
782  
783  
784 < void
784 > static void
785   extambient(             /* extrapolate value at pv, nv */
786          COLOR  cr,
787          AMBVAL   *ap,

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines