From a72f25e763319bfd742749a34d2997c8a60caac0 Mon Sep 17 00:00:00 2001 From: kaetemi Date: Fri, 13 Sep 2013 19:03:05 +0200 Subject: [PATCH] Add container for lighted vertex program --HG-- branch : multipass-stereo --- code/nel/include/nel/3d/render_trav.h | 41 +++++++++++++++++- code/nel/src/3d/meshvp_per_pixel_light.cpp | 4 +- code/nel/src/3d/meshvp_wind_tree.cpp | 2 +- code/nel/src/3d/render_trav.cpp | 50 +++++++++++++++++++++- 4 files changed, 91 insertions(+), 6 deletions(-) diff --git a/code/nel/include/nel/3d/render_trav.h b/code/nel/include/nel/3d/render_trav.h index 6e8d04b32..76931d68f 100644 --- a/code/nel/include/nel/3d/render_trav.h +++ b/code/nel/include/nel/3d/render_trav.h @@ -27,6 +27,7 @@ #include "nel/3d/mesh_block_manager.h" #include "nel/3d/shadow_map_manager.h" #include "nel/3d/u_scene.h" +#include "nel/3d/vertex_program.h" #include @@ -68,6 +69,41 @@ class CWaterModel; #define NL3D_SHADOW_MESH_SKIN_MANAGER_MAXVERTICES 3000 #define NL3D_SHADOW_MESH_SKIN_MANAGER_NUMVB 8 +/// Container for lighted vertex program. +class CVertexProgramLighted : CVertexProgram +{ +public: + static const uint MaxLight = 4; + static const uint MaxPointLight = (MaxLight - 1); + struct CIdxLighted + { + uint Ambient; + uint Diffuse[MaxLight]; + uint Specular[MaxLight]; + uint DirOrPos[MaxLight]; // light 0, directional sun; light 1,2,3, omni point light + uint EyePosition; + uint DiffuseAlpha; + }; + struct CFeaturesLighted + { + /// Number of point lights that this program is generated for, varies from 0 to 3. + uint NumActivePointLights; + bool SupportSpecular; + bool Normalize; + /// Start of constants to use for lighting with assembly shaders. + uint CtStartNeLVP; + }; + CVertexProgramLighted() { } + virtual ~CVertexProgramLighted() { } + virtual void buildInfo(); + const CIdxLighted &idxLighted() const { return m_IdxLighted; } + const CFeaturesLighted &featuresLighted() const { return m_FeaturesLighted; } + +private: + CIdxLighted m_IdxLighted; + CFeaturesLighted m_FeaturesLighted; + +}; // *************************************************************************** @@ -224,7 +260,7 @@ public: // @{ // Max VP Light setup Infos. - enum {MaxVPLight= 4}; + enum {MaxVPLight = CVertexProgramLighted::MaxLight}; /** reset the lighting setup in the driver (all lights are disabled). * called at beginning of traverse(). Must be called by any model (before and after rendering) @@ -299,7 +335,8 @@ public: * \param numActivePoinLights tells how many point light from 0 to 3 this VP must handle. NB: the Sun directionnal is not option * NB: nlassert(numActiveLights<=MaxVPLight-1). */ - static std::string getLightVPFragment(uint numActivePointLights, uint ctStart, bool supportSpecular, bool normalize); + static std::string getLightVPFragmentNeLVP(uint numActivePointLights, uint ctStart, bool supportSpecular, bool normalize); + // TODO_VP_GLSL /** This returns a reference to a driver light, by its index * \see getStrongestLightIndex diff --git a/code/nel/src/3d/meshvp_per_pixel_light.cpp b/code/nel/src/3d/meshvp_per_pixel_light.cpp index 3e2828328..809dd16c8 100644 --- a/code/nel/src/3d/meshvp_per_pixel_light.cpp +++ b/code/nel/src/3d/meshvp_per_pixel_light.cpp @@ -393,10 +393,10 @@ void CMeshVPPerPixelLight::initInstance(CMeshBaseInstance *mbi) for (uint vp = 0; vp < NumVp; ++vp) { // \todo yoyo TODO_OPTIM Manage different number of pointLights - // NB: never call getLightVPFragment() 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("# ***************") // temp for debug - + CRenderTrav::getLightVPFragment(CRenderTrav::MaxVPLight-1, VPLightConstantStart, (vp & 2) != 0, false) + + CRenderTrav::getLightVPFragmentNeLVP(CRenderTrav::MaxVPLight-1, VPLightConstantStart, (vp & 2) != 0, false) + std::string("# ***************") // temp for debug + std::string(PPLightingVPCodeEnd); #ifdef NL_DEBUG diff --git a/code/nel/src/3d/meshvp_wind_tree.cpp b/code/nel/src/3d/meshvp_wind_tree.cpp index 477814f6f..85a5550e8 100644 --- a/code/nel/src/3d/meshvp_wind_tree.cpp +++ b/code/nel/src/3d/meshvp_wind_tree.cpp @@ -155,7 +155,7 @@ void CMeshVPWindTree::initInstance(CMeshBaseInstance *mbi) // combine fragments vpCode= string(WindTreeVPCodeWave) - + CRenderTrav::getLightVPFragment(numPls, VPLightConstantStart, specular, normalize) + + CRenderTrav::getLightVPFragmentNeLVP(numPls, VPLightConstantStart, specular, normalize) + WindTreeVPCodeEnd; _VertexProgram[i] = new CVertexProgram(vpCode.c_str()); // TODO_VP_GLSL diff --git a/code/nel/src/3d/render_trav.cpp b/code/nel/src/3d/render_trav.cpp index 5cf6fd20e..eba42e724 100644 --- a/code/nel/src/3d/render_trav.cpp +++ b/code/nel/src/3d/render_trav.cpp @@ -1168,8 +1168,56 @@ static void strReplaceAll(string &strInOut, const string &tokenSrc, const string } } +void CVertexProgramLighted::buildInfo() +{ + if (m_FeaturesLighted.CtStartNeLVP != ~0) + { + // Fixed uniform locations + m_IdxLighted.Ambient = 0; + for (uint i = 0; i < MaxLight; ++i) + { + m_IdxLighted.Diffuse[i] = 1 + i; + } + if (m_FeaturesLighted.SupportSpecular) + { + for (uint i = 0; i < MaxLight; ++i) + { + m_IdxLighted.Specular[i] = 5 + i; + } + m_IdxLighted.DirOrPos[0] = 9; + for (uint i = 1; i < MaxLight; ++i) + { + m_IdxLighted.DirOrPos[i] = (12 - 1) + i; + } + m_IdxLighted.DiffuseAlpha = 10; + m_IdxLighted.EyePosition = 11; + } + else + { + for (uint i = 0; i < MaxLight; ++i) + { + m_IdxLighted.Specular[i] = ~0; + } + for (uint i = 0; i < MaxLight; ++i) + { + m_IdxLighted.DirOrPos[i] = 5 + i; + } + m_IdxLighted.DiffuseAlpha = 9; + m_IdxLighted.EyePosition = ~0; + } + } + else + { + // Named uniform locations + // TODO_VP_GLSL + // m_IdxLighted.Ambient = getUniformIndex("ambient"); + // etc + } +} + +// generates the lighting part of a vertex program, nelvp profile // *************************************************************************** -std::string CRenderTrav::getLightVPFragment(uint numActivePointLights, uint ctStart, bool supportSpecular, bool normalize) +std::string CRenderTrav::getLightVPFragmentNeLVP(uint numActivePointLights, uint ctStart, bool supportSpecular, bool normalize) { string ret;