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.37 by greg, Sun Apr 5 01:32:01 2015 UTC vs.
Revision 3.44 by greg, Sun Aug 23 00:56:00 2015 UTC

# Line 569 | Line 569 | SDqueryTre(const SDTre *sdt, float *coef,
569                  return 0;               /* should be internal error */
570                                          /* get BSDF value */
571          yval = SDlookupTre(sdt->stc[tt_Y], gridPos, hc);
572 +        if (coef == NULL)               /* just getting hypercube? */
573 +                return 1;
574          if (sdt->stc[tt_u] == NULL || sdt->stc[tt_v] == NULL) {
575 <                if (coef != NULL) *coef = yval;
575 >                *coef = yval;
576                  return 1;               /* no color */
577          }
576        if (coef == NULL)               /* just getting hypercube? */
577                return 1;
578                                          /* else decode color */
579          SDyuv2rgb(yval, SDlookupTre(sdt->stc[tt_u], gridPos, NULL),
580                          SDlookupTre(sdt->stc[tt_v], gridPos, NULL), coef);
# Line 789 | Line 789 | SDgetTreCDist(const FVECT inVec, SDComponent *sdc)
789          for (i = sdt->stc[tt_Y]->ndim - 2; i--; )
790                  inCoord[i] = floor(inCoord[i]/quantum)*quantum + .5*quantum;
791          cdlast = NULL;                  /* check for direction in cache list */
792 +        /* PLACE MUTEX LOCK HERE FOR THREAD-SAFE */
793          for (cd = (SDTreCDst *)sdc->cdList; cd != NULL;
794                                          cdlast = cd, cd = cd->next) {
795                  if (cd->sidef != mode)
# Line 807 | Line 808 | SDgetTreCDist(const FVECT inVec, SDComponent *sdc)
808                  cd->next = (SDTreCDst *)sdc->cdList;
809                  sdc->cdList = (SDCDst *)cd;
810          }
811 +        /* END MUTEX LOCK */
812          return (SDCDst *)cd;            /* ready to go */
813   }
814  
# Line 924 | Line 926 | next_token(char **spp)
926   }
927  
928   /* Advance pointer past matching token (or any token if c==0) */
929 < #define eat_token(spp,c)        (next_token(spp)==(c) ^ !(c) ? *(*(spp))++ : 0)
929 > #define eat_token(spp,c)        ((next_token(spp)==(c)) ^ !(c) ? *(*(spp))++ : 0)
930  
931   /* Count words from this point in string to '}' */
932   static int
# Line 1194 | Line 1196 | subtract_min_Y(SDNode *st)
1196          } else                          /* anisotropic covers entire tree */
1197                  vmin = SDgetTreMin(st);
1198  
1199 <        if (vmin <= FTINY)
1200 <                return .0;
1199 >        if (vmin <= .01/M_PI)
1200 >                return .0;              /* not worth bothering about */
1201  
1202          SDsubtractTreVal(st, vmin);
1203  
# Line 1241 | Line 1243 | adjust_utree(float uprime, const double *cmin, double
1243   {
1244          SDextRGBs       *mp = (SDextRGBs *)cptr;
1245          double          cmax[SD_MAXDIM];
1246 +        double          yval;
1247          float           rgb[3];
1248 <        int             ok;
1248 >        C_COLOR         clr;
1249  
1250          if (mp->stc[tt_Y]->ndim == 3) {
1251                  if (cmin[0] + .5*csiz >= .5)
# Line 1253 | Line 1256 | adjust_utree(float uprime, const double *cmin, double
1256          cmax[1] = cmin[1] + csiz;
1257          cmax[2] = cmin[2] + csiz;
1258                                          /* average RGB color over voxel */
1259 <        SDyuv2rgb(SDavgTreBox(mp->stc[tt_Y], cmin, cmax), uprime,
1259 >        SDyuv2rgb(yval=SDavgTreBox(mp->stc[tt_Y], cmin, cmax), uprime,
1260                          SDavgTreBox(mp->stc[tt_v], cmin, cmax), rgb);
1261 <                                        /* subtract minimum */
1262 <        ok = (rgb[0] -= mp->rgb[0]) > 1e-5;
1263 <        ok &= (rgb[1] -= mp->rgb[1]) > 1e-5;
1264 <        ok &= (rgb[2] -= mp->rgb[2]) > 1e-5;
1265 <        if (ok) {                       /* compute new u' for adj. RGB */
1266 <                C_COLOR clr;
1264 <                c_fromSharpRGB(rgb, &clr);
1265 <                uprime = 4.*clr.cx/(-2.*clr.cx + 12.*clr.cy + 3.);
1266 <        } else
1267 <                uprime = 4./3./(-2./3. + 12./3. + 3.);
1261 >                                        /* subtract minimum (& clamp) */
1262 >        if ((rgb[0] -= mp->rgb[0]) < 1e-5*yval) rgb[0] = 1e-5*yval;
1263 >        if ((rgb[1] -= mp->rgb[1]) < 1e-5*yval) rgb[1] = 1e-5*yval;
1264 >        if ((rgb[2] -= mp->rgb[2]) < 1e-5*yval) rgb[2] = 1e-5*yval;
1265 >        c_fromSharpRGB(rgb, &clr);      /* compute new u' for adj. RGB */
1266 >        uprime = 4.*clr.cx/(-2.*clr.cx + 12.*clr.cy + 3.);
1267                                          /* assign in new u' tree */
1268          mp->new_stu = SDsetVoxel(mp->new_stu, mp->stc[tt_Y]->ndim,
1269                                          cmin, csiz, uprime);
# Line 1277 | Line 1276 | adjust_vtree(float vprime, const double *cmin, double
1276   {
1277          SDextRGBs       *mp = (SDextRGBs *)cptr;
1278          double          cmax[SD_MAXDIM];
1279 +        double          yval;
1280          float           rgb[3];
1281 <        int             ok;
1281 >        C_COLOR         clr;
1282  
1283          if (mp->stc[tt_Y]->ndim == 3) {
1284                  if (cmin[0] + .5*csiz >= .5)
# Line 1289 | Line 1289 | adjust_vtree(float vprime, const double *cmin, double
1289          cmax[1] = cmin[1] + csiz;
1290          cmax[2] = cmin[2] + csiz;
1291                                          /* average RGB color over voxel */
1292 <        SDyuv2rgb(SDavgTreBox(mp->stc[tt_Y], cmin, cmax),
1292 >        SDyuv2rgb(yval=SDavgTreBox(mp->stc[tt_Y], cmin, cmax),
1293                          SDavgTreBox(mp->stc[tt_u], cmin, cmax),
1294                          vprime, rgb);
1295 <                                        /* subtract minimum */
1296 <        ok = (rgb[0] -= mp->rgb[0]) > 1e-5;
1297 <        ok &= (rgb[1] -= mp->rgb[1]) > 1e-5;
1298 <        ok &= (rgb[2] -= mp->rgb[2]) > 1e-5;
1299 <        if (ok) {                       /* compute new v' for adj. RGB */
1300 <                C_COLOR clr;
1301 <                c_fromSharpRGB(rgb, &clr);
1302 <                vprime = 9.*clr.cy/(-2.*clr.cx + 12.*clr.cy + 3.);
1303 <        } else
1304 <                vprime = 9./3./(-2./3. + 12./3. + 3.);
1295 >                                        /* subtract minimum (& clamp) */
1296 >        if ((rgb[0] -= mp->rgb[0]) < 1e-5*yval) rgb[0] = 1e-5*yval;
1297 >        if ((rgb[1] -= mp->rgb[1]) < 1e-5*yval) rgb[1] = 1e-5*yval;
1298 >        if ((rgb[2] -= mp->rgb[2]) < 1e-5*yval) rgb[2] = 1e-5*yval;
1299 >        c_fromSharpRGB(rgb, &clr);      /* compute new v' for adj. RGB */
1300 >        vprime = 9.*clr.cy/(-2.*clr.cx + 12.*clr.cy + 3.);
1301                                          /* assign in new v' tree */
1302          mp->new_stv = SDsetVoxel(mp->new_stv, mp->stc[tt_Y]->ndim,
1303                                          cmin, csiz, vprime);
# Line 1320 | Line 1316 | subtract_min_RGB(C_COLOR *cs, SDNode *stc[])
1316          my_min.new_stu = my_min.new_stv = NULL;
1317                                          /* get minimum RGB value */
1318          SDtraverseTre(stc[tt_Y], NULL, 0, get_min_RGB, &my_min);
1319 <        ymin = tt_RGB_coef[0]*my_min.rgb[0] +
1320 <                        tt_RGB_coef[1]*my_min.rgb[1] +
1321 <                                        tt_RGB_coef[2]*my_min.rgb[2];
1322 <        if (ymin <= 1e-5) {
1323 <                *cs = c_dfcolor;
1328 <                return .0;              /* not worth bothering about */
1329 <        }
1330 <                                        /* adjust u' & v' values */
1319 >                                        /* convert to C_COLOR */
1320 >        ymin =  c_fromSharpRGB(my_min.rgb, cs);
1321 >        if (ymin <= .01/M_PI)           /* not worth bothering about? */
1322 >                return .0;
1323 >                                        /* adjust u' & v' trees */
1324          SDtraverseTre(stc[tt_u], NULL, 0, adjust_utree, &my_min);
1325          SDtraverseTre(stc[tt_v], NULL, 0, adjust_vtree, &my_min);
1326          SDfreeTre(stc[tt_u]); SDfreeTre(stc[tt_v]);
1327          stc[tt_u] = SDsimplifyTre(my_min.new_stu);
1328          stc[tt_v] = SDsimplifyTre(my_min.new_stv);
1329 <                                        /* finally, subtract Y value */
1329 >                                        /* subtract Y & return hemispherical */
1330          SDsubtractTreVal(stc[tt_Y], ymin);
1331 <                                        /* return color and Y */
1332 <        c_fromSharpRGB(my_min.rgb, cs);
1340 <        return M_PI*ymin;
1331 >
1332 >        return M_PI * ymin;
1333   }
1334  
1335   /* Extract and separate diffuse portion of BSDF */
# Line 1364 | Line 1356 | extract_diffuse(SDValue *dv, SDSpectralDF *df)
1356                  memcpy(df->comp[0].cspec, tt_RGB_prim, sizeof(tt_RGB_prim));
1357                  dv->cieY = subtract_min_RGB(&dv->spec, sdt->stc);
1358          } else {
1359 <                df->comp[0].cspec[0] = c_dfcolor;
1359 >                df->comp[0].cspec[0] = dv->spec = c_dfcolor;
1360                  dv->cieY = subtract_min_Y(sdt->stc[tt_Y]);
1361          }
1362          df->maxHemi -= dv->cieY;        /* adjust maximum hemispherical */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines