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.50 by greg, Sat Mar 27 17:50:18 2021 UTC vs.
Revision 3.54 by greg, Tue Jan 25 01:34:20 2022 UTC

# Line 515 | Line 515 | SDyuv2rgb(double yval, double uprime, double vprime, f
515          c_toSharpRGB(&cxy, yval, rgb);
516   }
517  
518 + static double
519 + pfrac(double x)
520 + {
521 +        return( x - (int)x );
522 + }
523 +
524   /* Query BSDF value and sample hypercube for the given vectors */
525   static int
526   SDqueryTre(const SDTre *sdt, float *coef,
527 <                const FVECT outVec, const FVECT inVec, double *hc)
527 >                const FVECT inVec, const FVECT outVec, double *hc)
528   {
529          const RREAL     *vtmp;
530 +        double          hcube[SD_MAXDIM+1];
531          float           yval;
532          FVECT           rOutVec;
533 <        double          gridPos[4];
533 >        RREAL           gridPos[4];
534 >        double          d;
535 >        int             i;
536  
537          if (sdt->stc[tt_Y] == NULL)     /* paranoia, I hope */
538                  return 0;
# Line 561 | Line 570 | SDqueryTre(const SDTre *sdt, float *coef,
570                  spinvector(rOutVec, outVec, zvec, -atan2(-inVec[1],-inVec[0]));
571                  gridPos[0] = (.5-FTINY) -
572                                  .5*sqrt(inVec[0]*inVec[0] + inVec[1]*inVec[1]);
573 <                SDdisk2square(gridPos+1, rOutVec[0], rOutVec[1]);
573 >                disk2square(gridPos+1, rOutVec[0], rOutVec[1]);
574          } else if (sdt->stc[tt_Y]->ndim == 4) {
575 <                SDdisk2square(gridPos, -inVec[0], -inVec[1]);
576 <                SDdisk2square(gridPos+2, outVec[0], outVec[1]);
575 >                disk2square(gridPos, -inVec[0], -inVec[1]);
576 >                disk2square(gridPos+2, outVec[0], outVec[1]);
577          } else
578                  return 0;               /* should be internal error */
579 <                                        /* get BSDF value */
579 >
580 >        if (hc == NULL) hc = hcube;     /* get BSDF value */
581          yval = SDlookupTre(sdt->stc[tt_Y], gridPos, hc);
582          if (coef == NULL)               /* just getting hypercube? */
583                  return 1;
584 +        d = 0;                          /* position-specific perturbation */
585 +        for (i = sdt->stc[tt_Y]->ndim; i--; )
586 +                d += pfrac((2<<i)/(hc[i]+.01687)) - .5;
587 +        yval *= 1. + 1e-4*d;            /* assumes tolerance is > 0.04% */
588          if (sdt->stc[tt_u] == NULL || sdt->stc[tt_v] == NULL) {
589                  *coef = yval;
590                  return 1;               /* no color */
# Line 746 | Line 760 | SDgetTreCDist(const FVECT inVec, SDComponent *sdc)
760   {
761          unsigned long   cacheLeft = SDmaxCache;
762          const SDTre     *sdt;
763 <        double          inCoord[2];
763 >        RREAL           inCoord[2];
764          int             i;
765          int             mode;
766          SDTreCDst       *cd, *cdlast, *cdlimit;
# Line 781 | Line 795 | SDgetTreCDist(const FVECT inVec, SDComponent *sdc)
795                                  .5*sqrt(inVec[0]*inVec[0] + inVec[1]*inVec[1]);
796          } else if (sdt->stc[tt_Y]->ndim == 4) {
797                  if (mode != sdt->sidef) /* use reciprocity? */
798 <                        SDdisk2square(inCoord, inVec[0], inVec[1]);
798 >                        disk2square(inCoord, inVec[0], inVec[1]);
799                  else
800 <                        SDdisk2square(inCoord, -inVec[0], -inVec[1]);
800 >                        disk2square(inCoord, -inVec[0], -inVec[1]);
801          } else
802                  return NULL;            /* should be internal error */
803                                          /* quantize to avoid f.p. errors */
# Line 888 | Line 902 | SDsampTreCDist(FVECT ioVec, double randX, const SDCDst
902          const SDTreCDst *cd = (const SDTreCDst *)cdp;
903          const unsigned  target = randX*cumlmax;
904          bitmask_t       hndx, hcoord[2];
905 <        double          gpos[3], rotangle;
905 >        FVECT           gpos;
906 >        double          rotangle;
907          int             i, iupper, ilower;
908                                          /* check arguments */
909          if ((ioVec == NULL) | (cd == NULL))
# Line 918 | Line 933 | SDsampTreCDist(FVECT ioVec, double randX, const SDCDst
933          for (i = 2; i--; )
934                  gpos[i] = ((double)hcoord[i] + rand()*(1./(RAND_MAX+.5))) /
935                                  (double)((bitmask_t)1 << nBitsC);
936 <        SDsquare2disk(gpos, gpos[0], gpos[1]);
936 >        square2disk(gpos, gpos[0], gpos[1]);
937                                          /* compute Z-coordinate */
938          gpos[2] = 1. - gpos[0]*gpos[0] - gpos[1]*gpos[1];
939          gpos[2] = sqrt(gpos[2]*(gpos[2]>0));
# Line 1431 | Line 1446 | SDloadTre(SDData *sd, ezxml_t wtl)
1446          extract_diffuse(&sd->rLambFront, sd->rf);
1447          extract_diffuse(&sd->rLambBack, sd->rb);
1448          extract_diffuse(&sd->tLambFront, sd->tf);
1449 <        extract_diffuse(&sd->tLambBack, sd->tb);
1449 >        if (sd->tb != NULL) {
1450 >                extract_diffuse(&sd->tLambBack, sd->tb);
1451 >                if (sd->tf == NULL)
1452 >                        sd->tLambFront = sd->tLambBack;
1453 >        } else if (sd->tf != NULL)
1454 >                sd->tLambBack = sd->tLambFront;
1455                                          /* return success */
1456          return SDEnone;
1457   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines