ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/m_bsdf.c
(Generate patch)

Comparing ray/src/rt/m_bsdf.c (file contents):
Revision 2.71 by greg, Wed Nov 15 18:02:52 2023 UTC vs.
Revision 2.77 by greg, Fri Jun 20 18:05:30 2025 UTC

# Line 238 | Line 238 | direct_specular_OK(SCOLOR scval, FVECT ldir, double om
238   {
239          int     nsamp = 1;
240          int     scnt = 0;
241 <        FVECT   vsrc, vjit;
241 >        FVECT   vsrc;
242          double  tomega, tomega2;
243          double  tsr, sd[2];
244          SCOLOR  csmp, cdiff;
# Line 306 | Line 306 | direct_specular_OK(SCOLOR scval, FVECT ldir, double om
306                  nsamp = 4.*specjitter*ndp->pr->rweight + .5;
307                  nsamp += !nsamp;
308          }
309 <                                        /* jitter to fuzz BSDF cells */
310 <        for (i = nsamp; i--; ) {
309 >        for (i = nsamp; i--; ) {        /* jitter to fuzz BSDF cells */
310 >                FVECT   vjit;
311                  bsdf_jitter(vjit, ndp, tsr);
312                                          /* compute BSDF */
313                  ec = SDevalBSDF(&sv, vjit, vsrc, ndp->sd);
314                  if (ec)
315                          goto baderror;
316 <                if (sv.cieY - diffY <= FTINY)
317 <                        continue;       /* no specular part */
316 >                if (sv.cieY - diffY <= FTINY) {
317 >                        ++scnt;         /* still counts as 0 contribution */
318 >                        continue;
319 >                }
320                                          /* check for variable resolution */
321                  ec = SDsizeBSDF(&tomega2, vjit, vsrc, SDqueryMin, ndp->sd);
322                  if (ec)
# Line 531 | Line 533 | sample_sdcomp(BSDFDAT *ndp, SDComponent *dcp, int xmit
533                  cvt_sdcolor(sr.rcoef, &bsv);    /* use sample color */
534                  if (xmit)                       /* apply pattern on transmit */
535                          smultscolor(sr.rcoef, ndp->pr->pcol);
536 <                if (rayorigin(&sr, SPECULAR, ndp->pr, sr.rcoef) < 0) {
536 >                if (rayorigin(&sr, xmit ? TSPECULAR : RSPECULAR, ndp->pr, sr.rcoef) < 0) {
537                          if (!n & (nstarget > 1)) {
538                                  n = nstarget;   /* avoid infinitue loop */
539 <                                nstarget = nstarget*sr.rweight/minweight;
539 >                                nstarget = nstarget*sr.rweight/(minweight + 1e-20);
540                                  if (n == nstarget) break;
541                                  n = -1;         /* moved target */
542                          }
# Line 609 | Line 611 | sample_sdf(BSDFDAT *ndp, int sflags)
611                                  setscolor(unsc, b, b, b);
612                  }
613                  return(ntotal);
614 <        }
615 <        dimlist[ndims] = (int)(size_t)ndp->mp;  /* else sample specular */
616 <        ndims += 2;
614 >        }                                       /* else sample specular */
615 >        dimlist[ndims_inc()] = (int)(size_t)ndp->mp;
616 >        ndims_inc();
617          for (n = dfp->ncomp; n--; ) {           /* loop over components */
618                  dimlist[ndims-1] = n + 9438;
619                  ntotal += sample_sdcomp(ndp, &dfp->comp[n], sflags==SDsampSpT);
620          }
621 <        ndims -= 2;
621 >        dec_ndims(); dec_ndims();
622          return(ntotal);
623   }
624  
# Line 624 | Line 626 | sample_sdf(BSDFDAT *ndp, int sflags)
626   int
627   m_bsdf(OBJREC *m, RAY *r)
628   {
629 <        int     hasthick = (m->otype == MAT_BSDF);
630 <        int     hitfront;
629 >        const int       hasthick = (m->otype == MAT_BSDF);
630 >        const int       hitfront = (r->rod > 0);
631          SCOLOR  sctmp;
632          SDError ec;
633          FVECT   upvec, vtmp;
634          MFUNC   *mf;
635          BSDFDAT nd;
636 +                                                /* check backface visibility */
637 +        if (!hitfront & !backvis) {
638 +                raytrans(r);
639 +                return(1);
640 +        }
641                                                  /* check arguments */
642          if ((m->oargs.nsargs < hasthick+5) | (m->oargs.nfargs > 9) |
643                                  (m->oargs.nfargs % 3))
644                  objerror(m, USER, "bad # arguments");
638                                                /* record surface struck */
639        hitfront = (r->rod > 0);
645                                                  /* load cal file */
646          mf = hasthick   ? getfunc(m, 5, 0x1d, 1)
647                          : getfunc(m, 4, 0xe, 1) ;
# Line 647 | Line 652 | m_bsdf(OBJREC *m, RAY *r)
652                  if ((-FTINY <= nd.thick) & (nd.thick <= FTINY))
653                          nd.thick = 0;
654          }
650                                                /* check backface visibility */
651        if (!hitfront & !backvis) {
652                raytrans(r);
653                return(1);
654        }
655                                                  /* check other rays to pass */
656          if (nd.thick != 0 && (r->crtype & SHADOW ||
657                                  !(r->crtype & (SPECULAR|AMBIENT)) ||
# Line 766 | Line 766 | m_bsdf(OBJREC *m, RAY *r)
766          copyscolor(sctmp, nd.rdiff);
767          saddscolor(sctmp, nd.runsamp);
768          if (sintens(sctmp) > FTINY) {           /* ambient from reflection */
769                if (!hitfront)
770                        flipsurface(r);
769                  multambient(sctmp, r, nd.pnorm);
770                  saddscolor(r->rcol, sctmp);
773                if (!hitfront)
774                        flipsurface(r);
771          }
772          copyscolor(sctmp, nd.tdiff);
773          saddscolor(sctmp, nd.tunsamp);
774          if (sintens(sctmp) > FTINY) {           /* ambient from other side */
775                  FVECT  bnorm;
780                if (hitfront)
781                        flipsurface(r);
776                  bnorm[0] = -nd.pnorm[0];
777                  bnorm[1] = -nd.pnorm[1];
778                  bnorm[2] = -nd.pnorm[2];
# Line 790 | Line 784 | m_bsdf(OBJREC *m, RAY *r)
784                  } else
785                          multambient(sctmp, r, bnorm);
786                  saddscolor(r->rcol, sctmp);
793                if (hitfront)
794                        flipsurface(r);
787          }
788                                                  /* add direct component */
789          if ((nd.sd->tf == NULL) & (nd.sd->tb == NULL) &&

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines