mirror of
https://port.numenaute.org/aleajactaest/khanat-code-old.git
synced 2024-11-25 00:06:16 +00:00
Use lighted vertex program container for per pixel light program
This commit is contained in:
parent
2d9212669a
commit
c7894d0c15
5 changed files with 94 additions and 43 deletions
|
@ -27,6 +27,7 @@
|
||||||
|
|
||||||
namespace NL3D {
|
namespace NL3D {
|
||||||
|
|
||||||
|
class CVertexProgramPerPixelLight;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This vertex program is used to perform perpixel lighting with meshs. Its outputs are :
|
* This vertex program is used to perform perpixel lighting with meshs. Its outputs are :
|
||||||
|
@ -49,6 +50,8 @@ namespace NL3D {
|
||||||
class CMeshVPPerPixelLight : public IMeshVertexProgram
|
class CMeshVPPerPixelLight : public IMeshVertexProgram
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
friend class CVertexProgramPerPixelLight;
|
||||||
|
|
||||||
/// true if want Specular Lighting.
|
/// true if want Specular Lighting.
|
||||||
bool SpecularLighting;
|
bool SpecularLighting;
|
||||||
public:
|
public:
|
||||||
|
@ -84,7 +87,7 @@ private:
|
||||||
bool _IsPointLight;
|
bool _IsPointLight;
|
||||||
//
|
//
|
||||||
enum { NumVp = 8};
|
enum { NumVp = 8};
|
||||||
static NLMISC::CSmartPtr<CVertexProgram> _VertexProgram[NumVp];
|
static NLMISC::CSmartPtr<CVertexProgramPerPixelLight> _VertexProgram[NumVp];
|
||||||
};
|
};
|
||||||
|
|
||||||
} // NL3D
|
} // NL3D
|
||||||
|
|
|
@ -70,7 +70,7 @@ class CWaterModel;
|
||||||
#define NL3D_SHADOW_MESH_SKIN_MANAGER_NUMVB 8
|
#define NL3D_SHADOW_MESH_SKIN_MANAGER_NUMVB 8
|
||||||
|
|
||||||
/// Container for lighted vertex program.
|
/// Container for lighted vertex program.
|
||||||
class CVertexProgramLighted : CVertexProgram
|
class CVertexProgramLighted : public CVertexProgram
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static const uint MaxLight = 4;
|
static const uint MaxLight = 4;
|
||||||
|
@ -99,7 +99,7 @@ public:
|
||||||
const CIdxLighted &idxLighted() const { return m_IdxLighted; }
|
const CIdxLighted &idxLighted() const { return m_IdxLighted; }
|
||||||
const CFeaturesLighted &featuresLighted() const { return m_FeaturesLighted; }
|
const CFeaturesLighted &featuresLighted() const { return m_FeaturesLighted; }
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
CIdxLighted m_IdxLighted;
|
CIdxLighted m_IdxLighted;
|
||||||
CFeaturesLighted m_FeaturesLighted;
|
CFeaturesLighted m_FeaturesLighted;
|
||||||
|
|
||||||
|
|
|
@ -32,14 +32,13 @@
|
||||||
|
|
||||||
namespace NL3D
|
namespace NL3D
|
||||||
{
|
{
|
||||||
NLMISC::CSmartPtr<CVertexProgram> CMeshVPPerPixelLight::_VertexProgram[NumVp];
|
|
||||||
|
NLMISC::CSmartPtr<CVertexProgramPerPixelLight> CMeshVPPerPixelLight::_VertexProgram[NumVp];
|
||||||
|
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
// Light VP fragment constants start at 24
|
// Light VP fragment constants start at 24
|
||||||
static const uint VPLightConstantStart = 24;
|
static const uint VPLightConstantStart = 24;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
|
|
||||||
|
@ -355,18 +354,33 @@ static const char* PPLightingVPCodeTest =
|
||||||
";
|
";
|
||||||
***************************************************************/
|
***************************************************************/
|
||||||
|
|
||||||
|
class CVertexProgramPerPixelLight : public CVertexProgramLighted
|
||||||
|
|
||||||
|
|
||||||
//=================================================================================
|
|
||||||
void CMeshVPPerPixelLight::initInstance(CMeshBaseInstance *mbi)
|
|
||||||
{
|
{
|
||||||
// init the vertexProgram code.
|
public:
|
||||||
static bool vpCreated= false;
|
class CIdx
|
||||||
if (!vpCreated)
|
|
||||||
{
|
{
|
||||||
vpCreated= true;
|
|
||||||
|
|
||||||
|
};
|
||||||
|
CVertexProgramPerPixelLight(uint vp);
|
||||||
|
virtual ~CVertexProgramPerPixelLight() { };
|
||||||
|
virtual void buildInfo();
|
||||||
|
const CIdx &idx() const { return m_Idx; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
CIdx m_Idx;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
CVertexProgramPerPixelLight::CVertexProgramPerPixelLight(uint vp)
|
||||||
|
{
|
||||||
|
// lighted settings
|
||||||
|
m_FeaturesLighted.SupportSpecular = (vp & 2) != 0;
|
||||||
|
m_FeaturesLighted.NumActivePointLights = MaxLight - 1;
|
||||||
|
m_FeaturesLighted.Normalize = false;
|
||||||
|
m_FeaturesLighted.CtStartNeLVP = VPLightConstantStart;
|
||||||
|
|
||||||
|
// nelvp
|
||||||
|
{
|
||||||
// Gives each vp name
|
// Gives each vp name
|
||||||
// Bit 0 : 1 when it is a directionnal light
|
// Bit 0 : 1 when it is a directionnal light
|
||||||
// Bit 1 : 1 when specular is needed
|
// Bit 1 : 1 when specular is needed
|
||||||
|
@ -389,14 +403,17 @@ void CMeshVPPerPixelLight::initInstance(CMeshBaseInstance *mbi)
|
||||||
};
|
};
|
||||||
|
|
||||||
uint numvp = sizeof(vpName) / sizeof(const char *);
|
uint numvp = sizeof(vpName) / sizeof(const char *);
|
||||||
nlassert(NumVp == numvp); // make sure that it is in sync with header..todo : compile time assert :)
|
nlassert(CMeshVPPerPixelLight::NumVp == numvp); // make sure that it is in sync with header..todo : compile time assert :)
|
||||||
for (uint vp = 0; vp < NumVp; ++vp)
|
|
||||||
{
|
|
||||||
// \todo yoyo TODO_OPTIM Manage different number of pointLights
|
// \todo yoyo TODO_OPTIM Manage different number of pointLights
|
||||||
// NB: never call getLightVPFragmentNeLVP() with normalize, because already done by PerPixel fragment before.
|
// NB: never call getLightVPFragmentNeLVP() with normalize, because already done by PerPixel fragment before.
|
||||||
std::string vpCode = std::string(vpName[vp])
|
std::string vpCode = std::string(vpName[vp])
|
||||||
+ std::string("# ***************") // temp for debug
|
+ std::string("# ***************") // temp for debug
|
||||||
+ CRenderTrav::getLightVPFragmentNeLVP(CRenderTrav::MaxVPLight-1, VPLightConstantStart, (vp & 2) != 0, false)
|
+ CRenderTrav::getLightVPFragmentNeLVP(
|
||||||
|
m_FeaturesLighted.NumActivePointLights,
|
||||||
|
m_FeaturesLighted.CtStartNeLVP,
|
||||||
|
m_FeaturesLighted.SupportSpecular,
|
||||||
|
m_FeaturesLighted.Normalize)
|
||||||
+ std::string("# ***************") // temp for debug
|
+ std::string("# ***************") // temp for debug
|
||||||
+ std::string(PPLightingVPCodeEnd);
|
+ std::string(PPLightingVPCodeEnd);
|
||||||
#ifdef NL_DEBUG
|
#ifdef NL_DEBUG
|
||||||
|
@ -414,9 +431,39 @@ void CMeshVPPerPixelLight::initInstance(CMeshBaseInstance *mbi)
|
||||||
nlassert(0);
|
nlassert(0);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
_VertexProgram[vp] = new CVertexProgram(vpCode.c_str());
|
|
||||||
|
CSource *source = new CSource();
|
||||||
|
source->DisplayName = NLMISC::toString("nelvp/MeshVPPerPixel/%i", vp);
|
||||||
|
source->Profile = CVertexProgram::nelvp;
|
||||||
|
source->setSource(vpCode);
|
||||||
|
addSource(source);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// glsl
|
||||||
|
{
|
||||||
|
// TODO_VP_GLSL
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CVertexProgramPerPixelLight::buildInfo()
|
||||||
|
{
|
||||||
|
CVertexProgramLighted::buildInfo();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//=================================================================================
|
||||||
|
void CMeshVPPerPixelLight::initInstance(CMeshBaseInstance *mbi)
|
||||||
|
{
|
||||||
|
// init the vertexProgram code.
|
||||||
|
static bool vpCreated= false;
|
||||||
|
if (!vpCreated)
|
||||||
|
{
|
||||||
|
vpCreated = true;
|
||||||
|
|
||||||
|
for (uint vp = 0; vp < NumVp; ++vp)
|
||||||
|
{
|
||||||
|
_VertexProgram[vp] = new CVertexProgramPerPixelLight(vp);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -521,7 +568,7 @@ void CMeshVPPerPixelLight::enable(bool enabled, IDriver *drv)
|
||||||
| (SpecularLighting ? 2 : 0)
|
| (SpecularLighting ? 2 : 0)
|
||||||
| (_IsPointLight ? 1 : 0);
|
| (_IsPointLight ? 1 : 0);
|
||||||
//
|
//
|
||||||
drv->activeVertexProgram(_VertexProgram[idVP]);
|
drv->activeVertexProgram((CVertexProgramPerPixelLight *)_VertexProgram[idVP]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -1170,7 +1170,8 @@ static void strReplaceAll(string &strInOut, const string &tokenSrc, const string
|
||||||
|
|
||||||
void CVertexProgramLighted::buildInfo()
|
void CVertexProgramLighted::buildInfo()
|
||||||
{
|
{
|
||||||
if (m_FeaturesLighted.CtStartNeLVP != ~0)
|
CVertexProgram::buildInfo();
|
||||||
|
if (profile() == nelvp)
|
||||||
{
|
{
|
||||||
// Fixed uniform locations
|
// Fixed uniform locations
|
||||||
m_IdxLighted.Ambient = 0;
|
m_IdxLighted.Ambient = 0;
|
||||||
|
|
Loading…
Reference in a new issue