// Shave and a Haircut // (c) 2019 Epic Games // US Patent 6720962 /********************************************************************** *< FILE: shaveVrayTriShadeable.cpp -- implementation file DESCRIPTION: Used to shade the instanced surface CREATED BY: Vladimir Dubovoy HISTORY: created 13-05-2010 *> **********************************************************************/ #include "shaveVrayTriShadeable.h" shaveVrayTriShadeable::shaveVrayTriShadeable(shaveVrayTriVoxelPrim *hair) { _prim() = hair; } shaveVrayTriShadeable::~shaveVrayTriShadeable() { freeBSDFpool(); } /* | from Shadeable */ void shaveVrayTriShadeable::shade(VR::VRayContext &rc) { BSDFShadeable::shade(rc); if (VUtils::hasNonFiniteLanes(rc.mtlresult.color)) { rc.mtlresult.color.makeZero(); } //#ifdef USE_WHITE_TRI_BRDF // VR::Color c = VR::Color(1.0f, 1.0f, 1.0f); // rc.mtlresult.color *= c; //#else // BSDFShadeable::shade(rc); //#endif //rc.mtlresult.color.r = 1.0f; //rc.mtlresult.color.g = 0.0f; //rc.mtlresult.color.b = 0.0f; //rc.mtlresult.alpha.r = 0.0f; //rc.mtlresult.alpha.g = 0.0f; //rc.mtlresult.alpha.b = 0.0f; //rc.mtlresult.transp.r = 0.f; //rc.mtlresult.transp.g = 0.f; //rc.mtlresult.transp.b = 0.f; //rc.mtlresult.alphaTransp.r = 0.0f; //rc.mtlresult.alphaTransp.g = 0.0f; //rc.mtlresult.alphaTransp.b = 0.0f; } /* | from Shadeable */ tchar* shaveVrayTriShadeable::getName(VR::VRayContext &rc) { return const_cast("shaveVrayTriShadeable"); } VR::BSDFSampler* shaveVrayTriShadeable::newBSDF (const VR::VRayContext &rc, VR::BSDFFlags flags) { #ifdef USE_WHITE_TRI_BRDF VR::WhiteBRDF *bsdf = _bsdfPool().newBRDF(rc); return bsdf; #else #error not implemented //shaveVrayBaseBSDF *bsdf = _bsdfPool().newBRDF(rc); //if (!bsdf) // return NULL; //int strandIdx = rc.rayresult.faceIndex; //VR::Color diffCol = VR::Color(0.0f, 1.0f, 0.0f); //just green to see if somthing goes wrong //int segmentIdx=(int) rc.rayresult.extraf; //if(prim()->IsColorConst(strandIdx)) // prim()->GetRootColor(strandIdx,diffCol); //else // prim()->GetInterpColor(segmentIdx, strandIdx,diffCol); //VR::Color specCol = VR::Color(1.0f, 1.0f, 1.0f); //float opacity = 1.0f; //if(prim()->GetTipFade()) // opacity = prim()->GetInterpOpacity(segmentIdx,strandIdx); //else // opacity = prim()->GetOpacity(strandIdx); // ////transparency //float t=1.0f-opacity; //VR::Color trsp = VR::Color(t, t, t); ////ambient color [not used yet] //VR::Color ambientCol = prim()->GetAmbient(); ////abient/diffuse factor //float ambDiff = prim()->GetAmbDiff(strandIdx); ////glossines //float gloss = prim()->GetGlossiness(strandIdx); //float splvl = prim()->GetSpecLevel(strandIdx); //VR::Vector hairDir=prim()->GetHairDir(rc.rayresult.origPoint, segmentIdx, strandIdx); //bsdf->init(rc,specCol,diffCol,ambientCol,ambDiff,splvl,gloss,0,trsp, hairDir, t); //return bsdf; #endif } void shaveVrayTriShadeable::deleteBSDF(const VR::VRayContext &rc, VR::BSDFSampler *bsdf) { if(!bsdf) return; #ifdef USE_WHITE_TRI_BRDF VR::WhiteBRDF *dbsdf = static_cast(bsdf); #else #error not implemented //shaveVrayBaseBSDF* dbsdf = static_cast(bsdf); #endif _bsdfPool().deleteBRDF(rc, dbsdf); } #if defined(VRAY40) int shaveVrayTriShadeable::getBSDFFlags() { return VR::bsdfFlag_none; } #endif void shaveVrayTriShadeable::initBSDFpool(VR::VRayCore *vray) { const VR::VRaySequenceData &sdata=vray->getSequenceData(); _bsdfPool().init(sdata.maxRenderThreads); } void shaveVrayTriShadeable::freeBSDFpool() { _bsdfPool().freeMem(); }