// Shave and a Haircut // (c) 2019 Epic Games // US Patent 6720962 /********************************************************************** *< FILE: shaveVrayShadeable.cpp -- implementation file ( HairVrShadeable.cpp ) DESCRIPTION: Used to shade a surface CREATED BY: Vladimir Dubovoy HISTORY: created 21-08-2008 ( as part of 3ds Max + VRay hair shaders) merged 31-03-2010 *> **********************************************************************/ #include "shaveVrayShadeable.h" #include "hairAPIvray.h" #include "shaveVrayPlugin.h" #include "shaveVrayInstance.h" #if (defined WIN32) ||(defined LINUX) ; #else #include "shaveVrayBaseBSDFPool.h" // I did not split it for osx yet #endif #include "shaveVraySharedFunctions.h" shaveVrayShadeable::shaveVrayShadeable(shaveVrayVoxelPrim *hair) { _prim() = hair; #ifdef USE_WHITE_BRDF ; #else _bsdfPool() = NULL; #if (defined WIN32) ||(defined LINUX) //_bsdfPool() = new shaveVrayBaseBSDFPool(); if(CreateShaveBSDFPool != NULL) { _bsdfPool() = CreateShaveBSDFPool(); } if(!bsdfPool()) { LOGMSG("SHADE","shaveVrayShadeable: can not create BSDF pool."); } #else //osx _bsdfPool() = new shaveVrayBaseBSDFPool(); #endif #endif } shaveVrayShadeable::~shaveVrayShadeable() { freeBSDFpool(); } /* | from Shadeable */ void shaveVrayShadeable::shade(VR::VRayContext &rc) { //no trace //if(rc.rayparams.diffuseLevel > 1) //{ // rc.mtlresult.makeOpaque(); // return; //} BSDFShadeable::shade(rc); //////just a test - no trace //// //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; //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; //float segmentOffset=rc.rayresult.bary[2]; //if(prim()->IsColorConst(strandIdx)) // prim()->GetRootColor(strandIdx,diffCol); //else // prim()->GetInterpColor(segmentIdx, strandIdx, segmentOffset, diffCol); //rc.mtlresult.color = diffCol; ////////////////////////////// #ifdef USE_WHITE_BRDF VR::Color diffCol = VR::Color(0.0f, 1.0f, 0.0f); //just green to see if somthing goes wrong int strandIdx, segmentIdx; float segmentOffset; shaveVrayGetHairParams(rc, strandIdx, segmentIdx, segmentOffset); if(prim()->IsColorConst(strandIdx)) prim()->GetRootColor(strandIdx,diffCol); else prim()->GetInterpColor(segmentIdx, strandIdx, segmentOffset, diffCol); rc.mtlresult.color *= diffCol; #endif } /* | from Shadeable */ tchar* shaveVrayShadeable::getName(VR::VRayContext &rc) { return const_cast("shaveVrayShadeable"); } VR::BSDFSampler* shaveVrayShadeable::newBSDF (const VR::VRayContext &rc, VR::BSDFFlags flags) { #ifdef USE_WHITE_BRDF VR::WhiteBRDF *bsdf = _bsdfPool().newBRDF(rc); return bsdf; #else //shaveVrayBaseBSDF* bsdf = _bsdfPool().newBRDF(rc); IShaveVrayBSDF* bsdf = NULL; if(bsdfPool()) { bsdf =_bsdfPool()->newBRDF(rc); } if (!bsdf) return NULL; VR::Color diffCol = VR::Color(0.0f, 1.0f, 0.0f); //just green to see if somthing goes wrong int strandIdx, segmentIdx; float segmentOffset; shaveVrayGetHairParams(rc, strandIdx, segmentIdx, segmentOffset); if(prim()->IsColorConst(strandIdx)) prim()->GetRootColor(strandIdx,diffCol); else prim()->GetInterpColor(segmentIdx, strandIdx, segmentOffset, diffCol); VR::Color specCol = VR::Color(1.0f, 1.0f, 1.0f); float opacity = 1.0f; //hair is opaque for GI prepass steps to speedup computations -- 08-11-2010 if(rc.rayparams.currentPass != RPASS_GI) if(rc.rayparams.currentPass != RPASS_LIGHTMAP) { if(prim()->GetTipFade()) opacity = prim()->GetInterpOpacity(segmentIdx, strandIdx, segmentOffset); 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); //specular tints VR::Color spCol = prim()->GetSpecTint(); VR::Color spCol2= prim()->GetSpecTint2(); // printf("spec_tint %f %f %f \n",spCol.r, spCol.g, spCol.b); // printf("spec_tint2 %f %f %f \n",spCol2.r, spCol2.g, spCol2.b); #if defined(VRAY30) || defined(VRAY40) VR::ShadeVec hairDir=prim()->getHairDir(rc); #else VR::ShadeVec hairDir=prim()->GetHairDir(rc.rayresult.origPoint, segmentIdx, strandIdx, segmentOffset); #endif shaveVrayInstance* inst = prim()->GetInstance(); //printf("inst get selfShadow %f\n",inst->GetSelfShadow());fflush(stdout); bsdf->init(rc,specCol,diffCol,ambientCol,spCol,spCol2,ambDiff,splvl,gloss,0,trsp, hairDir, t, inst->GetCameraVisibility(), inst->GetReflVisibility(), inst->GetRefrlVisibility(), inst->GetLightVisibility(), inst->GetGiVisibility(), inst->GetSelfShadow(), inst->GetRecvShadow()); return bsdf; #endif } void shaveVrayShadeable::deleteBSDF(const VR::VRayContext &rc, VR::BSDFSampler *bsdf) { if(!bsdf) return; #ifdef USE_WHITE_BRDF VR::WhiteBRDF *dbsdf = static_cast(bsdf); _bsdfPool().deleteBRDF(rc, dbsdf); #else //shaveVrayBaseBSDF* dbsdf = static_cast(bsdf); //_bsdfPool().deleteBRDF(rc, dbsdf); IShaveVrayBSDF* dbsdf = static_cast(bsdf); if(bsdfPool()) { _bsdfPool()->deleteBRDF(rc, dbsdf); } #endif } #if defined(VRAY40) int shaveVrayShadeable::getBSDFFlags() { return VR::bsdfFlag_none; } #endif void shaveVrayShadeable::initBSDFpool(VR::VRayCore *vray) { #ifdef USE_WHITE_BRDF const VR::VRaySequenceData &sdata=vray->getSequenceData(); _bsdfPool().init(sdata.maxRenderThreads); #else if(bsdfPool()) { _bsdfPool()->init(vray); } #endif } void shaveVrayShadeable::freeBSDFpool() { #ifdef USE_WHITE_BRDF _bsdfPool().freeMem(); #else if(bsdfPool()) { _bsdfPool()->freeMem(); } #endif }