Use new program interface for water vertex program

This commit is contained in:
kaetemi 2013-09-10 02:07:16 +02:00
parent dd490a0cc4
commit 32288eabe8
3 changed files with 101 additions and 23 deletions

View file

@ -49,6 +49,29 @@ const NLMISC::CClassId WaveMakerModelClassId = NLMISC::CClassId(0x16da3356, 0x7
const uint WATER_VERTEX_HARD_SIZE = sizeof(float[3]); const uint WATER_VERTEX_HARD_SIZE = sizeof(float[3]);
const uint WATER_VERTEX_SOFT_SIZE = sizeof(float[5]); const uint WATER_VERTEX_SOFT_SIZE = sizeof(float[5]);
// VP Water No Wave
class CVertexProgramWaterVPNoWave : public CVertexProgram
{
public:
struct CIdx
{
uint BumpMap0Scale;
uint BumpMap0Offset;
uint BumpMap1Scale;
uint BumpMap1Offset;
uint ObserverHeight;
uint ScaleReflectedRay;
uint DiffuseMapVector0;
uint DiffuseMapVector1;
};
CVertexProgramWaterVPNoWave(bool diffuse);
virtual ~CVertexProgramWaterVPNoWave() { }
virtual void buildInfo();
inline const CIdx &idx() const { return m_Idx; }
private:
CIdx m_Idx;
bool m_Diffuse;
};
/** /**
* A water shape. * A water shape.
@ -256,8 +279,8 @@ private:
static NLMISC::CSmartPtr<CVertexProgram> _VertexProgramNoBump; static NLMISC::CSmartPtr<CVertexProgram> _VertexProgramNoBump;
static NLMISC::CSmartPtr<CVertexProgram> _VertexProgramNoBumpDiffuse; static NLMISC::CSmartPtr<CVertexProgram> _VertexProgramNoBumpDiffuse;
// //
static NLMISC::CSmartPtr<CVertexProgram> _VertexProgramNoWave; static NLMISC::CSmartPtr<CVertexProgramWaterVPNoWave> _VertexProgramNoWave;
static NLMISC::CSmartPtr<CVertexProgram> _VertexProgramNoWaveDiffuse; static NLMISC::CSmartPtr<CVertexProgramWaterVPNoWave> _VertexProgramNoWaveDiffuse;
}; };

View file

@ -903,15 +903,12 @@ void CWaterModel::setupMaterialNVertexShader(IDriver *drv, CWaterShape *shape, c
_WaterMat.setZWrite(true); _WaterMat.setZWrite(true);
_WaterMat.setShader(CMaterial::Water); _WaterMat.setShader(CMaterial::Water);
} }
const uint cstOffset = 5; // 4 places for the matrix
NLMISC::CVectorH cst[13];
//=========================// //=========================//
// setup Water material // // setup Water material //
//=========================// //=========================//
shape->initVertexProgram(); shape->initVertexProgram();
CVertexProgram *program = shape->_ColorMap ? CWaterShape::_VertexProgramNoWaveDiffuse : CWaterShape::_VertexProgramNoWave; CVertexProgramWaterVPNoWave *program = shape->_ColorMap ? CWaterShape::_VertexProgramNoWaveDiffuse : CWaterShape::_VertexProgramNoWave;
drv->activeVertexProgram(program); drv->activeVertexProgram(program);
// TODO_VP_MATERIAL
CWaterModel::_WaterMat.setTexture(0, shape->_BumpMap[0]); CWaterModel::_WaterMat.setTexture(0, shape->_BumpMap[0]);
CWaterModel::_WaterMat.setTexture(1, shape->_BumpMap[1]); CWaterModel::_WaterMat.setTexture(1, shape->_BumpMap[1]);
CWaterModel::_WaterMat.setTexture(3, shape->_ColorMap); CWaterModel::_WaterMat.setTexture(3, shape->_ColorMap);
@ -957,23 +954,21 @@ void CWaterModel::setupMaterialNVertexShader(IDriver *drv, CWaterShape *shape, c
{ {
// setup 2x3 matrix for lookup in diffuse map // setup 2x3 matrix for lookup in diffuse map
updateDiffuseMapMatrix(); updateDiffuseMapMatrix();
cst[11].set(_ColorMapMatColumn0.x, _ColorMapMatColumn1.x, 0, _ColorMapMatColumn0.x * obsPos.x + _ColorMapMatColumn1.x * obsPos.y + _ColorMapMatPos.x); drv->setUniform4f(IDriver::VertexProgram, program->idx().DiffuseMapVector0, _ColorMapMatColumn0.x, _ColorMapMatColumn1.x, 0, _ColorMapMatColumn0.x * obsPos.x + _ColorMapMatColumn1.x * obsPos.y + _ColorMapMatPos.x);
cst[12].set(_ColorMapMatColumn0.y, _ColorMapMatColumn1.y, 0, _ColorMapMatColumn0.y * obsPos.x + _ColorMapMatColumn1.y * obsPos.y + _ColorMapMatPos.y); drv->setUniform4f(IDriver::VertexProgram, program->idx().DiffuseMapVector1, _ColorMapMatColumn0.y, _ColorMapMatColumn1.y, 0, _ColorMapMatColumn0.y * obsPos.x + _ColorMapMatColumn1.y * obsPos.y + _ColorMapMatPos.y);
} }
/// set matrix /// temp
drv->setConstantMatrix(0, IDriver::ModelViewProjection, IDriver::Identity); // drv->setUniformMatrix(IDriver::VertexProgram, program->indices().ModelViewProjection, IDriver::ModelViewProjection, IDriver::Identity); // now set by setUniformDriver in setupMaterial
// drv->setUniformFog(IDriver::VertexProgram, program->indices().Fog); // now set by setUniformDriver in setupMaterial
// retrieve current time // retrieve current time
double date = scene->getCurrentTime(); double date = scene->getCurrentTime();
// set bumpmaps pos // set bumpmaps pos
cst[6].set(fmodf(obsPos.x * shape->_HeightMapScale[0].x, 1.f) + (float) fmod(date * shape->_HeightMapSpeed[0].x, 1), fmodf(shape->_HeightMapScale[0].y * obsPos.y, 1.f) + (float) fmod(date * shape->_HeightMapSpeed[0].y, 1), 0.f, 1.f); // bump map 0 offset drv->setUniform4f(IDriver::VertexProgram, program->idx().BumpMap0Offset, fmodf(obsPos.x * shape->_HeightMapScale[0].x, 1.f) + (float) fmod(date * shape->_HeightMapSpeed[0].x, 1), fmodf(shape->_HeightMapScale[0].y * obsPos.y, 1.f) + (float) fmod(date * shape->_HeightMapSpeed[0].y, 1), 0.f, 1.f); // bump map 0 offset
cst[5].set(shape->_HeightMapScale[0].x, shape->_HeightMapScale[0].y, 0, 0); // bump map 0 scale drv->setUniform4f(IDriver::VertexProgram, program->idx().BumpMap0Scale, shape->_HeightMapScale[0].x, shape->_HeightMapScale[0].y, 0, 0); // bump map 0 scale
cst[8].set(fmodf(shape->_HeightMapScale[1].x * obsPos.x, 1.f) + (float) fmod(date * shape->_HeightMapSpeed[1].x, 1), fmodf(shape->_HeightMapScale[1].y * obsPos.y, 1.f) + (float) fmod(date * shape->_HeightMapSpeed[1].y, 1), 0.f, 1.f); // bump map 1 offset drv->setUniform4f(IDriver::VertexProgram, program->idx().BumpMap1Offset, fmodf(shape->_HeightMapScale[1].x * obsPos.x, 1.f) + (float) fmod(date * shape->_HeightMapSpeed[1].x, 1), fmodf(shape->_HeightMapScale[1].y * obsPos.y, 1.f) + (float) fmod(date * shape->_HeightMapSpeed[1].y, 1), 0.f, 1.f); // bump map 1 offset
cst[7].set(shape->_HeightMapScale[1].x, shape->_HeightMapScale[1].y, 0, 0); // bump map 1 scale drv->setUniform4f(IDriver::VertexProgram, program->idx().BumpMap1Scale, shape->_HeightMapScale[1].x, shape->_HeightMapScale[1].y, 0, 0); // bump map 1 scale
cst[9].set(0, 0, obsPos.z - zHeight, 1.f); drv->setUniform4f(IDriver::VertexProgram, program->idx().ObserverHeight, 0, 0, obsPos.z - zHeight, 1.f);
cst[10].set(0.5f, 0.5f, 0.f, 1.f); // used to scale reflected ray into the envmap drv->setUniform4f(IDriver::VertexProgram, program->idx().ScaleReflectedRay, 0.5f, 0.5f, 0.f, 1.f); // used to scale reflected ray into the envmap
/// set all our constants in one call
drv->setConstant(cstOffset, sizeof(cst) / sizeof(cst[0]) - cstOffset, (float *) &cst[cstOffset]);
drv->setConstantFog(4);
} }
//================================================ //================================================

View file

@ -81,7 +81,67 @@ DP4 o[TEX3].x, v[0], c[11]; #compute uv for diffuse texture \n\
DP4 o[TEX3].y, v[0], c[12]; \n\ DP4 o[TEX3].y, v[0], c[12]; \n\
END"; END";
CVertexProgramWaterVPNoWave::CVertexProgramWaterVPNoWave(bool diffuse)
{
m_Diffuse = diffuse;
// nelvp
{
CSource *source = new CSource();
source->Profile = nelvp;
source->DisplayName = "WaterVPNoWave/nelvp";
source->Features.DriverFlags =
CGPUProgramFeatures::ModelViewProjection
| CGPUProgramFeatures::Fog;
source->ParamIndices["modelViewProjection"] = 0;
source->ParamIndices["fog"] = 4;
source->ParamIndices["bumpMap0Scale"] = 5;
source->ParamIndices["bumpMap0Offset"] = 6;
source->ParamIndices["bumpMap1Scale"] = 7;
source->ParamIndices["bumpMap1Offset"] = 8;
source->ParamIndices["observerHeight"] = 9;
source->ParamIndices["scaleReflectedRay"] = 10;
if (diffuse)
{
source->DisplayName += "/diffuse";
source->ParamIndices["diffuseMapVector0"] = 11;
source->ParamIndices["diffuseMapVector1"] = 12;
source->setSourcePtr(WaterVPNoWaveDiffuse);
}
else
{
source->setSourcePtr(WaterVPNoWave);
}
addSource(source);
}
// glsl330v
{
// TODO_VP_GLSL
// CSource *source = new CSource();
// source->Profile = glsl330v;
// source->DisplayName = "WaterVPNoWave/glsl330v";
// if (diffuse) source->DisplayName += "/diffuse";
// source->Features.DriverFlags =
// CGPUProgramFeatures::ModelViewProjection
// | CGPUProgramFeatures::Fog;
// source->setSource...
// addSource(source);
}
}
void CVertexProgramWaterVPNoWave::buildInfo()
{
m_Idx.BumpMap0Scale = getUniformIndex("bumpMap0Scale");
m_Idx.BumpMap0Offset = getUniformIndex("bumpMap0Offset");
m_Idx.BumpMap1Scale = getUniformIndex("bumpMap1Scale");
m_Idx.BumpMap1Offset = getUniformIndex("bumpMap1Offset");
m_Idx.ObserverHeight = getUniformIndex("observerHeight");
m_Idx.ScaleReflectedRay = getUniformIndex("scaleReflectedRay");
if (m_Diffuse)
{
m_Idx.DiffuseMapVector0 = getUniformIndex("diffuseMapVector0");
m_Idx.DiffuseMapVector1 = getUniformIndex("diffuseMapVector1");
}
}
//////////////// ////////////////
// WAVY WATER // // WAVY WATER //
@ -195,8 +255,8 @@ NLMISC::CSmartPtr<CVertexProgram> CWaterShape::_VertexProgramBump2Diffuse;
NLMISC::CSmartPtr<CVertexProgram> CWaterShape::_VertexProgramNoBump; NLMISC::CSmartPtr<CVertexProgram> CWaterShape::_VertexProgramNoBump;
NLMISC::CSmartPtr<CVertexProgram> CWaterShape::_VertexProgramNoBumpDiffuse; NLMISC::CSmartPtr<CVertexProgram> CWaterShape::_VertexProgramNoBumpDiffuse;
// water with no waves // water with no waves
NLMISC::CSmartPtr<CVertexProgram> CWaterShape::_VertexProgramNoWave; NLMISC::CSmartPtr<CVertexProgramWaterVPNoWave> CWaterShape::_VertexProgramNoWave;
NLMISC::CSmartPtr<CVertexProgram> CWaterShape::_VertexProgramNoWaveDiffuse; NLMISC::CSmartPtr<CVertexProgramWaterVPNoWave> CWaterShape::_VertexProgramNoWaveDiffuse;
/** Build a vertex program for water depending on requirements /** Build a vertex program for water depending on requirements
@ -331,8 +391,8 @@ void CWaterShape::initVertexProgram()
_VertexProgramNoBump = BuildWaterVP(false, false, false); _VertexProgramNoBump = BuildWaterVP(false, false, false);
_VertexProgramNoBumpDiffuse = BuildWaterVP(true, false, false); _VertexProgramNoBumpDiffuse = BuildWaterVP(true, false, false);
// no waves // no waves
_VertexProgramNoWave = new CVertexProgram(WaterVPNoWave); // TODO_VP_GLSL _VertexProgramNoWave = new CVertexProgramWaterVPNoWave(false);
_VertexProgramNoWaveDiffuse = new CVertexProgram(WaterVPNoWaveDiffuse); // TODO_VP_GLSL _VertexProgramNoWaveDiffuse = new CVertexProgramWaterVPNoWave(true); // TODO_VP_GLSL
created = true; created = true;
} }
} }