mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-11-19 13:46:13 +00:00
Use named uniform indices for lighted vertex program
This commit is contained in:
parent
e3b2908d49
commit
783adf9fba
11 changed files with 81 additions and 55 deletions
|
@ -1191,6 +1191,7 @@ public:
|
||||||
virtual void setUniform4ui(TProgram program, uint index, uint32 ui0, uint32 ui1, uint32 ui2, uint32 ui3) = 0;
|
virtual void setUniform4ui(TProgram program, uint index, uint32 ui0, uint32 ui1, uint32 ui2, uint32 ui3) = 0;
|
||||||
virtual void setUniform3f(TProgram program, uint index, const NLMISC::CVector& v) = 0;
|
virtual void setUniform3f(TProgram program, uint index, const NLMISC::CVector& v) = 0;
|
||||||
virtual void setUniform4f(TProgram program, uint index, const NLMISC::CVector& v, float f3) = 0;
|
virtual void setUniform4f(TProgram program, uint index, const NLMISC::CVector& v, float f3) = 0;
|
||||||
|
virtual void setUniform4f(TProgram program, uint index, const NLMISC::CRGBAF& rgba) = 0;
|
||||||
virtual void setUniform4x4f(TProgram program, uint index, const NLMISC::CMatrix& m) = 0;
|
virtual void setUniform4x4f(TProgram program, uint index, const NLMISC::CMatrix& m) = 0;
|
||||||
virtual void setUniform4fv(TProgram program, uint index, size_t num, const float *src) = 0;
|
virtual void setUniform4fv(TProgram program, uint index, size_t num, const float *src) = 0;
|
||||||
virtual void setUniform4iv(TProgram program, uint index, size_t num, const sint32 *src) = 0;
|
virtual void setUniform4iv(TProgram program, uint index, size_t num, const sint32 *src) = 0;
|
||||||
|
|
|
@ -88,6 +88,8 @@ private:
|
||||||
//
|
//
|
||||||
enum { NumVp = 8};
|
enum { NumVp = 8};
|
||||||
static NLMISC::CSmartPtr<CVertexProgramPerPixelLight> _VertexProgram[NumVp];
|
static NLMISC::CSmartPtr<CVertexProgramPerPixelLight> _VertexProgram[NumVp];
|
||||||
|
|
||||||
|
NLMISC::CRefPtr<CVertexProgramPerPixelLight> _ActiveVertexProgram;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // NL3D
|
} // NL3D
|
||||||
|
|
|
@ -116,6 +116,8 @@ private:
|
||||||
*/
|
*/
|
||||||
static NLMISC::CSmartPtr<CVertexProgramWindTree> _VertexProgram[NumVp];
|
static NLMISC::CSmartPtr<CVertexProgramWindTree> _VertexProgram[NumVp];
|
||||||
|
|
||||||
|
NLMISC::CRefPtr<CVertexProgramWindTree> _ActiveVertexProgram;
|
||||||
|
|
||||||
// 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];
|
||||||
double _LastSceneTime;
|
double _LastSceneTime;
|
||||||
|
|
|
@ -289,7 +289,7 @@ public:
|
||||||
* \param supportSpecular asitsounds. PointLights and dirLight are localViewer
|
* \param supportSpecular asitsounds. PointLights and dirLight are localViewer
|
||||||
* \param invObjectWM the inverse of object matrix: lights are mul by this. Vp compute in object space.
|
* \param invObjectWM the inverse of object matrix: lights are mul by this. Vp compute in object space.
|
||||||
*/
|
*/
|
||||||
void beginVPLightSetup(uint ctStart, bool supportSpecular, const CMatrix &invObjectWM);
|
void beginVPLightSetup(CVertexProgramLighted *program, const CMatrix &invObjectWM);
|
||||||
|
|
||||||
/** change the driver VP LightSetup constants which depends on material.
|
/** change the driver VP LightSetup constants which depends on material.
|
||||||
* \param excludeStrongest This remove the strongest light from the setup. The typical use is to have it computed by using perpixel lighting.
|
* \param excludeStrongest This remove the strongest light from the setup. The typical use is to have it computed by using perpixel lighting.
|
||||||
|
@ -418,12 +418,14 @@ private:
|
||||||
mutable uint _StrongestLightIndex;
|
mutable uint _StrongestLightIndex;
|
||||||
mutable bool _StrongestLightTouched;
|
mutable bool _StrongestLightTouched;
|
||||||
|
|
||||||
|
// Current vp setuped with beginVPLightSetup()
|
||||||
|
NLMISC::CRefPtr<CVertexProgramLighted> _VPCurrent;
|
||||||
// Current ctStart setuped with beginVPLightSetup()
|
// Current ctStart setuped with beginVPLightSetup()
|
||||||
uint _VPCurrentCtStart;
|
//uint _VPCurrentCtStart;
|
||||||
// Current num of VP lights enabled.
|
// Current num of VP lights enabled.
|
||||||
uint _VPNumLights;
|
uint _VPNumLights;
|
||||||
// Current support of specular
|
// Current support of specular
|
||||||
bool _VPSupportSpecular;
|
//bool _VPSupportSpecular;
|
||||||
// Sum of all ambiant of all lights + ambiantGlobal.
|
// Sum of all ambiant of all lights + ambiantGlobal.
|
||||||
NLMISC::CRGBAF _VPFinalAmbient;
|
NLMISC::CRGBAF _VPFinalAmbient;
|
||||||
// Diffuse/Spec comp of all light / 255.
|
// Diffuse/Spec comp of all light / 255.
|
||||||
|
|
|
@ -1200,6 +1200,7 @@ public:
|
||||||
virtual void setUniform4ui(TProgram program, uint index, uint32 ui0, uint32 ui1, uint32 ui2, uint32 ui3);
|
virtual void setUniform4ui(TProgram program, uint index, uint32 ui0, uint32 ui1, uint32 ui2, uint32 ui3);
|
||||||
virtual void setUniform3f(TProgram program, uint index, const NLMISC::CVector& v);
|
virtual void setUniform3f(TProgram program, uint index, const NLMISC::CVector& v);
|
||||||
virtual void setUniform4f(TProgram program, uint index, const NLMISC::CVector& v, float f3);
|
virtual void setUniform4f(TProgram program, uint index, const NLMISC::CVector& v, float f3);
|
||||||
|
virtual void setUniform4f(TProgram program, uint index, const NLMISC::CRGBAF& rgba);
|
||||||
virtual void setUniform4x4f(TProgram program, uint index, const NLMISC::CMatrix& m);
|
virtual void setUniform4x4f(TProgram program, uint index, const NLMISC::CMatrix& m);
|
||||||
virtual void setUniform4fv(TProgram program, uint index, size_t num, const float *src);
|
virtual void setUniform4fv(TProgram program, uint index, size_t num, const float *src);
|
||||||
virtual void setUniform4iv(TProgram program, uint index, size_t num, const sint32 *src);
|
virtual void setUniform4iv(TProgram program, uint index, size_t num, const sint32 *src);
|
||||||
|
|
|
@ -138,6 +138,11 @@ void CDriverD3D::setUniform4f(TProgram program, uint index, const NLMISC::CVecto
|
||||||
CDriverD3D::setUniform4f(program, index, v.x, v.y, v.z, f3);
|
CDriverD3D::setUniform4f(program, index, v.x, v.y, v.z, f3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CDriverD3D::setUniform4f(TProgram program, uint index, const NLMISC::CRGBAF& rgba)
|
||||||
|
{
|
||||||
|
CDriverD3D::setUniform4fv(program, index, 1, &rgba.R);
|
||||||
|
}
|
||||||
|
|
||||||
void CDriverD3D::setUniform4x4f(TProgram program, uint index, const NLMISC::CMatrix& m)
|
void CDriverD3D::setUniform4x4f(TProgram program, uint index, const NLMISC::CMatrix& m)
|
||||||
{
|
{
|
||||||
H_AUTO_D3D(CDriverD3D_setUniform4x4f);
|
H_AUTO_D3D(CDriverD3D_setUniform4x4f);
|
||||||
|
|
|
@ -1406,6 +1406,7 @@ private:
|
||||||
virtual void setUniform4ui(TProgram program, uint index, uint32 ui0, uint32 ui1, uint32 ui2, uint32 ui3);
|
virtual void setUniform4ui(TProgram program, uint index, uint32 ui0, uint32 ui1, uint32 ui2, uint32 ui3);
|
||||||
virtual void setUniform3f(TProgram program, uint index, const NLMISC::CVector& v);
|
virtual void setUniform3f(TProgram program, uint index, const NLMISC::CVector& v);
|
||||||
virtual void setUniform4f(TProgram program, uint index, const NLMISC::CVector& v, float f3);
|
virtual void setUniform4f(TProgram program, uint index, const NLMISC::CVector& v, float f3);
|
||||||
|
virtual void setUniform4f(TProgram program, uint index, const NLMISC::CRGBAF& rgba);
|
||||||
virtual void setUniform4x4f(TProgram program, uint index, const NLMISC::CMatrix& m);
|
virtual void setUniform4x4f(TProgram program, uint index, const NLMISC::CMatrix& m);
|
||||||
virtual void setUniform4fv(TProgram program, uint index, size_t num, const float *src);
|
virtual void setUniform4fv(TProgram program, uint index, size_t num, const float *src);
|
||||||
virtual void setUniform4iv(TProgram program, uint index, size_t num, const sint32 *src);
|
virtual void setUniform4iv(TProgram program, uint index, size_t num, const sint32 *src);
|
||||||
|
|
|
@ -169,6 +169,11 @@ void CDriverGL::setUniform4f(TProgram program, uint index, const NLMISC::CVector
|
||||||
CDriverGL::setUniform4f(program, index, v.x, v.y, v.z, f3);
|
CDriverGL::setUniform4f(program, index, v.x, v.y, v.z, f3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CDriverGL::setUniform4f(TProgram program, uint index, const NLMISC::CRGBAF& rgba)
|
||||||
|
{
|
||||||
|
CDriverGL::setUniform4fv(program, index, 1, &rgba.R);
|
||||||
|
}
|
||||||
|
|
||||||
void CDriverGL::setUniform4x4f(TProgram program, uint index, const NLMISC::CMatrix& m)
|
void CDriverGL::setUniform4x4f(TProgram program, uint index, const NLMISC::CMatrix& m)
|
||||||
{
|
{
|
||||||
H_AUTO_OGL(CDriverGL_setUniform4x4f);
|
H_AUTO_OGL(CDriverGL_setUniform4x4f);
|
||||||
|
|
|
@ -488,9 +488,7 @@ bool CMeshVPPerPixelLight::begin(IDriver *drv,
|
||||||
//
|
//
|
||||||
CRenderTrav *renderTrav= &scene->getRenderTrav();
|
CRenderTrav *renderTrav= &scene->getRenderTrav();
|
||||||
/// Setup for gouraud lighting
|
/// Setup for gouraud lighting
|
||||||
renderTrav->beginVPLightSetup(VPLightConstantStart,
|
renderTrav->beginVPLightSetup(_ActiveVertexProgram, invertedModelMat);
|
||||||
SpecularLighting,
|
|
||||||
invertedModelMat);
|
|
||||||
//
|
//
|
||||||
sint strongestLightIndex = renderTrav->getStrongestLightIndex();
|
sint strongestLightIndex = renderTrav->getStrongestLightIndex();
|
||||||
if (strongestLightIndex == -1) return false; // if no strongest light, disable this vertex program
|
if (strongestLightIndex == -1) return false; // if no strongest light, disable this vertex program
|
||||||
|
@ -569,10 +567,12 @@ void CMeshVPPerPixelLight::enable(bool enabled, IDriver *drv)
|
||||||
| (_IsPointLight ? 1 : 0);
|
| (_IsPointLight ? 1 : 0);
|
||||||
//
|
//
|
||||||
drv->activeVertexProgram((CVertexProgramPerPixelLight *)_VertexProgram[idVP]);
|
drv->activeVertexProgram((CVertexProgramPerPixelLight *)_VertexProgram[idVP]);
|
||||||
|
_ActiveVertexProgram = _VertexProgram[idVP];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
drv->activeVertexProgram(NULL);
|
drv->activeVertexProgram(NULL);
|
||||||
|
_ActiveVertexProgram = NULL;
|
||||||
}
|
}
|
||||||
_Enabled = enabled;
|
_Enabled = enabled;
|
||||||
}
|
}
|
||||||
|
|
|
@ -354,6 +354,7 @@ bool CMeshVPWindTree::begin(IDriver *driver, CScene *scene, CMeshBaseInstance *m
|
||||||
idVP= numPls*4 + idVP;
|
idVP= numPls*4 + idVP;
|
||||||
// activate VP.
|
// activate VP.
|
||||||
driver->activeVertexProgram(_VertexProgram[idVP]);
|
driver->activeVertexProgram(_VertexProgram[idVP]);
|
||||||
|
_ActiveVertexProgram = _VertexProgram[idVP];
|
||||||
|
|
||||||
|
|
||||||
// precompute mesh
|
// precompute mesh
|
||||||
|
@ -373,6 +374,7 @@ void CMeshVPWindTree::end(IDriver *driver)
|
||||||
{
|
{
|
||||||
// Disable the VertexProgram
|
// Disable the VertexProgram
|
||||||
driver->activeVertexProgram(NULL);
|
driver->activeVertexProgram(NULL);
|
||||||
|
_ActiveVertexProgram = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
|
@ -398,7 +400,8 @@ void CMeshVPWindTree::setupLighting(CScene *scene, CMeshBaseInstance *mbi, const
|
||||||
nlassert(scene != NULL);
|
nlassert(scene != NULL);
|
||||||
CRenderTrav *renderTrav= &scene->getRenderTrav();
|
CRenderTrav *renderTrav= &scene->getRenderTrav();
|
||||||
// setup cte for lighting
|
// setup cte for lighting
|
||||||
renderTrav->beginVPLightSetup(VPLightConstantStart, SpecularLighting, invertedModelMat);
|
CVertexProgramWindTree *program = _ActiveVertexProgram;
|
||||||
|
renderTrav->beginVPLightSetup(program, invertedModelMat);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -431,6 +434,7 @@ void CMeshVPWindTree::beginMBRMesh(IDriver *driver, CScene *scene)
|
||||||
|
|
||||||
// activate VP.
|
// activate VP.
|
||||||
driver->activeVertexProgram(_VertexProgram[_LastMBRIdVP]);
|
driver->activeVertexProgram(_VertexProgram[_LastMBRIdVP]);
|
||||||
|
_ActiveVertexProgram = _VertexProgram[_LastMBRIdVP];
|
||||||
|
|
||||||
// precompute mesh
|
// precompute mesh
|
||||||
setupPerMesh(driver, scene);
|
setupPerMesh(driver, scene);
|
||||||
|
@ -456,6 +460,7 @@ void CMeshVPWindTree::beginMBRInstance(IDriver *driver, CScene *scene, CMeshBase
|
||||||
{
|
{
|
||||||
_LastMBRIdVP= idVP;
|
_LastMBRIdVP= idVP;
|
||||||
driver->activeVertexProgram(_VertexProgram[_LastMBRIdVP]);
|
driver->activeVertexProgram(_VertexProgram[_LastMBRIdVP]);
|
||||||
|
_ActiveVertexProgram = _VertexProgram[_LastMBRIdVP];
|
||||||
|
|
||||||
if (!_VertexProgram[_LastMBRIdVP]->PerMeshSetup)
|
if (!_VertexProgram[_LastMBRIdVP]->PerMeshSetup)
|
||||||
{
|
{
|
||||||
|
@ -474,6 +479,7 @@ void CMeshVPWindTree::endMBRMesh(IDriver *driver)
|
||||||
{
|
{
|
||||||
// Disable the VertexProgram
|
// Disable the VertexProgram
|
||||||
driver->activeVertexProgram(NULL);
|
driver->activeVertexProgram(NULL);
|
||||||
|
_ActiveVertexProgram = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
|
|
|
@ -762,13 +762,15 @@ void CRenderTrav::changeLightSetup(CLightContribution *lightContribution, bool
|
||||||
|
|
||||||
|
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
void CRenderTrav::beginVPLightSetup(uint ctStart, bool supportSpecular, const CMatrix &invObjectWM)
|
void CRenderTrav::beginVPLightSetup(CVertexProgramLighted *program, const CMatrix &invObjectWM)
|
||||||
{
|
{
|
||||||
uint i;
|
uint i;
|
||||||
nlassert(MaxVPLight==4);
|
nlassert(MaxVPLight==4);
|
||||||
_VPNumLights= min(_NumLightEnabled, (uint)MaxVPLight);
|
_VPNumLights= min(_NumLightEnabled, (uint)MaxVPLight);
|
||||||
_VPCurrentCtStart= ctStart;
|
// _VPCurrentCtStart= ctStart;
|
||||||
_VPSupportSpecular= supportSpecular;
|
// _VPSupportSpecular= supportSpecular;
|
||||||
|
_VPCurrent = program;
|
||||||
|
bool supportSpecular = program->featuresLighted().SupportSpecular;
|
||||||
|
|
||||||
// Prepare Colors (to be multiplied by material)
|
// Prepare Colors (to be multiplied by material)
|
||||||
//================
|
//================
|
||||||
|
@ -786,8 +788,11 @@ void CRenderTrav::beginVPLightSetup(uint ctStart, bool supportSpecular, const C
|
||||||
// reset other to 0.
|
// reset other to 0.
|
||||||
for(; i<MaxVPLight; i++)
|
for(; i<MaxVPLight; i++)
|
||||||
{
|
{
|
||||||
_VPLightDiffuse[i]= CRGBA::Black;
|
_VPLightDiffuse[i] = CRGBA::Black;
|
||||||
Driver->setConstant(_VPCurrentCtStart+1+i, 0.f, 0.f, 0.f, 0.f);
|
if (program->idxLighted().Diffuse[i] != ~0)
|
||||||
|
{
|
||||||
|
Driver->setUniform4f(IDriver::VertexProgram, program->idxLighted().Diffuse[i], 0.f, 0.f, 0.f, 0.f);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Specular. _VPCurrentCtStart+5 to 8 (only if supportSpecular)
|
// Specular. _VPCurrentCtStart+5 to 8 (only if supportSpecular)
|
||||||
if(supportSpecular)
|
if(supportSpecular)
|
||||||
|
@ -800,7 +805,10 @@ void CRenderTrav::beginVPLightSetup(uint ctStart, bool supportSpecular, const C
|
||||||
for(; i<MaxVPLight; i++)
|
for(; i<MaxVPLight; i++)
|
||||||
{
|
{
|
||||||
_VPLightSpecular[i]= CRGBA::Black;
|
_VPLightSpecular[i]= CRGBA::Black;
|
||||||
Driver->setConstant(_VPCurrentCtStart+5+i, 0.f, 0.f, 0.f, 0.f);
|
if (program->idxLighted().Specular[i] != ~0)
|
||||||
|
{
|
||||||
|
Driver->setUniform4f(IDriver::VertexProgram, program->idxLighted().Specular[i], 0.f, 0.f, 0.f, 0.f);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -816,40 +824,24 @@ void CRenderTrav::beginVPLightSetup(uint ctStart, bool supportSpecular, const C
|
||||||
lightDir= invObjectWM.mulVector(_DriverLight[0].getDirection());
|
lightDir= invObjectWM.mulVector(_DriverLight[0].getDirection());
|
||||||
lightDir.normalize();
|
lightDir.normalize();
|
||||||
lightDir= -lightDir;
|
lightDir= -lightDir;
|
||||||
if(supportSpecular)
|
Driver->setUniform3f(IDriver::VertexProgram, program->idxLighted().DirOrPos[0], lightDir); // The sun is the same for every instance.
|
||||||
{
|
|
||||||
// Setup lightDir.
|
|
||||||
Driver->setConstant(_VPCurrentCtStart+9, lightDir);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Setup lightDir. NB: no specular color!
|
|
||||||
Driver->setConstant(_VPCurrentCtStart+5, lightDir);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Setup PointLights
|
// Setup PointLights
|
||||||
//================
|
//================
|
||||||
uint startPLPos;
|
uint startPLPos;
|
||||||
if(supportSpecular)
|
if (supportSpecular)
|
||||||
{
|
{
|
||||||
// Setup eye in objectSpace for localViewer
|
// Setup eye in objectSpace for localViewer
|
||||||
Driver->setConstant(_VPCurrentCtStart+11, eye);
|
Driver->setUniform3f(IDriver::VertexProgram, program->idxLighted().EyePosition, eye);
|
||||||
// Start at 12.
|
|
||||||
startPLPos= 12;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Start at 6.
|
|
||||||
startPLPos= 6;
|
|
||||||
}
|
}
|
||||||
// For all pointLight enabled (other are black: don't matter)
|
// For all pointLight enabled (other are black: don't matter)
|
||||||
for(i=1; i<_VPNumLights; i++)
|
for(i=1; i<_VPNumLights; i++)
|
||||||
{
|
{
|
||||||
// Setup position of light.
|
// Setup position of light.
|
||||||
CVector lightPos;
|
CVector lightPos;
|
||||||
lightPos= invObjectWM * _DriverLight[i].getPosition();
|
lightPos = invObjectWM * _DriverLight[i].getPosition();
|
||||||
Driver->setConstant(_VPCurrentCtStart+startPLPos+(i-1), lightPos);
|
Driver->setUniform3f(IDriver::VertexProgram, program->idxLighted().DirOrPos[i], lightPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -860,6 +852,9 @@ void CRenderTrav::beginVPLightSetup(uint ctStart, bool supportSpecular, const C
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
void CRenderTrav::changeVPLightSetupMaterial(const CMaterial &mat, bool excludeStrongest)
|
void CRenderTrav::changeVPLightSetupMaterial(const CMaterial &mat, bool excludeStrongest)
|
||||||
{
|
{
|
||||||
|
CVertexProgramLighted *program = _VPCurrent;
|
||||||
|
nlassert(program);
|
||||||
|
|
||||||
// Must test if at least done one time.
|
// Must test if at least done one time.
|
||||||
if(!_VPMaterialCacheDirty)
|
if(!_VPMaterialCacheDirty)
|
||||||
{
|
{
|
||||||
|
@ -869,7 +864,7 @@ void CRenderTrav::changeVPLightSetupMaterial(const CMaterial &mat, bool exclude
|
||||||
_VPMaterialCacheDiffuse == mat.getDiffuse().getPacked() )
|
_VPMaterialCacheDiffuse == mat.getDiffuse().getPacked() )
|
||||||
{
|
{
|
||||||
// Same Diffuse part, test if same specular if necessary
|
// Same Diffuse part, test if same specular if necessary
|
||||||
if( !_VPSupportSpecular ||
|
if( !program->featuresLighted().SupportSpecular ||
|
||||||
( _VPMaterialCacheSpecular == mat.getSpecular().getPacked() &&
|
( _VPMaterialCacheSpecular == mat.getSpecular().getPacked() &&
|
||||||
_VPMaterialCacheShininess == mat.getShininess() ) )
|
_VPMaterialCacheShininess == mat.getShininess() ) )
|
||||||
{
|
{
|
||||||
|
@ -899,7 +894,7 @@ void CRenderTrav::changeVPLightSetupMaterial(const CMaterial &mat, bool exclude
|
||||||
// setup Ambient + Emissive
|
// setup Ambient + Emissive
|
||||||
color= _VPFinalAmbient * mat.getAmbient();
|
color= _VPFinalAmbient * mat.getAmbient();
|
||||||
color+= mat.getEmissive();
|
color+= mat.getEmissive();
|
||||||
Driver->setConstant(_VPCurrentCtStart+0, 1, &color.R);
|
Driver->setUniform4f(IDriver::VertexProgram, program->idxLighted().Ambient, color);
|
||||||
|
|
||||||
|
|
||||||
// is the strongest light is not excluded, its index should have been setup to _VPNumLights
|
// is the strongest light is not excluded, its index should have been setup to _VPNumLights
|
||||||
|
@ -908,7 +903,7 @@ void CRenderTrav::changeVPLightSetupMaterial(const CMaterial &mat, bool exclude
|
||||||
for(i = 0; i < strongestLightIndex; ++i)
|
for(i = 0; i < strongestLightIndex; ++i)
|
||||||
{
|
{
|
||||||
color= _VPLightDiffuse[i] * matDiff;
|
color= _VPLightDiffuse[i] * matDiff;
|
||||||
Driver->setConstant(_VPCurrentCtStart+1+i, 1, &color.R);
|
Driver->setUniform4f(IDriver::VertexProgram, program->idxLighted().Diffuse[i], color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -917,24 +912,24 @@ void CRenderTrav::changeVPLightSetupMaterial(const CMaterial &mat, bool exclude
|
||||||
color= _VPLightDiffuse[i] * matDiff;
|
color= _VPLightDiffuse[i] * matDiff;
|
||||||
_StrongestLightDiffuse.set((uint8) (255.f * color.R), (uint8) (255.f * color.G), (uint8) (255.f * color.B), (uint8) (255.f * color.A));
|
_StrongestLightDiffuse.set((uint8) (255.f * color.R), (uint8) (255.f * color.G), (uint8) (255.f * color.B), (uint8) (255.f * color.A));
|
||||||
// setup strongest light to black for the gouraud part
|
// setup strongest light to black for the gouraud part
|
||||||
Driver->setConstant(_VPCurrentCtStart + 1 + i, 0.f, 0.f, 0.f, 0.f);
|
Driver->setUniform4f(IDriver::VertexProgram, program->idxLighted().Diffuse[i], 0.f, 0.f, 0.f, 0.f);
|
||||||
++i;
|
++i;
|
||||||
// setup other lights
|
// setup other lights
|
||||||
for(; i < _VPNumLights; i++)
|
for(; i < _VPNumLights; i++)
|
||||||
{
|
{
|
||||||
color= _VPLightDiffuse[i] * matDiff;
|
color= _VPLightDiffuse[i] * matDiff;
|
||||||
Driver->setConstant(_VPCurrentCtStart + 1 + i, 1, &color.R);
|
Driver->setUniform4f(IDriver::VertexProgram, program->idxLighted().Diffuse[i], color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// setup Specular
|
// setup Specular
|
||||||
if(_VPSupportSpecular)
|
if (program->featuresLighted().SupportSpecular)
|
||||||
{
|
{
|
||||||
for(i = 0; i < strongestLightIndex; ++i)
|
for(i = 0; i < strongestLightIndex; ++i)
|
||||||
{
|
{
|
||||||
color= _VPLightSpecular[i] * matSpec;
|
color= _VPLightSpecular[i] * matSpec;
|
||||||
color.A= specExp;
|
color.A= specExp;
|
||||||
Driver->setConstant(_VPCurrentCtStart+5+i, 1, &color.R);
|
Driver->setUniform4f(IDriver::VertexProgram, program->idxLighted().Specular[i], color);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i != _VPNumLights)
|
if (i != _VPNumLights)
|
||||||
|
@ -943,14 +938,14 @@ void CRenderTrav::changeVPLightSetupMaterial(const CMaterial &mat, bool exclude
|
||||||
_StrongestLightSpecular.set((uint8) (255.f * color.R), (uint8) (255.f * color.G), (uint8) (255.f * color.B), (uint8) (255.f * color.A));
|
_StrongestLightSpecular.set((uint8) (255.f * color.R), (uint8) (255.f * color.G), (uint8) (255.f * color.B), (uint8) (255.f * color.A));
|
||||||
|
|
||||||
// setup strongest light to black (for gouraud part)
|
// setup strongest light to black (for gouraud part)
|
||||||
Driver->setConstant(_VPCurrentCtStart + 5 + i, 0.f, 0.f, 0.f, 0.f);
|
Driver->setUniform4f(IDriver::VertexProgram, program->idxLighted().Specular[i], 0.f, 0.f, 0.f, 0.f);
|
||||||
++i;
|
++i;
|
||||||
// setup other lights
|
// setup other lights
|
||||||
for(; i < _VPNumLights; i++)
|
for(; i < _VPNumLights; i++)
|
||||||
{
|
{
|
||||||
color= _VPLightSpecular[i] * matSpec;
|
color= _VPLightSpecular[i] * matSpec;
|
||||||
color.A= specExp;
|
color.A= specExp;
|
||||||
Driver->setConstant(_VPCurrentCtStart + 5 + i, 1, &color.R);
|
Driver->setUniform4f(IDriver::VertexProgram, program->idxLighted().Specular[i], color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -959,10 +954,7 @@ void CRenderTrav::changeVPLightSetupMaterial(const CMaterial &mat, bool exclude
|
||||||
static float alphaCte[4]= {0,0,1,0};
|
static float alphaCte[4]= {0,0,1,0};
|
||||||
alphaCte[3]= matDiff.A;
|
alphaCte[3]= matDiff.A;
|
||||||
// setup at good place
|
// setup at good place
|
||||||
if(_VPSupportSpecular)
|
Driver->setUniform4fv(IDriver::VertexProgram, program->idxLighted().DiffuseAlpha, 1, alphaCte);
|
||||||
Driver->setConstant(_VPCurrentCtStart+10, 1, alphaCte);
|
|
||||||
else
|
|
||||||
Driver->setConstant(_VPCurrentCtStart+9, 1, alphaCte);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
|
@ -1174,24 +1166,24 @@ void CVertexProgramLighted::buildInfo()
|
||||||
if (profile() == nelvp)
|
if (profile() == nelvp)
|
||||||
{
|
{
|
||||||
// Fixed uniform locations
|
// Fixed uniform locations
|
||||||
m_IdxLighted.Ambient = 0;
|
m_IdxLighted.Ambient = m_FeaturesLighted.CtStartNeLVP + 0;
|
||||||
for (uint i = 0; i < MaxLight; ++i)
|
for (uint i = 0; i < MaxLight; ++i)
|
||||||
{
|
{
|
||||||
m_IdxLighted.Diffuse[i] = 1 + i;
|
m_IdxLighted.Diffuse[i] = m_FeaturesLighted.CtStartNeLVP + 1 + i;
|
||||||
}
|
}
|
||||||
if (m_FeaturesLighted.SupportSpecular)
|
if (m_FeaturesLighted.SupportSpecular)
|
||||||
{
|
{
|
||||||
for (uint i = 0; i < MaxLight; ++i)
|
for (uint i = 0; i < MaxLight; ++i)
|
||||||
{
|
{
|
||||||
m_IdxLighted.Specular[i] = 5 + i;
|
m_IdxLighted.Specular[i] = m_FeaturesLighted.CtStartNeLVP + 5 + i;
|
||||||
}
|
}
|
||||||
m_IdxLighted.DirOrPos[0] = 9;
|
m_IdxLighted.DirOrPos[0] = 9;
|
||||||
for (uint i = 1; i < MaxLight; ++i)
|
for (uint i = 1; i < MaxLight; ++i)
|
||||||
{
|
{
|
||||||
m_IdxLighted.DirOrPos[i] = (12 - 1) + i;
|
m_IdxLighted.DirOrPos[i] = m_FeaturesLighted.CtStartNeLVP + (12 - 1) + i;
|
||||||
}
|
}
|
||||||
m_IdxLighted.DiffuseAlpha = 10;
|
m_IdxLighted.DiffuseAlpha = m_FeaturesLighted.CtStartNeLVP + 10;
|
||||||
m_IdxLighted.EyePosition = 11;
|
m_IdxLighted.EyePosition = m_FeaturesLighted.CtStartNeLVP + 11;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1201,9 +1193,9 @@ void CVertexProgramLighted::buildInfo()
|
||||||
}
|
}
|
||||||
for (uint i = 0; i < MaxLight; ++i)
|
for (uint i = 0; i < MaxLight; ++i)
|
||||||
{
|
{
|
||||||
m_IdxLighted.DirOrPos[i] = 5 + i;
|
m_IdxLighted.DirOrPos[i] = m_FeaturesLighted.CtStartNeLVP + 5 + i;
|
||||||
}
|
}
|
||||||
m_IdxLighted.DiffuseAlpha = 9;
|
m_IdxLighted.DiffuseAlpha = m_FeaturesLighted.CtStartNeLVP + 9;
|
||||||
m_IdxLighted.EyePosition = ~0;
|
m_IdxLighted.EyePosition = ~0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1214,6 +1206,15 @@ void CVertexProgramLighted::buildInfo()
|
||||||
// m_IdxLighted.Ambient = getUniformIndex("ambient");
|
// m_IdxLighted.Ambient = getUniformIndex("ambient");
|
||||||
// etc
|
// etc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nlassert(m_IdxLighted.Diffuse[0] != ~0);
|
||||||
|
if (m_FeaturesLighted.SupportSpecular)
|
||||||
|
{
|
||||||
|
nlassert(m_IdxLighted.Specular[0] != ~0);
|
||||||
|
nlassert(m_IdxLighted.EyePosition != ~0);
|
||||||
|
}
|
||||||
|
nlassert(m_IdxLighted.DirOrPos[0] != ~0);
|
||||||
|
nlassert(m_IdxLighted.DiffuseAlpha != ~0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// generates the lighting part of a vertex program, nelvp profile
|
// generates the lighting part of a vertex program, nelvp profile
|
||||||
|
|
Loading…
Reference in a new issue