--- ray/src/common/bsdf_m.c 2015/04/08 02:41:02 3.32 +++ ray/src/common/bsdf_m.c 2018/05/10 22:55:35 3.38 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: bsdf_m.c,v 3.32 2015/04/08 02:41:02 greg Exp $"; +static const char RCSid[] = "$Id: bsdf_m.c,v 3.38 2018/05/10 22:55:35 greg Exp $"; #endif /* * bsdf_m.c @@ -151,8 +151,8 @@ fo_getvec(FVECT v, double ndxr, void *p) for (li = 0; ndx >= ab->lat[li].nphis; li++) ndx -= ab->lat[li].nphis; SDmultiSamp(rx, 2, randX); - d = (1. - randX)*sq(cos(M_PI/180.*ab->lat[li].tmin)) + - randX*sq(cos(M_PI/180.*ab->lat[li+1].tmin)); + d = (1. - rx[0])*sq(cos(M_PI/180.*ab->lat[li].tmin)) + + rx[0]*sq(cos(M_PI/180.*ab->lat[li+1].tmin)); v[2] = d = sqrt(d); /* cos(pol) */ azi = 2.*M_PI*(ndx + rx[1] - .5)/ab->lat[li].nphis; d = sqrt(1. - d*d); /* sin(pol) */ @@ -191,6 +191,7 @@ fo_getndx(const FVECT v, void *p) double io_getohm(int ndx, void *p) { + static void *last_p = NULL; static int last_li = -1; static double last_ohm; ANGLE_BASIS *ab = (ANGLE_BASIS *)p; @@ -201,8 +202,9 @@ io_getohm(int ndx, void *p) return -1.; for (li = 0; ndx >= ab->lat[li].nphis; li++) ndx -= ab->lat[li].nphis; - if (li == last_li) /* cached latitude? */ + if ((p == last_p) & (li == last_li)) /* cached latitude? */ return last_ohm; + last_p = p; last_li = li; theta = M_PI/180. * ab->lat[li].tmin; theta1 = M_PI/180. * ab->lat[li+1].tmin; @@ -298,7 +300,7 @@ mBSDF_color(float coef[], const SDMat *dp, int i, int if (dp->chroma == NULL) return 1; /* grayscale */ - c_decodeChroma(&cxy, dp->chroma[o*dp->ninc + i]); + c_decodeChroma(&cxy, mBSDF_chroma(dp,i,o)); c_toSharpRGB(&cxy, coef[0], coef); coef[0] *= mtx_RGB_coef[0]; coef[1] *= mtx_RGB_coef[1]; @@ -622,7 +624,7 @@ subtract_min(C_COLOR *cs, SDMat *sm) coef[c] = (coef[c] - min_coef[c]) / mtx_RGB_coef[c]; if (c_fromSharpRGB(coef, &cxy) > 1e-5) - sm->chroma[o*sm->ninc + i] = c_encodeChroma(&cxy); + mBSDF_chroma(sm,i,o) = c_encodeChroma(&cxy); mBSDF_value(sm,i,o) -= ymin; } /* return colored minimum */ @@ -647,8 +649,8 @@ extract_diffuse(SDValue *dv, SDSpectralDF *df) /* subtract minimum value */ dv->cieY = subtract_min(&dv->spec, (SDMat *)df->comp[0].dist); 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 */ return df; } @@ -849,6 +851,7 @@ SDgetMtxCDist(const FVECT inVec, SDComponent *sdc) reverse = 1; } cdlast = NULL; /* check for it in cache list */ + /* PLACE MUTEX LOCK HERE FOR THREAD-SAFE */ for (cd = (SDMatCDst *)sdc->cdList; cd != NULL; cdlast = cd, cd = cd->next) if (cd->indx == myCD.indx && (cd->calen == myCD.calen) & @@ -872,6 +875,7 @@ SDgetMtxCDist(const FVECT inVec, SDComponent *sdc) cd->next = (SDMatCDst *)sdc->cdList; sdc->cdList = (SDCDst *)cd; } + /* END MUTEX LOCK */ return (SDCDst *)cd; /* ready to go */ } @@ -904,7 +908,7 @@ SDsampMtxCDist(FVECT ioVec, double randX, const SDCDst } /* Fixed resolution BSDF methods */ -SDFunc SDhandleMtx = { +const SDFunc SDhandleMtx = { &SDgetMtxBSDF, &SDqueryMtxProjSA, &SDgetMtxCDist,