Updated wind tree program container
This commit is contained in:
parent
ba945f30a8
commit
a0fbb152ee
2 changed files with 78 additions and 22 deletions
|
@ -24,6 +24,7 @@
|
||||||
|
|
||||||
namespace NL3D {
|
namespace NL3D {
|
||||||
|
|
||||||
|
class CVertexProgramWindTree;
|
||||||
|
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
/**
|
/**
|
||||||
|
@ -35,6 +36,7 @@ namespace NL3D {
|
||||||
class CMeshVPWindTree : public IMeshVertexProgram
|
class CMeshVPWindTree : public IMeshVertexProgram
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
friend class CVertexProgramWindTree;
|
||||||
|
|
||||||
enum {HrcDepth= 3};
|
enum {HrcDepth= 3};
|
||||||
|
|
||||||
|
@ -112,7 +114,7 @@ private:
|
||||||
/** The 16 versions: Specular or not (0 or 2), + normalize normal or not (0 or 1).
|
/** 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..)
|
* All multiplied by 4, because support from 0 to 3 pointLights activated. (0.., 4.., 8.., 12..)
|
||||||
*/
|
*/
|
||||||
static NLMISC::CSmartPtr<CVertexProgram> _VertexProgram[NumVp];
|
static NLMISC::CSmartPtr<CVertexProgramWindTree> _VertexProgram[NumVp];
|
||||||
|
|
||||||
// WindTree Time for this mesh param setup. Stored in mesh because same for all instances.
|
// WindTree Time for this mesh param setup. Stored in mesh because same for all instances.
|
||||||
float _CurrentTime[HrcDepth];
|
float _CurrentTime[HrcDepth];
|
||||||
|
|
|
@ -35,11 +35,11 @@ namespace NL3D
|
||||||
|
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
// Light VP fragment constants start at 24
|
// Light VP fragment constants start at 24
|
||||||
static const uint VPLightConstantStart= 24;
|
static const uint VPLightConstantStart = 24;
|
||||||
|
|
||||||
|
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
NLMISC::CSmartPtr<CVertexProgram> CMeshVPWindTree::_VertexProgram[CMeshVPWindTree::NumVp];
|
NLMISC::CSmartPtr<CVertexProgramWindTree> CMeshVPWindTree::_VertexProgram[CMeshVPWindTree::NumVp];
|
||||||
|
|
||||||
static const char* WindTreeVPCodeWave=
|
static const char* WindTreeVPCodeWave=
|
||||||
"!!VP1.0 \n\
|
"!!VP1.0 \n\
|
||||||
|
@ -79,6 +79,59 @@ static const char* WindTreeVPCodeEnd=
|
||||||
END \n\
|
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)
|
float CMeshVPWindTree::speedCos(float angle)
|
||||||
{
|
{
|
||||||
|
@ -142,9 +195,6 @@ void CMeshVPWindTree::initInstance(CMeshBaseInstance *mbi)
|
||||||
// All vpcode and begin() written for HrcDepth==3
|
// All vpcode and begin() written for HrcDepth==3
|
||||||
nlassert(HrcDepth==3);
|
nlassert(HrcDepth==3);
|
||||||
|
|
||||||
// combine fragments.
|
|
||||||
string vpCode;
|
|
||||||
|
|
||||||
// For all possible VP.
|
// For all possible VP.
|
||||||
for(uint i=0;i<NumVp;i++)
|
for(uint i=0;i<NumVp;i++)
|
||||||
{
|
{
|
||||||
|
@ -153,12 +203,8 @@ void CMeshVPWindTree::initInstance(CMeshBaseInstance *mbi)
|
||||||
bool normalize= (i&1)!=0;
|
bool normalize= (i&1)!=0;
|
||||||
bool specular= (i&2)!=0;
|
bool specular= (i&2)!=0;
|
||||||
|
|
||||||
// combine fragments
|
// combine
|
||||||
vpCode= string(WindTreeVPCodeWave)
|
_VertexProgram[i] = new CVertexProgramWindTree(numPls, normalize, specular);
|
||||||
+ CRenderTrav::getLightVPFragmentNeLVP(numPls, VPLightConstantStart, specular, normalize)
|
|
||||||
+ WindTreeVPCodeEnd;
|
|
||||||
_VertexProgram[i] = new CVertexProgram(vpCode.c_str());
|
|
||||||
// TODO_VP_GLSL
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -378,24 +424,22 @@ bool CMeshVPWindTree::isMBRVpOk(IDriver *driver) const
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
void CMeshVPWindTree::beginMBRMesh(IDriver *driver, CScene *scene)
|
void CMeshVPWindTree::beginMBRMesh(IDriver *driver, CScene *scene)
|
||||||
{
|
{
|
||||||
// precompute mesh
|
|
||||||
setupPerMesh(driver, scene);
|
|
||||||
|
|
||||||
/* Since need a VertexProgram Activation before activeVBHard, activate a default one
|
/* Since need a VertexProgram Activation before activeVBHard, activate a default one
|
||||||
bet the common one will be "NoPointLight, NoSpecular, No ForceNormalize" => 0.
|
bet the common one will be "NoPointLight, NoSpecular, No ForceNormalize" => 0.
|
||||||
*/
|
*/
|
||||||
_LastMBRIdVP= 0;
|
_LastMBRIdVP = 0;
|
||||||
|
|
||||||
// activate VP.
|
// activate VP.
|
||||||
driver->activeVertexProgram(_VertexProgram[_LastMBRIdVP]);
|
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)
|
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.
|
// Get how many pointLights are setuped now.
|
||||||
nlassert(scene != NULL);
|
nlassert(scene != NULL);
|
||||||
CRenderTrav *renderTrav= &scene->getRenderTrav();
|
CRenderTrav *renderTrav= &scene->getRenderTrav();
|
||||||
|
@ -403,16 +447,26 @@ void CMeshVPWindTree::beginMBRInstance(IDriver *driver, CScene *scene, CMeshBase
|
||||||
clamp(numPls, 0, CRenderTrav::MaxVPLight-1);
|
clamp(numPls, 0, CRenderTrav::MaxVPLight-1);
|
||||||
|
|
||||||
// Enable normalize only if requested by user. Because lighting don't manage correct "scale lighting"
|
// 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.
|
// 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
|
// re-activate VP if idVP different from last setup
|
||||||
if( idVP!=_LastMBRIdVP )
|
if(idVP != _LastMBRIdVP)
|
||||||
{
|
{
|
||||||
_LastMBRIdVP= idVP;
|
_LastMBRIdVP= idVP;
|
||||||
driver->activeVertexProgram(_VertexProgram[_LastMBRIdVP]);
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
|
|
Loading…
Reference in a new issue