ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/bsdf_t.c
(Generate patch)

Comparing ray/src/common/bsdf_t.c (file contents):
Revision 3.47 by greg, Thu May 10 22:55:35 2018 UTC vs.
Revision 3.52 by greg, Tue Dec 7 23:49:50 2021 UTC

# Line 518 | Line 518 | SDyuv2rgb(double yval, double uprime, double vprime, f
518   /* Query BSDF value and sample hypercube for the given vectors */
519   static int
520   SDqueryTre(const SDTre *sdt, float *coef,
521 <                const FVECT outVec, const FVECT inVec, double *hc)
521 >                const FVECT inVec, const FVECT outVec, double *hc)
522   {
523          const RREAL     *vtmp;
524          float           yval;
# Line 744 | Line 744 | make_cdist(const SDTre *sdt, const double *invec, int
744   const SDCDst *
745   SDgetTreCDist(const FVECT inVec, SDComponent *sdc)
746   {
747 +        unsigned long   cacheLeft = SDmaxCache;
748          const SDTre     *sdt;
749          double          inCoord[2];
750          int             i;
751          int             mode;
752 <        SDTreCDst       *cd, *cdlast;
752 >        SDTreCDst       *cd, *cdlast, *cdlimit;
753                                          /* check arguments */
754          if ((inVec == NULL) | (sdc == NULL) ||
755                          (sdt = (SDTre *)sdc->dist) == NULL)
# Line 788 | Line 789 | SDgetTreCDist(const FVECT inVec, SDComponent *sdc)
789                                          /* quantize to avoid f.p. errors */
790          for (i = sdt->stc[tt_Y]->ndim - 2; i--; )
791                  inCoord[i] = floor(inCoord[i]/quantum)*quantum + .5*quantum;
792 <        cdlast = NULL;                  /* check for direction in cache list */
792 >        cdlast = cdlimit = NULL;        /* check for direction in cache list */
793          /* PLACE MUTEX LOCK HERE FOR THREAD-SAFE */
794          for (cd = (SDTreCDst *)sdc->cdList; cd != NULL;
795                                          cdlast = cd, cd = cd->next) {
796 +                if (cacheLeft) {        /* check cache size limit */
797 +                        long    csiz = sizeof(SDTreCDst) +
798 +                                        sizeof(cd->carr[0])*cd->calen;
799 +                        if (cacheLeft > csiz)
800 +                                cacheLeft -= csiz;
801 +                        else {
802 +                                cdlimit = cdlast;
803 +                                cacheLeft = 0;
804 +                        }
805 +                }
806                  if (cd->sidef != mode)
807                          continue;
808                  for (i = sdt->stc[tt_Y]->ndim - 2; i--; )
# Line 801 | Line 812 | SDgetTreCDist(const FVECT inVec, SDComponent *sdc)
812                  if (i < 0)
813                          break;          /* means we have a match */
814          }
815 <        if (cd == NULL)                 /* need to create new entry? */
815 >        if (cd == NULL) {               /* need to create new entry? */
816 >                if (cdlimit != NULL)    /* exceeded cache size limit? */
817 >                        while ((cd = cdlimit->next) != NULL) {
818 >                                cdlimit->next = cd->next;
819 >                                free(cd);
820 >                        }
821                  cdlast = cd = make_cdist(sdt, inCoord, mode != sdt->sidef);
822 +        }
823          if (cdlast != NULL) {           /* move entry to head of cache list */
824                  cdlast->next = cd->next;
825                  cd->next = (SDTreCDst *)sdc->cdList;
# Line 1413 | Line 1430 | SDloadTre(SDData *sd, ezxml_t wtl)
1430                                          /* separate diffuse components */
1431          extract_diffuse(&sd->rLambFront, sd->rf);
1432          extract_diffuse(&sd->rLambBack, sd->rb);
1433 <        if (sd->tf != NULL)
1434 <                extract_diffuse(&sd->tLamb, sd->tf);
1435 <        if (sd->tb != NULL)
1436 <                extract_diffuse(&sd->tLamb, sd->tb);
1433 >        extract_diffuse(&sd->tLambFront, sd->tf);
1434 >        if (sd->tb != NULL) {
1435 >                extract_diffuse(&sd->tLambBack, sd->tb);
1436 >                if (sd->tf == NULL)
1437 >                        sd->tLambFront = sd->tLambBack;
1438 >        } else if (sd->tf != NULL)
1439 >                sd->tLambBack = sd->tLambFront;
1440                                          /* return success */
1441          return SDEnone;
1442   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines