--- ray/src/common/bsdf_t.c 2015/04/05 06:02:43 3.38 +++ ray/src/common/bsdf_t.c 2015/04/25 19:08:29 3.42 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: bsdf_t.c,v 3.38 2015/04/05 06:02:43 greg Exp $"; +static const char RCSid[] = "$Id: bsdf_t.c,v 3.42 2015/04/25 19:08:29 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); @@ -1194,8 +1194,8 @@ subtract_min_Y(SDNode *st) } else /* anisotropic covers entire tree */ vmin = SDgetTreMin(st); - if (vmin <= FTINY) - return .0; + if (vmin <= .01/M_PI) + return .0; /* not worth bothering about */ SDsubtractTreVal(st, vmin); @@ -1314,24 +1314,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 <= 1e-5) { - *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 +1354,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 */