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

Comparing ray/src/common/bsdf.c (file contents):
Revision 2.58 by greg, Thu May 14 19:20:13 2020 UTC vs.
Revision 2.61 by greg, Tue Dec 7 23:49:50 2021 UTC

# Line 330 | Line 330 | SDclipName(char *res, const char *fname)
330          for (cp = fname; *cp; cp++)
331                  if (*cp == '.')
332                          dot = cp;
333 +                else if (*cp == '/')
334 +                        dot = NULL;
335          if ((dot == NULL) | (dot < fname+2))
336                  dot = cp;
337          if (dot - fname >= SDnameLn)
# Line 381 | Line 383 | SDfreeBSDF(SDData *sd)
383          sd->rLambFront.spec.flags = 0;
384          sd->rLambBack.cieY = .0;
385          sd->rLambBack.spec.flags = 0;
386 <        sd->tLamb.cieY = .0;
387 <        sd->tLamb.spec.flags = 0;
386 >        sd->tLambFront.cieY = .0;
387 >        sd->tLambFront.spec.flags = 0;
388 >        sd->tLambBack.cieY = .0;
389 >        sd->tLambBack.spec.flags = 0;
390   }
391  
392   /* Find writeable BSDF by name, or allocate new cache entry if absent */
# Line 507 | Line 511 | SDsampComponent(SDValue *sv, FVECT ioVec, double randX
511          if (ec)
512                  return ec;
513                                          /* get BSDF color */
514 <        n = (*sdc->func->getBSDFs)(coef, ioVec, inVec, sdc);
514 >        n = (*sdc->func->getBSDFs)(coef, inVec, ioVec, sdc);
515          if (n <= 0) {
516                  strcpy(SDerrorDetail, "BSDF sample value error");
517                  return SDEinternal;
# Line 556 | Line 560 | SDmultiSamp(double t[], int n, double randX)
560  
561   /* Generate diffuse hemispherical sample */
562   static void
563 < SDdiffuseSamp(FVECT outVec, int outFront, double randX)
563 > SDdiffuseSamp(FVECT ioVec, int outFront, double randX)
564   {
565                                          /* convert to position on hemisphere */
566 <        SDmultiSamp(outVec, 2, randX);
567 <        SDsquare2disk(outVec, outVec[0], outVec[1]);
568 <        outVec[2] = 1. - outVec[0]*outVec[0] - outVec[1]*outVec[1];
569 <        outVec[2] = sqrt(outVec[2]*(outVec[2]>0));
566 >        SDmultiSamp(ioVec, 2, randX);
567 >        SDsquare2disk(ioVec, ioVec[0], ioVec[1]);
568 >        ioVec[2] = 1. - ioVec[0]*ioVec[0] - ioVec[1]*ioVec[1];
569 >        ioVec[2] = sqrt(ioVec[2]*(ioVec[2]>0));
570          if (!outFront)                  /* going out back? */
571 <                outVec[2] = -outVec[2];
571 >                ioVec[2] = -ioVec[2];
572   }
573  
574   /* Query projected solid angle coverage for non-diffuse BSDF direction */
# Line 629 | Line 633 | SDsizeBSDF(double *projSA, const FVECT v1, const RREAL
633  
634   /* Return BSDF for the given incident and scattered ray vectors */
635   SDError
636 < SDevalBSDF(SDValue *sv, const FVECT outVec, const FVECT inVec, const SDData *sd)
636 > SDevalBSDF(SDValue *sv, const FVECT inVec, const FVECT outVec, const SDData *sd)
637   {
638          int             inFront, outFront;
639          SDSpectralDF    *sdf;
# Line 649 | Line 653 | SDevalBSDF(SDValue *sv, const FVECT outVec, const FVEC
653                  *sv = sd->rLambBack;
654                  sdf = sd->rb;
655          } else if (inFront) {
656 <                *sv = sd->tLamb;
656 >                *sv = sd->tLambFront;
657                  sdf = (sd->tf != NULL) ? sd->tf : sd->tb;
658          } else /* outFront & !inFront */ {
659 <                *sv = sd->tLamb;
659 >                *sv = sd->tLambBack;
660                  sdf = (sd->tb != NULL) ? sd->tb : sd->tf;
661          }
662          sv->cieY *= 1./M_PI;
663                                          /* add non-diffuse components */
664          i = (sdf != NULL) ? sdf->ncomp : 0;
665          while (i-- > 0) {
666 <                nch = (*sdf->comp[i].func->getBSDFs)(coef, outVec, inVec,
666 >                nch = (*sdf->comp[i].func->getBSDFs)(coef, inVec, outVec,
667                                                          &sdf->comp[i]);
668                  while (nch-- > 0) {
669                          c_cmix(&sv->spec, sv->cieY, &sv->spec,
# Line 695 | Line 699 | SDdirectHemi(const FVECT inVec, int sflags, const SDDa
699          if ((sflags & SDsampDf+SDsampR) != SDsampDf+SDsampR)
700                  hsum = .0;
701          if ((sflags & SDsampDf+SDsampT) == SDsampDf+SDsampT)
702 <                hsum += sd->tLamb.cieY;
702 >                hsum += (inVec[2] > 0) ?
703 >                                sd->tLambFront.cieY : sd->tLambBack.cieY;
704                                          /* gather non-diffuse components */
705          i = (((sflags & SDsampSp+SDsampR) == SDsampSp+SDsampR) &
706                          (rdf != NULL)) ? rdf->ncomp : 0;
# Line 748 | Line 753 | SDsampBSDF(SDValue *sv, FVECT ioVec, double randX, int
753                  sv->cieY = .0;
754          rdiff = sv->cieY;
755          if ((sflags & SDsampDf+SDsampT) == SDsampDf+SDsampT)
756 <                sv->cieY += sd->tLamb.cieY;
756 >                sv->cieY += inFront ? sd->tLambFront.cieY : sd->tLambBack.cieY;
757                                          /* gather non-diffuse components */
758          i = nr = (((sflags & SDsampSp+SDsampR) == SDsampSp+SDsampR) &
759                          (rdf != NULL)) ? rdf->ncomp : 0;
# Line 784 | Line 789 | SDsampBSDF(SDValue *sv, FVECT ioVec, double randX, int
789          randX -= rdiff;
790                                          /* diffuse transmission? */
791          if ((sflags & SDsampDf+SDsampT) == SDsampDf+SDsampT) {
792 <                if (randX < sd->tLamb.cieY) {
793 <                        sv->spec = sd->tLamb.spec;
794 <                        SDdiffuseSamp(ioVec, !inFront, randX/sd->tLamb.cieY);
792 >                const SDValue   *sdt = inFront ? &sd->tLambFront : &sd->tLambBack;
793 >                if (randX < sdt->cieY) {
794 >                        sv->spec = sdt->spec;
795 >                        SDdiffuseSamp(ioVec, !inFront, randX/sdt->cieY);
796                          goto done;
797                  }
798 <                randX -= sd->tLamb.cieY;
798 >                randX -= sdt->cieY;
799          }
800                                          /* else one of cumulative dist. */
801          for (i = 0; i < n && randX >= cdarr[i]->cTotal; i++)
# Line 802 | Line 808 | SDsampBSDF(SDValue *sv, FVECT ioVec, double randX, int
808          if (ec)
809                  return ec;
810                                          /* compute color */
811 <        j = (*sdc->func->getBSDFs)(coef, ioVec, inVec, sdc);
811 >        j = (*sdc->func->getBSDFs)(coef, inVec, ioVec, sdc);
812          if (j <= 0) {
813                  sprintf(SDerrorDetail, "BSDF \"%s\" sampling value error",
814                                  sd->name);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines