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.118 by greg, Wed Nov 15 18:02:52 2023 UTC vs.
Revision 2.124 by greg, Wed Nov 6 20:16:58 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 */
458                  if (delta_r2 >= maxangle*maxangle)
459                          continue;
460                  /*
461 <                 *  Modified ray behind test
461 >                 *  Original ray behind test
462                   */
463 <                VSUB(ck0, r->rop, av->pos);
464 <                d = DOT(ck0, uvw[2]);
463 >                d = 0.0;
464 >                for (j = 0; j < 3; j++)
465 >                        d += (r->rop[j] - av->pos[j])*(r->ron[j] + uvw[2][j]);
466 >                d *= 0.5;
467                  if (d < -minarad*ambacc)
468                          continue;
469 <                d /= av->rad[0];
470 <                delta_t2 = d*d;
466 <                if (delta_t2 >= ambacc*ambacc)
469 >                /* Pre-empt following test if we can */
470 >                if (fabs(d) >= av->rad[0]*ambacc)
471                          continue;
472                  /*
473                   *  Elliptical radii test based on Hessian
# Line 504 | Line 508 | makeambient(           /* make a new ambient value for storage
508          int  al
509   )
510   {
511 +        int     sgn = 1 - 2*(DOT(r->ron,rn) < 0);
512          AMBVAL  amb;
513          FVECT   uvw[3];
514          int     i;
# Line 515 | Line 520 | makeambient(           /* make a new ambient value for storage
520                  amb.weight = 1.25*r->rweight;
521          setscolor(acol, AVGREFL, AVGREFL, AVGREFL);
522                                                  /* compute ambient */
523 <        i = doambient(acol, r, amb.weight,
523 >        i = doambient(acol, r, amb.weight*sgn,
524                          uvw, amb.rad, amb.gpos, amb.gdir, &amb.corral);
525          scalescolor(acol, 1./AVGREFL);          /* undo assumed reflectance */
526          if (i <= 0 || amb.rad[0] <= FTINY)      /* no Hessian or zero radius */
527                  return(i);
528 +        uvw[2][0] = sgn*r->ron[0];              /* orient unperturbed normal */
529 +        uvw[2][1] = sgn*r->ron[1];
530 +        uvw[2][2] = sgn*r->ron[2];
531                                                  /* store value */
532          VCOPY(amb.pos, r->rop);
533 <        amb.ndir = encodedir(r->ron);
533 >        amb.ndir = encodedir(uvw[2]);
534          amb.udir = encodedir(uvw[0]);
535          amb.lvl = al;
536          copyscolor(amb.val, acol);
537 <                                                /* insert into tree */
538 <        avsave(&amb);                           /* and save to file */
531 <        if (rn != r->ron) {                     /* texture */
532 <                VCOPY(uvw[2], r->ron);
537 >        avsave(&amb);                           /* insert and save to file */
538 >        if (DOT(uvw[2],rn) < 0.9999)            /* texture? */
539                  extambient(acol, &amb, r->rop, rn, uvw);
534        }
540          return(1);
541   }
542  
# Line 634 | Line 639 | initambfile(           /* initialize ambient file */
639          if (mybuf == NULL)
640                  mybuf = (char *)bmalloc(BUFSIZ+8);
641          setbuf(ambfp, mybuf);
642 + retry:
643          if (cre8) {                     /* new file */
644                  newheader("RADIANCE", ambfp);
645                  fprintf(ambfp, "%s -av %g %g %g -aw %d -ab %d -aa %g ",
# Line 646 | Line 652 | initambfile(           /* initialize ambient file */
652                                  srcsizerat, shadthresh, shadcert);
653                  fprintf(ambfp, "-ss %g -st %g -lr %d -lw %g ", specjitter,
654                                  specthresh, maxdepth, minweight);
655 <                fprintf(ambfp, "-cw %f %f -cs %d ", WLPART[3], WLPART[0], NCSAMP);
655 >                fprintf(ambfp, "-cw %g %g -cs %d ", WLPART[3], WLPART[0], NCSAMP);
656                  if (octname != NULL)
657                          fputs(octname, ambfp);
658 <                fputc('\n', ambfp);
658 >                fputc('\n', ambfp);     /* end of command line, not header! */
659                  fprintf(ambfp, "SOFTWARE= %s\n", VersionID);
660                  fputnow(ambfp);
661 +                AMB_CNDX = CNDX;        /* use current spectral sampling */
662 +                AMB_WLPART = WLPART;
663                  fputwlsplit(WLPART, ambfp);
664                  fputncomp(NCSAMP, ambfp);
665                  fputformat(AMBFMT, ambfp);
666                  fputc('\n', ambfp);
667                  putambmagic(ambfp);
668 <        } else if (getheader(ambfp, amb_headline, NULL) < 0 || !hasambmagic(ambfp))
668 >        } else if (getheader(ambfp, amb_headline, NULL) < 0 || !hasambmagic(ambfp)) {
669 > #ifndef  F_SETLKW
670 >                static int      ntries = 3;
671 >                if (--ntries > 0 && ftell(ambfp) == 0) {
672 >                        clearerr(ambfp);
673 >                        sleep(2);
674 >                        goto retry;
675 >                }
676 > #endif
677                  error(USER, "bad/incompatible ambient file");
678 <
678 >        }
679          if ((AMB_CNDX != CNDX) | (AMB_WLPART != WLPART)) {
680                  if (setspectrsamp(AMB_CNDX, AMB_WLPART) < 0)
681                          error(USER, "bad wavelength sampling in ambient file");

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines