diff --git a/code/nel/include/nel/3d/meshvp_wind_tree.h b/code/nel/include/nel/3d/meshvp_wind_tree.h index a19f6b43d..b33ac7587 100644 --- a/code/nel/include/nel/3d/meshvp_wind_tree.h +++ b/code/nel/include/nel/3d/meshvp_wind_tree.h @@ -24,6 +24,7 @@ namespace NL3D { +class CVertexProgramWindTree; // *************************************************************************** /** @@ -35,6 +36,7 @@ namespace NL3D { class CMeshVPWindTree : public IMeshVertexProgram { public: + friend class CVertexProgramWindTree; enum {HrcDepth= 3}; @@ -112,7 +114,7 @@ private: /** The 16 versions: Specular or not (0 or 2), + normalize normal or not (0 or 1). * All multiplied by 4, because support from 0 to 3 pointLights activated. (0.., 4.., 8.., 12..) */ - static NLMISC::CSmartPtr _VertexProgram[NumVp]; + static NLMISC::CSmartPtr _VertexProgram[NumVp]; // WindTree Time for this mesh param setup. Stored in mesh because same for all instances. float _CurrentTime[HrcDepth]; diff --git a/code/nel/src/3d/meshvp_wind_tree.cpp b/code/nel/src/3d/meshvp_wind_tree.cpp index 85a5550e8..ca7964ac1 100644 --- a/code/nel/src/3d/meshvp_wind_tree.cpp +++ b/code/nel/src/3d/meshvp_wind_tree.cpp @@ -35,11 +35,11 @@ namespace NL3D // *************************************************************************** // Light VP fragment constants start at 24 -static const uint VPLightConstantStart= 24; +static const uint VPLightConstantStart = 24; // *************************************************************************** -NLMISC::CSmartPtr CMeshVPWindTree::_VertexProgram[CMeshVPWindTree::NumVp]; +NLMISC::CSmartPtr CMeshVPWindTree::_VertexProgram[CMeshVPWindTree::NumVp]; static const char* WindTreeVPCodeWave= "!!VP1.0 \n\ @@ -79,6 +79,59 @@ static const char* WindTreeVPCodeEnd= END \n\ "; + +class CVertexProgramWindTree : public CVertexProgramLighted +{ +public: + class CIdx + { + + }; + CVertexProgramWindTree(uint numPls, bool specular, bool normalize); + virtual ~CVertexProgramWindTree() { }; + virtual void buildInfo(); + const CIdx &idx() const { return m_Idx; } + + bool PerMeshSetup; + +private: + CIdx m_Idx; + +}; + +CVertexProgramWindTree::CVertexProgramWindTree(uint numPls, bool specular, bool normalize) +{ + // lighted settings + m_FeaturesLighted.SupportSpecular = specular; + m_FeaturesLighted.NumActivePointLights = numPls; + m_FeaturesLighted.Normalize = normalize; + m_FeaturesLighted.CtStartNeLVP = VPLightConstantStart; + + // constants cache + PerMeshSetup = false; + + // nelvp + { + std::string vpCode = std::string(WindTreeVPCodeWave) + + CRenderTrav::getLightVPFragmentNeLVP(numPls, VPLightConstantStart, specular, normalize) + + WindTreeVPCodeEnd; + + CSource *source = new CSource(); + source->DisplayName = NLMISC::toString("nelvp/MeshVPWindTree/%i/%s/%s", numPls, specular ? "spec" : "nospec", normalize ? "normalize" : "nonormalize"); + source->Profile = CVertexProgram::nelvp; + source->setSource(vpCode); + addSource(source); + } + + // TODO_VP_GLSL +} + +void CVertexProgramWindTree::buildInfo() +{ + CVertexProgramLighted::buildInfo(); +} + + // *************************************************************************** float CMeshVPWindTree::speedCos(float angle) { @@ -142,9 +195,6 @@ void CMeshVPWindTree::initInstance(CMeshBaseInstance *mbi) // All vpcode and begin() written for HrcDepth==3 nlassert(HrcDepth==3); - // combine fragments. - string vpCode; - // For all possible VP. for(uint i=0;i 0. */ - _LastMBRIdVP= 0; + _LastMBRIdVP = 0; // activate VP. driver->activeVertexProgram(_VertexProgram[_LastMBRIdVP]); + + // precompute mesh + setupPerMesh(driver, scene); + _VertexProgram[_LastMBRIdVP]->PerMeshSetup = true; } // *************************************************************************** void CMeshVPWindTree::beginMBRInstance(IDriver *driver, CScene *scene, CMeshBaseInstance *mbi, const NLMISC::CMatrix &invertedModelMat) { - // setup first constants for this instance - setupPerInstanceConstants(driver, scene, mbi, invertedModelMat); - // Get how many pointLights are setuped now. nlassert(scene != NULL); CRenderTrav *renderTrav= &scene->getRenderTrav(); @@ -403,16 +447,26 @@ void CMeshVPWindTree::beginMBRInstance(IDriver *driver, CScene *scene, CMeshBase clamp(numPls, 0, CRenderTrav::MaxVPLight-1); // Enable normalize only if requested by user. Because lighting don't manage correct "scale lighting" - uint idVP= (SpecularLighting?2:0) + (driver->isForceNormalize()?1:0) ; + uint idVP = (SpecularLighting?2:0) + (driver->isForceNormalize()?1:0) ; // correct VP id for correct number of pls. - idVP= numPls*4 + idVP; + idVP = numPls*4 + idVP; // re-activate VP if idVP different from last setup - if( idVP!=_LastMBRIdVP ) + if(idVP != _LastMBRIdVP) { _LastMBRIdVP= idVP; driver->activeVertexProgram(_VertexProgram[_LastMBRIdVP]); + + if (!_VertexProgram[_LastMBRIdVP]->PerMeshSetup) + { + // precompute mesh + setupPerMesh(driver, scene); + _VertexProgram[_LastMBRIdVP]->PerMeshSetup = true; + } } + + // setup first constants for this instance + setupPerInstanceConstants(driver, scene, mbi, invertedModelMat); } // ***************************************************************************