Use named indices with wind tree program
This commit is contained in:
parent
7176cbc0af
commit
881949a5d7
1 changed files with 59 additions and 19 deletions
|
@ -83,9 +83,12 @@ static const char* WindTreeVPCodeEnd=
|
|||
class CVertexProgramWindTree : public CVertexProgramLighted
|
||||
{
|
||||
public:
|
||||
class CIdx
|
||||
struct CIdx
|
||||
{
|
||||
|
||||
uint ProgramConstants[3];
|
||||
uint WindLevel1;
|
||||
uint WindLevel2[4];
|
||||
uint WindLevel3[4];
|
||||
};
|
||||
CVertexProgramWindTree(uint numPls, bool specular, bool normalize);
|
||||
virtual ~CVertexProgramWindTree() { };
|
||||
|
@ -120,6 +123,8 @@ CVertexProgramWindTree::CVertexProgramWindTree(uint numPls, bool specular, bool
|
|||
source->DisplayName = NLMISC::toString("nelvp/MeshVPWindTree/%i/%s/%s", numPls, specular ? "spec" : "nospec", normalize ? "normalize" : "nonormalize");
|
||||
source->Profile = CVertexProgram::nelvp;
|
||||
source->setSource(vpCode);
|
||||
source->ParamIndices["modelViewProjection"] = 0;
|
||||
source->ParamIndices["fog"] = 6;
|
||||
addSource(source);
|
||||
}
|
||||
|
||||
|
@ -129,6 +134,25 @@ CVertexProgramWindTree::CVertexProgramWindTree(uint numPls, bool specular, bool
|
|||
void CVertexProgramWindTree::buildInfo()
|
||||
{
|
||||
CVertexProgramLighted::buildInfo();
|
||||
if (profile() == nelvp)
|
||||
{
|
||||
m_Idx.ProgramConstants[0] = 8;
|
||||
m_Idx.ProgramConstants[1] = 9;
|
||||
m_Idx.ProgramConstants[2] = 10;
|
||||
m_Idx.WindLevel1 = 15;
|
||||
m_Idx.WindLevel2[0] = 16;
|
||||
m_Idx.WindLevel2[1] = 17;
|
||||
m_Idx.WindLevel2[2] = 18;
|
||||
m_Idx.WindLevel2[3] = 19;
|
||||
m_Idx.WindLevel3[0] = 20;
|
||||
m_Idx.WindLevel3[1] = 21;
|
||||
m_Idx.WindLevel3[2] = 22;
|
||||
m_Idx.WindLevel3[3] = 23;
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO_VP_GLSL
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -250,21 +274,27 @@ inline void CMeshVPWindTree::setupPerMesh(IDriver *driver, CScene *scene)
|
|||
}
|
||||
}
|
||||
|
||||
CVertexProgramWindTree *program = _ActiveVertexProgram;
|
||||
nlassert(program);
|
||||
|
||||
// Setup common constants for each instances.
|
||||
// c[8] take useful constants.
|
||||
static float ct8[4]= {0, 1, 0.5f, 2};
|
||||
driver->setConstant(8, 1, ct8);
|
||||
driver->setUniform4f(IDriver::VertexProgram, program->idx().ProgramConstants[0],
|
||||
0, 1, 0.5f, 2);
|
||||
// c[9] take other useful constants.
|
||||
static float ct9[4]= {3.f, 0.f, -1.f, -2.f};
|
||||
driver->setConstant(9, 1, ct9);
|
||||
driver->setUniform4f(IDriver::VertexProgram, program->idx().ProgramConstants[1],
|
||||
3.f, 0.f, -1.f, -2.f);
|
||||
// c[10] take Number of phase (4) for level2 and 3. -0.01 to avoid int value == 4.
|
||||
static float ct10[4]= {4-0.01f, 0, 0, 0};
|
||||
driver->setConstant(10, 1, ct10);
|
||||
driver->setUniform4f(IDriver::VertexProgram, program->idx().ProgramConstants[2],
|
||||
4-0.01f, 0, 0, 0);
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
inline void CMeshVPWindTree::setupPerInstanceConstants(IDriver *driver, CScene *scene, CMeshBaseInstance *mbi, const NLMISC::CMatrix &invertedModelMat)
|
||||
{
|
||||
CVertexProgramWindTree *program = _ActiveVertexProgram;
|
||||
nlassert(program);
|
||||
|
||||
// get instance info
|
||||
float instancePhase= mbi->_VPWindTreePhase;
|
||||
|
||||
|
@ -285,16 +315,18 @@ inline void CMeshVPWindTree::setupPerInstanceConstants(IDriver *driver, CScene
|
|||
setupLighting(scene, mbi, invertedModelMat);
|
||||
|
||||
// c[0..3] take the ModelViewProjection Matrix. After setupModelMatrix();
|
||||
driver->setConstantMatrix(0, IDriver::ModelViewProjection, IDriver::Identity);
|
||||
driver->setUniformMatrix(IDriver::VertexProgram, program->getUniformIndex(CGPUProgramIndex::ModelViewProjection),
|
||||
IDriver::ModelViewProjection, IDriver::Identity);
|
||||
// c[4..7] take the ModelView Matrix. After setupModelMatrix();00
|
||||
driver->setConstantFog(6);
|
||||
driver->setUniformFog(IDriver::VertexProgram, program->getUniformIndex(CGPUProgramIndex::Fog));
|
||||
|
||||
|
||||
// c[15] take Wind of level 0.
|
||||
float f;
|
||||
f= _CurrentTime[0] + instancePhase;
|
||||
f= speedCos(f) + Bias[0];
|
||||
driver->setConstant(15, maxDeltaPosOS[0]*f );
|
||||
driver->setUniform3f(IDriver::VertexProgram, program->idx().WindLevel1,
|
||||
maxDeltaPosOS[0]*f );
|
||||
|
||||
|
||||
// c[16-19] take Wind of level 1.
|
||||
|
@ -302,16 +334,20 @@ inline void CMeshVPWindTree::setupPerInstanceConstants(IDriver *driver, CScene
|
|||
float instTime1= _CurrentTime[1] + instancePhase;
|
||||
// phase 0.
|
||||
f= speedCos( instTime1+0 ) + Bias[1];
|
||||
driver->setConstant(16+0, maxDeltaPosOS[1]*f);
|
||||
driver->setUniform3f(IDriver::VertexProgram, program->idx().WindLevel2[0],
|
||||
maxDeltaPosOS[1]*f);
|
||||
// phase 1.
|
||||
f= speedCos( instTime1+0.25f ) + Bias[1];
|
||||
driver->setConstant(16+1, maxDeltaPosOS[1]*f);
|
||||
driver->setUniform3f(IDriver::VertexProgram, program->idx().WindLevel2[1],
|
||||
maxDeltaPosOS[1]*f);
|
||||
// phase 2.
|
||||
f= speedCos( instTime1+0.50f ) + Bias[1];
|
||||
driver->setConstant(16+2, maxDeltaPosOS[1]*f);
|
||||
driver->setUniform3f(IDriver::VertexProgram, program->idx().WindLevel2[2],
|
||||
maxDeltaPosOS[1]*f);
|
||||
// phase 3.
|
||||
f= speedCos( instTime1+0.75f ) + Bias[1];
|
||||
driver->setConstant(16+3, maxDeltaPosOS[1]*f);
|
||||
driver->setUniform3f(IDriver::VertexProgram, program->idx().WindLevel2[3],
|
||||
maxDeltaPosOS[1]*f);
|
||||
|
||||
|
||||
// c[20, 23] take Wind of level 2.
|
||||
|
@ -319,16 +355,20 @@ inline void CMeshVPWindTree::setupPerInstanceConstants(IDriver *driver, CScene
|
|||
float instTime2= _CurrentTime[2] + instancePhase;
|
||||
// phase 0.
|
||||
f= speedCos( instTime2+0 ) + Bias[2];
|
||||
driver->setConstant(20+0, maxDeltaPosOS[2]*f);
|
||||
driver->setUniform3f(IDriver::VertexProgram, program->idx().WindLevel3[0],
|
||||
maxDeltaPosOS[2]*f);
|
||||
// phase 1.
|
||||
f= speedCos( instTime2+0.25f ) + Bias[2];
|
||||
driver->setConstant(20+1, maxDeltaPosOS[2]*f);
|
||||
driver->setUniform3f(IDriver::VertexProgram, program->idx().WindLevel3[1],
|
||||
maxDeltaPosOS[2]*f);
|
||||
// phase 2.
|
||||
f= speedCos( instTime2+0.50f ) + Bias[2];
|
||||
driver->setConstant(20+2, maxDeltaPosOS[2]*f);
|
||||
driver->setUniform3f(IDriver::VertexProgram, program->idx().WindLevel3[2],
|
||||
maxDeltaPosOS[2]*f);
|
||||
// phase 3.
|
||||
f= speedCos( instTime2+0.75f ) + Bias[2];
|
||||
driver->setConstant(20+3, maxDeltaPosOS[2]*f);
|
||||
driver->setUniform3f(IDriver::VertexProgram, program->idx().WindLevel3[3],
|
||||
maxDeltaPosOS[2]*f);
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
|
|
Loading…
Reference in a new issue