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.122 by greg, Wed Jan 31 04:03:03 2024 UTC vs.
Revision 2.123 by greg, Fri Apr 5 01:10:26 2024 UTC

# Line 269 | Line 269 | multambient(           /* compute ambient component & multiply
269                          ambincl != inset(ambset, r->ro->omod))
270                  goto dumbamb;
271  
272 <        if (ambacc <= FTINY) {                  /* no ambient storage */
273 <                FVECT   uvd[2];
272 >        if (ambacc <= FTINY) {                  /* no ambient storage? */
273 >                double  rdot = DOT(nrm,r->ron);
274 >                int     sgn = 1 - 2*(rdot < 0);
275                  float   dgrad[2], *dgp = NULL;
276 +                FVECT   uvd[2];
277  
278 <                if (nrm != r->ron && DOT(nrm,r->ron) < 0.9999)
278 >                if (sgn*rdot < 0.9999)
279                          dgp = dgrad;            /* compute rotational grad. */
280                  copyscolor(acol, aval);
281                  rdepth++;
282 <                ok = doambient(acol, r, r->rweight,
282 >                ok = doambient(acol, r, r->rweight*sgn,
283                                  uvd, NULL, NULL, dgp, NULL);
284                  rdepth--;
285                  if (!ok)
# Line 287 | Line 289 | multambient(           /* compute ambient component & multiply
289                          VCROSS(v1, r->ron, nrm);
290                          d = 1.0;
291                          for (i = 3; i--; )
292 <                                d += v1[i] * (dgp[0]*uvd[0][i] + dgp[1]*uvd[1][i]);
292 >                                d += sgn*v1[i] * (dgp[0]*uvd[0][i] + dgp[1]*uvd[1][i]);
293                          if (d >= 0.05)
294                                  scalescolor(acol, d);
295                  }
# Line 404 | Line 406 | sumambient(            /* get interpolated ambient value */
406   )
407   {                       /* initial limit is 10 degrees plus ambacc radians */
408          const double    minangle = 10.0 * PI/180.;
409 +        const int       sgn = 1 - 2*(DOT(r->ron,rn) < 0);
410          double          maxangle = minangle + ambacc;
411          double          wsum = 0.0;
412          FVECT           ck0;
# Line 448 | Line 451 | sumambient(            /* get interpolated ambient value */
451                   *  Direction test using unperturbed normal
452                   */
453                  decodedir(uvw[2], av->ndir);
454 <                d = DOT(uvw[2], r->ron);
454 >                d = sgn * DOT(uvw[2], r->ron);
455                  if (d <= 0.0)           /* >= 90 degrees */
456                          continue;
457                  delta_r2 = 2.0 - 2.0*d; /* approx. radians^2 */
# Line 504 | Line 507 | makeambient(           /* make a new ambient value for storage
507          int  al
508   )
509   {
510 +        int     sgn = 1 - 2*(DOT(r->ron,rn) < 0);
511          AMBVAL  amb;
512          FVECT   uvw[3];
513          int     i;
# Line 515 | Line 519 | makeambient(           /* make a new ambient value for storage
519                  amb.weight = 1.25*r->rweight;
520          setscolor(acol, AVGREFL, AVGREFL, AVGREFL);
521                                                  /* compute ambient */
522 <        i = doambient(acol, r, amb.weight,
522 >        i = doambient(acol, r, amb.weight*sgn,
523                          uvw, amb.rad, amb.gpos, amb.gdir, &amb.corral);
524          scalescolor(acol, 1./AVGREFL);          /* undo assumed reflectance */
525          if (i <= 0 || amb.rad[0] <= FTINY)      /* no Hessian or zero radius */
526                  return(i);
527 +        uvw[2][0] = sgn*r->ron[0];              /* orient unperturbed normal */
528 +        uvw[2][1] = sgn*r->ron[1];
529 +        uvw[2][2] = sgn*r->ron[2];
530                                                  /* store value */
531          VCOPY(amb.pos, r->rop);
532 <        amb.ndir = encodedir(r->ron);
532 >        amb.ndir = encodedir(uvw[2]);
533          amb.udir = encodedir(uvw[0]);
534          amb.lvl = al;
535          copyscolor(amb.val, acol);
536 <                                                /* insert into tree */
537 <        avsave(&amb);                           /* and save to file */
531 <        if (rn != r->ron) {                     /* texture */
532 <                VCOPY(uvw[2], r->ron);
536 >        avsave(&amb);                           /* insert and save to file */
537 >        if (DOT(uvw[2],rn) < 0.9999)            /* texture? */
538                  extambient(acol, &amb, r->rop, rn, uvw);
534        }
539          return(1);
540   }
541  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines