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.53 by greg, Thu Feb 2 04:46:38 2017 UTC vs.
Revision 2.59 by greg, Sat Mar 27 17:50:18 2021 UTC

# Line 47 | Line 47 | const SDCDst           SDemptyCD;
47   /* Cache of loaded BSDFs */
48   struct SDCache_s        *SDcacheList = NULL;
49  
50 < /* Retain BSDFs in cache list */
50 > /* Retain BSDFs in cache list? */
51   int                     SDretainSet = SDretainNone;
52  
53 + /* Maximum cache size for any given BSDF? */
54 + unsigned long           SDmaxCache = 0;         /* 0 == unlimited */
55 +
56   /* Report any error to the indicated stream */
57   SDError
58   SDreportError(SDError ec, FILE *fp)
# Line 378 | Line 381 | SDfreeBSDF(SDData *sd)
381          sd->rLambFront.spec.flags = 0;
382          sd->rLambBack.cieY = .0;
383          sd->rLambBack.spec.flags = 0;
384 <        sd->tLamb.cieY = .0;
385 <        sd->tLamb.spec.flags = 0;
384 >        sd->tLambFront.cieY = .0;
385 >        sd->tLambFront.spec.flags = 0;
386 >        sd->tLambBack.cieY = .0;
387 >        sd->tLambBack.spec.flags = 0;
388   }
389  
390   /* Find writeable BSDF by name, or allocate new cache entry if absent */
# Line 515 | Line 520 | SDsampComponent(SDValue *sv, FVECT ioVec, double randX
520                  c_cmix(&sv->spec, d, &sv->spec, coef[n], &sdc->cspec[n]);
521                  d += coef[n];
522          }
523 <                                        /* make sure everything is set */
519 <        c_ccvt(&sv->spec, C_CSXY+C_CSSPEC);
523 >        c_ccvt(&sv->spec, C_CSXY);      /* make sure (x,y) is set */
524          return SDEnone;
525   }
526  
# Line 647 | Line 651 | SDevalBSDF(SDValue *sv, const FVECT outVec, const FVEC
651                  *sv = sd->rLambBack;
652                  sdf = sd->rb;
653          } else if (inFront) {
654 <                *sv = sd->tLamb;
654 >                *sv = sd->tLambFront;
655                  sdf = (sd->tf != NULL) ? sd->tf : sd->tb;
656 <        } else /* inBack */ {
657 <                *sv = sd->tLamb;
656 >        } else /* outFront & !inFront */ {
657 >                *sv = sd->tLambBack;
658                  sdf = (sd->tb != NULL) ? sd->tb : sd->tf;
659          }
660          sv->cieY *= 1./M_PI;
# Line 665 | Line 669 | SDevalBSDF(SDValue *sv, const FVECT outVec, const FVEC
669                          sv->cieY += coef[nch];
670                  }
671          }
672 <                                        /* make sure everything is set */
669 <        c_ccvt(&sv->spec, C_CSXY+C_CSSPEC);
672 >        c_ccvt(&sv->spec, C_CSXY);      /* make sure (x,y) is set */
673          return SDEnone;
674   }
675  
# Line 694 | Line 697 | SDdirectHemi(const FVECT inVec, int sflags, const SDDa
697          if ((sflags & SDsampDf+SDsampR) != SDsampDf+SDsampR)
698                  hsum = .0;
699          if ((sflags & SDsampDf+SDsampT) == SDsampDf+SDsampT)
700 <                hsum += sd->tLamb.cieY;
700 >                hsum += (inVec[2] > 0) ?
701 >                                sd->tLambFront.cieY : sd->tLambBack.cieY;
702                                          /* gather non-diffuse components */
703          i = (((sflags & SDsampSp+SDsampR) == SDsampSp+SDsampR) &
704                          (rdf != NULL)) ? rdf->ncomp : 0;
# Line 747 | Line 751 | SDsampBSDF(SDValue *sv, FVECT ioVec, double randX, int
751                  sv->cieY = .0;
752          rdiff = sv->cieY;
753          if ((sflags & SDsampDf+SDsampT) == SDsampDf+SDsampT)
754 <                sv->cieY += sd->tLamb.cieY;
754 >                sv->cieY += inFront ? sd->tLambFront.cieY : sd->tLambBack.cieY;
755                                          /* gather non-diffuse components */
756          i = nr = (((sflags & SDsampSp+SDsampR) == SDsampSp+SDsampR) &
757                          (rdf != NULL)) ? rdf->ncomp : 0;
# Line 783 | Line 787 | SDsampBSDF(SDValue *sv, FVECT ioVec, double randX, int
787          randX -= rdiff;
788                                          /* diffuse transmission? */
789          if ((sflags & SDsampDf+SDsampT) == SDsampDf+SDsampT) {
790 <                if (randX < sd->tLamb.cieY) {
791 <                        sv->spec = sd->tLamb.spec;
792 <                        SDdiffuseSamp(ioVec, !inFront, randX/sd->tLamb.cieY);
790 >                const SDValue   *sdt = inFront ? &sd->tLambFront : &sd->tLambBack;
791 >                if (randX < sdt->cieY) {
792 >                        sv->spec = sdt->spec;
793 >                        SDdiffuseSamp(ioVec, !inFront, randX/sdt->cieY);
794                          goto done;
795                  }
796 <                randX -= sd->tLamb.cieY;
796 >                randX -= sdt->cieY;
797          }
798                                          /* else one of cumulative dist. */
799 <        for (i = 0; i < n && randX > cdarr[i]->cTotal; i++)
799 >        for (i = 0; i < n && randX >= cdarr[i]->cTotal; i++)
800                  randX -= cdarr[i]->cTotal;
801          if (i >= n)
802                  return SDEinternal;
# Line 816 | Line 821 | SDsampBSDF(SDValue *sv, FVECT ioVec, double randX, int
821   done:
822          if (cdarr != NULL)
823                  free(cdarr);
824 <                                        /* make sure everything is set */
820 <        c_ccvt(&sv->spec, C_CSXY+C_CSSPEC);
824 >        c_ccvt(&sv->spec, C_CSXY);      /* make sure (x,y) is set */
825          return SDEnone;
826   }
827  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines