--- ray/src/rt/m_bsdf.c 2011/02/18 00:40:25 2.1 +++ ray/src/rt/m_bsdf.c 2011/02/19 01:48:59 2.3 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: m_bsdf.c,v 2.1 2011/02/18 00:40:25 greg Exp $"; +static const char RCSid[] = "$Id: m_bsdf.c,v 2.3 2011/02/19 01:48:59 greg Exp $"; #endif /* * Shading for materials with BSDFs taken from XML data files @@ -8,7 +8,6 @@ static const char RCSid[] = "$Id: m_bsdf.c,v 2.1 2011/ #include "copyright.h" #include "ray.h" -#include "paths.h" #include "ambient.h" #include "source.h" #include "func.h" @@ -65,16 +64,6 @@ typedef struct { #define cvt_sdcolor(cv, svp) ccy2rgb(&(svp)->spec, (svp)->cieY, cv) -/* Convert error from BSDF library */ -static char * -cvt_sderr(SDError ec) -{ - if (!SDerrorDetail[0]) - return(strcpy(errmsg, SDerrorEnglish[ec])); - sprintf(errmsg, "%s: %s", SDerrorEnglish[ec], SDerrorDetail); - return(errmsg); -} - /* Compute source contribution for BSDF */ static void dirbsdf( @@ -84,7 +73,7 @@ dirbsdf( double omega /* light source size */ ) { - BSDFDAT *np = nnp; + BSDFDAT *np = (BSDFDAT *)nnp; SDError ec; SDValue sv; FVECT vout; @@ -123,7 +112,7 @@ dirbsdf( return; ec = SDevalBSDF(&sv, vout, np->vinc, np->sd); if (ec) - objerror(np->mp, USER, cvt_sderr(ec)); + objerror(np->mp, USER, transSDError(ec)); if (sv.cieY <= FTINY) /* not worth using? */ return; @@ -137,7 +126,7 @@ dirbsdf( scalecolor(ctmp2, dtmp); setcolor(ctmp1, 1.-dtmp, 1.-dtmp, 1.-dtmp); addcolor(ctmp1, ctmp2); - multcolor(ctmp, ctmp1); /* apply desaturated pattern */ + multcolor(ctmp, ctmp1); /* apply derated pattern */ dtmp = ldot * omega; } else { /* full pattern on transmission */ multcolor(ctmp, np->pr->pcol); @@ -174,7 +163,7 @@ sample_sdcomp(BSDFDAT *ndp, SDComponent *dcp, int usep : urand(ilhash(dimlist,ndims)+samplendx), dcp); if (ec) - objerror(ndp->mp, USER, cvt_sderr(ec)); + objerror(ndp->mp, USER, transSDError(ec)); /* zero component? */ if (bsv.cieY <= FTINY) break; @@ -196,11 +185,11 @@ sample_sdcomp(BSDFDAT *ndp, SDComponent *dcp, int usep ++nsent; /* Russian roulette victim */ continue; } - /* need to move origin? */ - sthick = (ndp->pr->rod > .0) ? -ndp->thick : ndp->thick; - if (sthick < .0 ^ vout[2] > .0) - VSUM(sr.rorg, sr.rorg, ndp->pr->ron, sthick); - + if (ndp->thick > FTINY) { /* need to move origin? */ + sthick = (ndp->pr->rod > .0) ? -ndp->thick : ndp->thick; + if (sthick < .0 ^ vout[2] > .0) + VSUM(sr.rorg, sr.rorg, ndp->pr->ron, sthick); + } rayvalue(&sr); /* send & evaluate sample */ multcolor(sr.rcol, sr.rcoef); addcolor(ndp->pr->rcol, sr.rcol); @@ -236,7 +225,7 @@ sample_sdf(BSDFDAT *ndp, int sflags) return(0); /* below sampling threshold? */ if (dfp->maxHemi <= specthresh+FTINY) { - if (dfp->maxHemi > FTINY) { /* XXX no color from BSDF! */ + if (dfp->maxHemi > FTINY) { /* XXX no color from BSDF */ double d = SDdirectHemi(ndp->vinc, sflags, ndp->sd); COLOR ctmp; if (sflags == SDsampSpT) { @@ -273,22 +262,8 @@ m_bsdf(OBJREC *m, RAY *r) (m->oargs.nfargs % 3)) objerror(m, USER, "bad # arguments"); - SDerrorDetail[0] = '\0'; /* get BSDF data */ - nd.sd = SDgetCache(m->oargs.sarg[1]); - if (nd.sd == NULL) - error(SYSTEM, "out of memory in m_bsdf"); - if (!SDisLoaded(nd.sd)) { - char *pname = getpath(m->oargs.sarg[1], getrlibpath(), R_OK); - if (pname == NULL) { - sprintf(errmsg, "cannot find BSDF file \"%s\"", - m->oargs.sarg[1]); - objerror(m, USER, errmsg); - } - ec = SDloadFile(nd.sd, pname); - if (ec) - objerror(m, USER, cvt_sderr(ec)); - SDretainSet = SDretainAll; - } + /* get BSDF data */ + nd.sd = loadBSDF(m->oargs.sarg[1]); /* load cal file */ mf = getfunc(m, 5, 0x1d, 1); /* get thickness */ @@ -297,15 +272,14 @@ m_bsdf(OBJREC *m, RAY *r) nd.thick = .0; /* check shadow */ if (r->crtype & SHADOW) { - SDfreeCache(nd.sd); - if (nd.thick > FTINY && nd.sd->tf != NULL && - nd.sd->tf->maxHemi > FTINY) + if ((nd.thick > FTINY) & (nd.sd->tf != NULL)) raytrans(r); /* pass-through */ + SDfreeCache(nd.sd); return(1); /* else shadow */ } /* check unscattered ray */ - if (!(r->crtype & (SPECULAR|AMBIENT)) && nd.thick > FTINY && - nd.sd->tf != NULL && nd.sd->tf->maxHemi > FTINY) { + if (!(r->crtype & (SPECULAR|AMBIENT)) && + (nd.thick > FTINY) & (nd.sd->tf != NULL)) { SDfreeCache(nd.sd); raytrans(r); /* pass-through */ return(1); @@ -320,10 +294,8 @@ m_bsdf(OBJREC *m, RAY *r) m->oargs.farg[2]); } else { if (m->oargs.nfargs < 6) { /* check invisible backside */ - if (!backvis && (nd.sd->rb == NULL || - nd.sd->rb->maxHemi <= FTINY) && - (nd.sd->tf == NULL || - nd.sd->tf->maxHemi <= FTINY)) { + if (!backvis && (nd.sd->rb == NULL) & + (nd.sd->tf == NULL)) { SDfreeCache(nd.sd); raytrans(r); return(1); @@ -373,7 +345,7 @@ m_bsdf(OBJREC *m, RAY *r) if (!ec) ec = SDinvXform(nd.fromloc, nd.toloc); if (ec) { - objerror(m, WARNING, cvt_sderr(ec)); + objerror(m, WARNING, transSDError(ec)); SDfreeCache(nd.sd); return(1); }