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.48 by greg, Mon Mar 24 04:00:45 2014 UTC vs.
Revision 2.58 by greg, Thu May 14 19:20:13 2020 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 199 | Line 202 | SDloadFile(SDData *sd, const char *fname)
202          }
203          wtl = ezxml_child(ezxml_child(fl, "Optical"), "Layer");
204          if (wtl == NULL) {
205 <                sprintf(SDerrorDetail, "BSDF \"%s\": no optical layers'",
205 >                sprintf(SDerrorDetail, "BSDF \"%s\": no optical layers",
206                                  sd->name);
207                  ezxml_free(fl);
208                  return SDEformat;
# Line 422 | Line 425 | SDcacheFile(const char *fname)
425          if (fname == NULL || !*fname)
426                  return NULL;
427          SDerrorDetail[0] = '\0';
428 +        /* PLACE MUTEX LOCK HERE FOR THREAD-SAFE */
429          if ((sd = SDgetCache(fname)) == NULL) {
430                  SDreportError(SDEmemory, stderr);
431                  return NULL;
# Line 429 | Line 433 | SDcacheFile(const char *fname)
433          if (!SDisLoaded(sd) && (ec = SDloadFile(sd, fname))) {
434                  SDreportError(ec, stderr);
435                  SDfreeCache(sd);
436 <                return NULL;
436 >                sd = NULL;
437          }
438 +        /* END MUTEX LOCK */
439          return sd;
440   }
441  
# Line 494 | Line 499 | SDsampComponent(SDValue *sv, FVECT ioVec, double randX
499                  sv->cieY = cd->cTotal;
500          if (sv->cieY <= 1e-6) {         /* nothing to sample? */
501                  sv->spec = c_dfcolor;
502 <                memset(ioVec, 0, 3*sizeof(double));
502 >                memset(ioVec, 0, sizeof(FVECT));
503                  return SDEnone;
504          }
505                                          /* compute sample direction */
# Line 513 | Line 518 | SDsampComponent(SDValue *sv, FVECT ioVec, double randX
518                  c_cmix(&sv->spec, d, &sv->spec, coef[n], &sdc->cspec[n]);
519                  d += coef[n];
520          }
521 <                                        /* make sure everything is set */
517 <        c_ccvt(&sv->spec, C_CSXY+C_CSSPEC);
521 >        c_ccvt(&sv->spec, C_CSXY);      /* make sure (x,y) is set */
522          return SDEnone;
523   }
524  
# Line 595 | Line 599 | SDsizeBSDF(double *projSA, const FVECT v1, const RREAL
599                  rdf = sd->rb;
600                  tdf = (sd->tb != NULL) ? sd->tb : sd->tf;
601          }
602 <        if (v2 != NULL)                 /* bidirectional? */
602 >        if (v2 != NULL) {               /* bidirectional? */
603                  if (v1[2] > 0 ^ v2[2] > 0)
604                          rdf = NULL;
605                  else
606                          tdf = NULL;
607 +        }
608          ec = SDEdata;                   /* run through components */
609          for (i = (rdf==NULL) ? 0 : rdf->ncomp; i--; ) {
610                  ec = (*rdf->comp[i].func->queryProjSA)(projSA, v1, v2,
# Line 646 | Line 651 | SDevalBSDF(SDValue *sv, const FVECT outVec, const FVEC
651          } else if (inFront) {
652                  *sv = sd->tLamb;
653                  sdf = (sd->tf != NULL) ? sd->tf : sd->tb;
654 <        } else /* inBack */ {
654 >        } else /* outFront & !inFront */ {
655                  *sv = sd->tLamb;
656                  sdf = (sd->tb != NULL) ? sd->tb : sd->tf;
657          }
# Line 662 | Line 667 | SDevalBSDF(SDValue *sv, const FVECT outVec, const FVEC
667                          sv->cieY += coef[nch];
668                  }
669          }
670 <                                        /* make sure everything is set */
666 <        c_ccvt(&sv->spec, C_CSXY+C_CSSPEC);
670 >        c_ccvt(&sv->spec, C_CSXY);      /* make sure (x,y) is set */
671          return SDEnone;
672   }
673  
# Line 763 | Line 767 | SDsampBSDF(SDValue *sv, FVECT ioVec, double randX, int
767                  cdarr[i] = (*rdf->comp[i].func->getCDist)(inVec, &rdf->comp[i]);
768                  if (cdarr[i] == NULL)
769                          cdarr[i] = &SDemptyCD;
770 <                else
767 <                        sv->cieY += cdarr[i]->cTotal;
770 >                sv->cieY += cdarr[i]->cTotal;
771          }
772          if (sv->cieY <= 1e-6) {         /* anything to sample? */
773                  sv->cieY = .0;
774 <                memset(ioVec, 0, 3*sizeof(double));
774 >                memset(ioVec, 0, sizeof(FVECT));
775                  return SDEnone;
776          }
777                                          /* scale random variable */
# Line 789 | Line 792 | SDsampBSDF(SDValue *sv, FVECT ioVec, double randX, int
792                  randX -= sd->tLamb.cieY;
793          }
794                                          /* else one of cumulative dist. */
795 <        for (i = 0; i < n && randX > cdarr[i]->cTotal; i++)
795 >        for (i = 0; i < n && randX >= cdarr[i]->cTotal; i++)
796                  randX -= cdarr[i]->cTotal;
797          if (i >= n)
798                  return SDEinternal;
# Line 814 | Line 817 | SDsampBSDF(SDValue *sv, FVECT ioVec, double randX, int
817   done:
818          if (cdarr != NULL)
819                  free(cdarr);
820 <                                        /* make sure everything is set */
818 <        c_ccvt(&sv->spec, C_CSXY+C_CSSPEC);
820 >        c_ccvt(&sv->spec, C_CSXY);      /* make sure (x,y) is set */
821          return SDEnone;
822   }
823  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines