--- ray/src/common/bsdf_t.c 2015/04/24 21:02:14 3.41 +++ ray/src/common/bsdf_t.c 2018/05/10 22:55:35 3.47 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: bsdf_t.c,v 3.41 2015/04/24 21:02:14 greg Exp $"; +static const char RCSid[] = "$Id: bsdf_t.c,v 3.47 2018/05/10 22:55:35 greg Exp $"; #endif /* * bsdf_t.c @@ -571,7 +571,7 @@ SDqueryTre(const SDTre *sdt, float *coef, 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 (sdt->stc[tt_u] == NULL || sdt->stc[tt_v] == NULL) { *coef = yval; return 1; /* no color */ } @@ -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); @@ -1316,8 +1319,8 @@ subtract_min_RGB(C_COLOR *cs, SDNode *stc[]) SDtraverseTre(stc[tt_Y], NULL, 0, get_min_RGB, &my_min); /* convert to C_COLOR */ ymin = c_fromSharpRGB(my_min.rgb, cs); - if (ymin <= .01/M_PI) /* not worth bothering about? */ - return .0; + 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); @@ -1354,12 +1357,12 @@ 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 */ - /* make sure everything is set */ - c_ccvt(&dv->spec, C_CSXY+C_CSSPEC); + + c_ccvt(&dv->spec, C_CSXY); /* make sure (x,y) is set */ } /* Load a variable-resolution BSDF tree from an open XML file */ @@ -1419,7 +1422,7 @@ SDloadTre(SDData *sd, ezxml_t wtl) } /* Variable resolution BSDF methods */ -SDFunc SDhandleTre = { +const SDFunc SDhandleTre = { &SDgetTreBSDF, &SDqueryTreProjSA, &SDgetTreCDist,