--- ray/src/common/bsdf_t.c 2015/04/06 16:00:15 3.39 +++ ray/src/common/bsdf_t.c 2018/04/17 18:11:16 3.46 @@ -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.46 2018/04/17 18:11:16 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 @@ -1174,11 +1176,12 @@ SDsubtractTreVal(SDNode *st, float val) static double subtract_min_Y(SDNode *st) { - float vmin; + const float vmaxmin = 1.5/M_PI; + float vmin; /* be sure to skip unused portion */ if (st->ndim == 3) { int n; - vmin = 1./M_PI; + vmin = vmaxmin; if (st->log2GR < 0) { for (n = 0; n < 8; n += 2) { float v = SDgetTreMin(st->u.t[n]); @@ -1194,7 +1197,7 @@ subtract_min_Y(SDNode *st) } else /* anisotropic covers entire tree */ vmin = SDgetTreMin(st); - if (vmin <= .01/M_PI) + if ((vmin >= vmaxmin) | (vmin <= .01/M_PI)) return .0; /* not worth bothering about */ SDsubtractTreVal(st, vmin); @@ -1314,24 +1317,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 >= .5*FHUGE) | (ymin <= .01/M_PI)) + return .0; /* close to zero or no tree */ + /* 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 +1357,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 +1422,7 @@ SDloadTre(SDData *sd, ezxml_t wtl) } /* Variable resolution BSDF methods */ -SDFunc SDhandleTre = { +const SDFunc SDhandleTre = { &SDgetTreBSDF, &SDqueryTreProjSA, &SDgetTreCDist,