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.50 by greg, Sun Feb 8 22:14:50 2015 UTC vs.
Revision 2.60 by greg, Wed Apr 28 00:59:10 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 327 | 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 378 | 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 422 | Line 429 | SDcacheFile(const char *fname)
429          if (fname == NULL || !*fname)
430                  return NULL;
431          SDerrorDetail[0] = '\0';
432 +        /* PLACE MUTEX LOCK HERE FOR THREAD-SAFE */
433          if ((sd = SDgetCache(fname)) == NULL) {
434                  SDreportError(SDEmemory, stderr);
435                  return NULL;
# Line 429 | Line 437 | SDcacheFile(const char *fname)
437          if (!SDisLoaded(sd) && (ec = SDloadFile(sd, fname))) {
438                  SDreportError(ec, stderr);
439                  SDfreeCache(sd);
440 <                return NULL;
440 >                sd = NULL;
441          }
442 +        /* END MUTEX LOCK */
443          return sd;
444   }
445  
# Line 494 | Line 503 | SDsampComponent(SDValue *sv, FVECT ioVec, double randX
503                  sv->cieY = cd->cTotal;
504          if (sv->cieY <= 1e-6) {         /* nothing to sample? */
505                  sv->spec = c_dfcolor;
506 <                memset(ioVec, 0, 3*sizeof(double));
506 >                memset(ioVec, 0, sizeof(FVECT));
507                  return SDEnone;
508          }
509                                          /* compute sample direction */
# Line 513 | Line 522 | SDsampComponent(SDValue *sv, FVECT ioVec, double randX
522                  c_cmix(&sv->spec, d, &sv->spec, coef[n], &sdc->cspec[n]);
523                  d += coef[n];
524          }
525 <                                        /* make sure everything is set */
517 <        c_ccvt(&sv->spec, C_CSXY+C_CSSPEC);
525 >        c_ccvt(&sv->spec, C_CSXY);      /* make sure (x,y) is set */
526          return SDEnone;
527   }
528  
# Line 595 | Line 603 | SDsizeBSDF(double *projSA, const FVECT v1, const RREAL
603                  rdf = sd->rb;
604                  tdf = (sd->tb != NULL) ? sd->tb : sd->tf;
605          }
606 <        if (v2 != NULL)                 /* bidirectional? */
606 >        if (v2 != NULL) {               /* bidirectional? */
607                  if (v1[2] > 0 ^ v2[2] > 0)
608                          rdf = NULL;
609                  else
610                          tdf = NULL;
611 +        }
612          ec = SDEdata;                   /* run through components */
613          for (i = (rdf==NULL) ? 0 : rdf->ncomp; i--; ) {
614                  ec = (*rdf->comp[i].func->queryProjSA)(projSA, v1, v2,
# Line 644 | 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 /* inBack */ {
659 <                *sv = sd->tLamb;
658 >        } else /* outFront & !inFront */ {
659 >                *sv = sd->tLambBack;
660                  sdf = (sd->tb != NULL) ? sd->tb : sd->tf;
661          }
662          sv->cieY *= 1./M_PI;
# Line 662 | Line 671 | SDevalBSDF(SDValue *sv, const FVECT outVec, const FVEC
671                          sv->cieY += coef[nch];
672                  }
673          }
674 <                                        /* make sure everything is set */
666 <        c_ccvt(&sv->spec, C_CSXY+C_CSSPEC);
674 >        c_ccvt(&sv->spec, C_CSXY);      /* make sure (x,y) is set */
675          return SDEnone;
676   }
677  
# Line 691 | 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 744 | 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 767 | Line 776 | SDsampBSDF(SDValue *sv, FVECT ioVec, double randX, int
776          }
777          if (sv->cieY <= 1e-6) {         /* anything to sample? */
778                  sv->cieY = .0;
779 <                memset(ioVec, 0, 3*sizeof(double));
779 >                memset(ioVec, 0, sizeof(FVECT));
780                  return SDEnone;
781          }
782                                          /* scale random variable */
# Line 780 | 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++)
801 >        for (i = 0; i < n && randX >= cdarr[i]->cTotal; i++)
802                  randX -= cdarr[i]->cTotal;
803          if (i >= n)
804                  return SDEinternal;
# Line 813 | Line 823 | SDsampBSDF(SDValue *sv, FVECT ioVec, double randX, int
823   done:
824          if (cdarr != NULL)
825                  free(cdarr);
826 <                                        /* make sure everything is set */
817 <        c_ccvt(&sv->spec, C_CSXY+C_CSSPEC);
826 >        c_ccvt(&sv->spec, C_CSXY);      /* make sure (x,y) is set */
827          return SDEnone;
828   }
829  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines