--- ray/src/common/bsdf_t.c 2015/04/06 16:00:15 3.39 +++ ray/src/common/bsdf_t.c 2018/01/05 21:00:24 3.45 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: bsdf_t.c,v 3.39 2015/04/06 16:00:15 greg Exp $"; +static const char RCSid[] = "$Id: bsdf_t.c,v 3.45 2018/01/05 21:00:24 greg Exp $"; #endif /* * bsdf_t.c @@ -569,12 +569,12 @@ SDqueryTre(const SDTre *sdt, float *coef, return 0; /* should be internal error */ /* get BSDF value */ yval = SDlookupTre(sdt->stc[tt_Y], gridPos, hc); + if (coef == NULL) /* just getting hypercube? */ + return 1; if (sdt->stc[tt_u] == NULL || sdt->stc[tt_v] == NULL) { - if (coef != NULL) *coef = yval; + *coef = yval; return 1; /* no color */ } - if (coef == NULL) /* just getting hypercube? */ - return 1; /* else decode color */ SDyuv2rgb(yval, SDlookupTre(sdt->stc[tt_u], gridPos, NULL), SDlookupTre(sdt->stc[tt_v], gridPos, NULL), coef); @@ -789,6 +789,7 @@ SDgetTreCDist(const FVECT inVec, SDComponent *sdc) for (i = sdt->stc[tt_Y]->ndim - 2; i--; ) inCoord[i] = floor(inCoord[i]/quantum)*quantum + .5*quantum; cdlast = NULL; /* check for direction in cache list */ + /* PLACE MUTEX LOCK HERE FOR THREAD-SAFE */ for (cd = (SDTreCDst *)sdc->cdList; cd != NULL; cdlast = cd, cd = cd->next) { if (cd->sidef != mode) @@ -807,6 +808,7 @@ SDgetTreCDist(const FVECT inVec, SDComponent *sdc) cd->next = (SDTreCDst *)sdc->cdList; sdc->cdList = (SDCDst *)cd; } + /* END MUTEX LOCK */ return (SDCDst *)cd; /* ready to go */ } @@ -924,7 +926,7 @@ next_token(char **spp) } /* Advance pointer past matching token (or any token if c==0) */ -#define eat_token(spp,c) (next_token(spp)==(c) ^ !(c) ? *(*(spp))++ : 0) +#define eat_token(spp,c) ((next_token(spp)==(c)) ^ !(c) ? *(*(spp))++ : 0) /* Count words from this point in string to '}' */ static int @@ -1314,24 +1316,20 @@ subtract_min_RGB(C_COLOR *cs, SDNode *stc[]) my_min.new_stu = my_min.new_stv = NULL; /* get minimum RGB value */ SDtraverseTre(stc[tt_Y], NULL, 0, get_min_RGB, &my_min); - ymin = tt_RGB_coef[0]*my_min.rgb[0] + - tt_RGB_coef[1]*my_min.rgb[1] + - tt_RGB_coef[2]*my_min.rgb[2]; - if (ymin <= .01/M_PI) { - *cs = c_dfcolor; - return .0; /* not worth bothering about */ - } - /* adjust u' & v' values */ + /* convert to C_COLOR */ + ymin = c_fromSharpRGB(my_min.rgb, cs); + if (ymin <= .01/M_PI) /* not worth bothering about? */ + return .0; + /* adjust u' & v' trees */ SDtraverseTre(stc[tt_u], NULL, 0, adjust_utree, &my_min); SDtraverseTre(stc[tt_v], NULL, 0, adjust_vtree, &my_min); SDfreeTre(stc[tt_u]); SDfreeTre(stc[tt_v]); stc[tt_u] = SDsimplifyTre(my_min.new_stu); stc[tt_v] = SDsimplifyTre(my_min.new_stv); - /* finally, subtract Y value */ + /* subtract Y & return hemispherical */ SDsubtractTreVal(stc[tt_Y], ymin); - /* return color and Y */ - c_fromSharpRGB(my_min.rgb, cs); - return M_PI*ymin; + + return M_PI * ymin; } /* Extract and separate diffuse portion of BSDF */ @@ -1358,7 +1356,7 @@ extract_diffuse(SDValue *dv, SDSpectralDF *df) memcpy(df->comp[0].cspec, tt_RGB_prim, sizeof(tt_RGB_prim)); dv->cieY = subtract_min_RGB(&dv->spec, sdt->stc); } else { - df->comp[0].cspec[0] = c_dfcolor; + df->comp[0].cspec[0] = dv->spec = c_dfcolor; dv->cieY = subtract_min_Y(sdt->stc[tt_Y]); } df->maxHemi -= dv->cieY; /* adjust maximum hemispherical */ @@ -1423,7 +1421,7 @@ SDloadTre(SDData *sd, ezxml_t wtl) } /* Variable resolution BSDF methods */ -SDFunc SDhandleTre = { +const SDFunc SDhandleTre = { &SDgetTreBSDF, &SDqueryTreProjSA, &SDgetTreCDist,