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.44 by greg, Sun Apr 21 21:36:23 2013 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 488 | Line 493 | SDsampComponent(SDValue *sv, FVECT ioVec, double randX
493                  return SDEargument;
494                                          /* get cumulative distribution */
495          VCOPY(inVec, ioVec);
496 +        sv->cieY = 0;
497          cd = (*sdc->func->getCDist)(inVec, sdc);
498 <        if (cd == NULL)
499 <                return SDEmemory;
500 <        if (cd->cTotal <= 1e-6) {       /* anything to sample? */
498 >        if (cd != NULL)
499 >                sv->cieY = cd->cTotal;
500 >        if (sv->cieY <= 1e-6) {         /* nothing to sample? */
501                  sv->spec = c_dfcolor;
502 <                sv->cieY = .0;
497 <                memset(ioVec, 0, 3*sizeof(double));
502 >                memset(ioVec, 0, sizeof(FVECT));
503                  return SDEnone;
504          }
500        sv->cieY = cd->cTotal;
505                                          /* compute sample direction */
506          ec = (*sdc->func->sampCDist)(ioVec, randX, cd);
507          if (ec)
# Line 514 | 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 */
518 <        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 559 | Line 562 | SDdiffuseSamp(FVECT outVec, int outFront, double randX
562          SDmultiSamp(outVec, 2, randX);
563          SDsquare2disk(outVec, outVec[0], outVec[1]);
564          outVec[2] = 1. - outVec[0]*outVec[0] - outVec[1]*outVec[1];
565 <        if (outVec[2] > 0)              /* a bit of paranoia */
563 <                outVec[2] = sqrt(outVec[2]);
565 >        outVec[2] = sqrt(outVec[2]*(outVec[2]>0));
566          if (!outFront)                  /* going out back? */
567                  outVec[2] = -outVec[2];
568   }
# Line 597 | 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 619 | Line 622 | SDsizeBSDF(double *projSA, const FVECT v1, const RREAL
622                  projSA[0] = M_PI;
623                  if (qflags == SDqueryMin+SDqueryMax)
624                          projSA[1] = M_PI;
625 <        }
625 >        } else if (qflags == SDqueryMin+SDqueryMax && projSA[0] > projSA[1])
626 >                projSA[0] = projSA[1];
627          return SDEnone;
628   }
629  
# Line 647 | 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 663 | Line 667 | SDevalBSDF(SDValue *sv, const FVECT outVec, const FVEC
667                          sv->cieY += coef[nch];
668                  }
669          }
670 <                                        /* make sure everything is set */
667 <        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 756 | Line 759 | SDsampBSDF(SDValue *sv, FVECT ioVec, double randX, int
759                  return SDEmemory;
760          while (j-- > 0) {               /* non-diffuse transmission */
761                  cdarr[i+j] = (*tdf->comp[j].func->getCDist)(inVec, &tdf->comp[j]);
762 <                if (cdarr[i+j] == NULL) {
763 <                        free(cdarr);
761 <                        return SDEmemory;
762 <                }
762 >                if (cdarr[i+j] == NULL)
763 >                        cdarr[i+j] = &SDemptyCD;
764                  sv->cieY += cdarr[i+j]->cTotal;
765          }
766          while (i-- > 0) {               /* non-diffuse reflection */
767                  cdarr[i] = (*rdf->comp[i].func->getCDist)(inVec, &rdf->comp[i]);
768 <                if (cdarr[i] == NULL) {
769 <                        free(cdarr);
769 <                        return SDEmemory;
770 <                }
768 >                if (cdarr[i] == NULL)
769 >                        cdarr[i] = &SDemptyCD;
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 793 | 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 818 | 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 */
822 <        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