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.51 by greg, Sat Aug 1 23:27:04 2015 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 422 | Line 427 | SDcacheFile(const char *fname)
427          if (fname == NULL || !*fname)
428                  return NULL;
429          SDerrorDetail[0] = '\0';
430 +        /* PLACE MUTEX LOCK HERE FOR THREAD-SAFE */
431          if ((sd = SDgetCache(fname)) == NULL) {
432                  SDreportError(SDEmemory, stderr);
433                  return NULL;
# Line 429 | Line 435 | SDcacheFile(const char *fname)
435          if (!SDisLoaded(sd) && (ec = SDloadFile(sd, fname))) {
436                  SDreportError(ec, stderr);
437                  SDfreeCache(sd);
438 <                return NULL;
438 >                sd = NULL;
439          }
440 +        /* END MUTEX LOCK */
441          return sd;
442   }
443  
# Line 494 | Line 501 | SDsampComponent(SDValue *sv, FVECT ioVec, double randX
501                  sv->cieY = cd->cTotal;
502          if (sv->cieY <= 1e-6) {         /* nothing to sample? */
503                  sv->spec = c_dfcolor;
504 <                memset(ioVec, 0, 3*sizeof(double));
504 >                memset(ioVec, 0, sizeof(FVECT));
505                  return SDEnone;
506          }
507                                          /* compute sample direction */
# Line 513 | 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 */
517 <        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 645 | 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 663 | Line 669 | SDevalBSDF(SDValue *sv, const FVECT outVec, const FVEC
669                          sv->cieY += coef[nch];
670                  }
671          }
672 <                                        /* make sure everything is set */
667 <        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 692 | 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 745 | 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 768 | Line 774 | SDsampBSDF(SDValue *sv, FVECT ioVec, double randX, int
774          }
775          if (sv->cieY <= 1e-6) {         /* anything to sample? */
776                  sv->cieY = .0;
777 <                memset(ioVec, 0, 3*sizeof(double));
777 >                memset(ioVec, 0, sizeof(FVECT));
778                  return SDEnone;
779          }
780                                          /* scale random variable */
# Line 781 | 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 814 | 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 */
818 <        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