--- ray/src/rt/m_bsdf.c 2020/07/09 17:32:31 2.61 +++ ray/src/rt/m_bsdf.c 2021/08/27 03:09:27 2.65 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: m_bsdf.c,v 2.61 2020/07/09 17:32:31 greg Exp $"; +static const char RCSid[] = "$Id: m_bsdf.c,v 2.65 2021/08/27 03:09:27 greg Exp $"; #endif /* * Shading for materials with BSDFs taken from XML data files @@ -17,7 +17,7 @@ static const char RCSid[] = "$Id: m_bsdf.c,v 2.61 2020 #include "pmapmat.h" /* - * Arguments to this material include optional diffuse colors. + * Arguments to this material include optional diffuse colors. * String arguments include the BSDF and function files. * For the MAT_BSDF type, a non-zero thickness causes the useful behavior * of translating transmitted rays this distance beneath the surface @@ -130,7 +130,6 @@ compute_through(BSDFDAT *ndp) {1.8, -1.8}, {-2.4, 0}, {0, 2.4}, {0, -2.4}, {2.4, 0}, }; - const double peak_over = 1.5; PEAKSAMP psamp[NDIR2CHECK]; SDSpectralDF *dfp; FVECT pdir; @@ -165,7 +164,7 @@ compute_through(BSDFDAT *ndp) } qsort(psamp, NDIR2CHECK, sizeof(PEAKSAMP), cmp_psamp); if (psamp[0].vy <= FTINY) - return; /* zero area */ + return; /* zero BTDF here */ setcolor(vpeak, 0, 0, 0); setcolor(vsurr, 0, 0, 0); vypeak = tomsum = tomsurr = 0; /* combine top unique values */ @@ -178,32 +177,31 @@ compute_through(BSDFDAT *ndp) SDqueryMin, ndp->sd); if (ec) goto baderror; - /* not really a peak? */ + + scalecolor(psamp[i].vcol, tomega); + /* not part of peak? */ if (tomega > 1.5*dfp->minProjSA || vypeak > 8.*psamp[i].vy*ns) { if (!i) return; /* abort */ - scalecolor(psamp[i].vcol, tomega); addcolor(vsurr, psamp[i].vcol); tomsurr += tomega; continue; } - scalecolor(psamp[i].vcol, tomega); addcolor(vpeak, psamp[i].vcol); tomsum += tomega; vypeak += psamp[i].vy; ++ns; } - if (vypeak*tomsurr < peak_over*bright(vsurr)*ns) - return; /* peak not peaky enough */ - if ((vypeak/ns - ndp->sd->tLamb.cieY*(1./PI))*tomsum <= .001) - return; /* < 0.1% transmission */ + if (tomsurr <= FTINY) /* no surround implies no peak */ + return; + if ((vypeak/ns - (ndp->vray[2] > 0 ? ndp->sd->tLambFront.cieY + : ndp->sd->tLambBack.cieY)*(1./PI))*tomsum < .0005) + return; /* < 0.05% transmission */ copycolor(ndp->cthru, vpeak); /* already scaled by omega */ multcolor(ndp->cthru, ndp->pr->pcol); /* modify by pattern */ - if (tomsurr > FTINY) { /* surround contribution? */ - scalecolor(vsurr, 1./tomsurr); /* this one is avg. BTDF */ - copycolor(ndp->cthru_surr, vsurr); - multcolor(ndp->cthru_surr, ndp->pr->pcol); - } + scalecolor(vsurr, 1./tomsurr); /* surround is avg. BTDF */ + copycolor(ndp->cthru_surr, vsurr); + multcolor(ndp->cthru_surr, ndp->pr->pcol); return; baderror: objerror(ndp->mp, USER, transSDError(ec)); @@ -255,11 +253,16 @@ direct_specular_OK(COLOR cval, FVECT ldir, double omeg return(0); /* all diffuse */ sv = ndp->sd->rLambBack; break; - default: + case 1: if ((ndp->sd->tf == NULL) & (ndp->sd->tb == NULL)) return(0); /* all diffuse */ - sv = ndp->sd->tLamb; + sv = ndp->sd->tLambFront; break; + case 2: + if ((ndp->sd->tf == NULL) & (ndp->sd->tb == NULL)) + return(0); /* all diffuse */ + sv = ndp->sd->tLambBack; + break; } if (sv.cieY > FTINY) { diffY = sv.cieY *= 1./PI; @@ -677,7 +680,7 @@ m_bsdf(OBJREC *m, RAY *r) SDfreeCache(nd.sd); return(1); } - /* diffuse reflectance */ + /* diffuse components */ if (hitfront) { cvt_sdcolor(nd.rdiff, &nd.sd->rLambFront); if (m->oargs.nfargs >= 3) { @@ -686,6 +689,7 @@ m_bsdf(OBJREC *m, RAY *r) m->oargs.farg[2]); addcolor(nd.rdiff, ctmp); } + cvt_sdcolor(nd.tdiff, &nd.sd->tLambFront); } else { cvt_sdcolor(nd.rdiff, &nd.sd->rLambBack); if (m->oargs.nfargs >= 6) { @@ -694,10 +698,9 @@ m_bsdf(OBJREC *m, RAY *r) m->oargs.farg[5]); addcolor(nd.rdiff, ctmp); } + cvt_sdcolor(nd.tdiff, &nd.sd->tLambBack); } - /* diffuse transmittance */ - cvt_sdcolor(nd.tdiff, &nd.sd->tLamb); - if (m->oargs.nfargs >= 9) { + if (m->oargs.nfargs >= 9) { /* add diffuse transmittance? */ setcolor(ctmp, m->oargs.farg[6], m->oargs.farg[7], m->oargs.farg[8]);