From a0e457ac1303c778c32e8fafbbf4af86d1580906 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Thu, 7 Aug 2014 00:40:09 +0200 Subject: [PATCH 01/13] Port shadow shaders to singleton and remove non singleton. --- src/graphics/render_geometry.cpp | 38 ++++++++-------- src/graphics/shaders.cpp | 24 ---------- src/graphics/shaders.hpp | 63 ++++---------------------- src/graphics/stkinstancedscenenode.cpp | 16 +++---- 4 files changed, 35 insertions(+), 106 deletions(-) diff --git a/src/graphics/render_geometry.cpp b/src/graphics/render_geometry.cpp index 914278bb1..f5d2681c6 100644 --- a/src/graphics/render_geometry.cpp +++ b/src/graphics/render_geometry.cpp @@ -416,8 +416,8 @@ void IrrDriver::renderTransparent() GLenum itype = mesh.IndexType; size_t count = mesh.IndexCount; - glUseProgram(MeshShader::DisplaceMaskShaderInstance->Program); - MeshShader::DisplaceMaskShaderInstance->setUniforms(AbsoluteTransformation); + glUseProgram(MeshShader::DisplaceMaskShader::getInstance()->Program); + MeshShader::DisplaceMaskShader::getInstance()->setUniforms(AbsoluteTransformation); glDrawElementsBaseVertex(ptype, count, itype, (GLvoid *)mesh.vaoOffset, mesh.vaoBaseVertex); } @@ -435,12 +435,12 @@ void IrrDriver::renderTransparent() GLenum itype = mesh.IndexType; size_t count = mesh.IndexCount; // Render the effect - setTexture(MeshShader::DisplaceShaderInstance->TU_displacement_tex, getTextureGLuint(displaceTex), GL_LINEAR, GL_LINEAR, true); - setTexture(MeshShader::DisplaceShaderInstance->TU_mask_tex, irr_driver->getRenderTargetTexture(RTT_TMP1), GL_LINEAR, GL_LINEAR, true); - setTexture(MeshShader::DisplaceShaderInstance->TU_color_tex, irr_driver->getRenderTargetTexture(RTT_COLOR), GL_LINEAR, GL_LINEAR, true); - setTexture(MeshShader::DisplaceShaderInstance->TU_tex, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR, true); - glUseProgram(MeshShader::DisplaceShaderInstance->Program); - MeshShader::DisplaceShaderInstance->setUniforms(AbsoluteTransformation, + setTexture(MeshShader::DisplaceShader::getInstance()->TU_displacement_tex, getTextureGLuint(displaceTex), GL_LINEAR, GL_LINEAR, true); + setTexture(MeshShader::DisplaceShader::getInstance()->TU_mask_tex, irr_driver->getRenderTargetTexture(RTT_TMP1), GL_LINEAR, GL_LINEAR, true); + setTexture(MeshShader::DisplaceShader::getInstance()->TU_color_tex, irr_driver->getRenderTargetTexture(RTT_COLOR), GL_LINEAR, GL_LINEAR, true); + setTexture(MeshShader::DisplaceShader::getInstance()->TU_tex, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR, true); + glUseProgram(MeshShader::DisplaceShader::getInstance()->Program); + MeshShader::DisplaceShader::getInstance()->setUniforms(AbsoluteTransformation, core::vector2df(cb->getDirX(), cb->getDirY()), core::vector2df(cb->getDir2X(), cb->getDir2Y())); @@ -490,9 +490,9 @@ struct shadow_custom_unroll_args }; template -void renderShadow(const T *Shader, const std::vector TextureUnits, const std::vector >&t) +void renderShadow(const std::vector TextureUnits, const std::vector >&t) { - glUseProgram(Shader->Program); + glUseProgram(T::getInstance()->Program); glBindVertexArray(getVAO(VertexType)); for (unsigned i = 0; i < t.size(); i++) { @@ -503,7 +503,7 @@ void renderShadow(const T *Shader, const std::vector TextureUnits, const setTexture(TextureUnits[j], getTextureGLuint(mesh->textures[j]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true); } - shadow_custom_unroll_args::template exec(Shader, t[i]); + shadow_custom_unroll_args::template exec(T::getInstance(), t[i]); } } @@ -551,14 +551,14 @@ void IrrDriver::renderShadows() m_scene_manager->drawAll(scene::ESNRP_SOLID); std::vector noTexUnits; - renderShadow(MeshShader::ShadowShaderInstance, noTexUnits, ListMatDefault::Arguments); - renderShadow(MeshShader::ShadowShaderInstance, noTexUnits, ListMatSphereMap::Arguments); - renderShadow(MeshShader::ShadowShaderInstance, noTexUnits, ListMatUnlit::Arguments); - renderShadow(MeshShader::ShadowShaderInstance, noTexUnits, ListMatDetails::Arguments); - renderShadow(MeshShader::ShadowShaderInstance, noTexUnits, ListMatSplatting::Arguments); - renderShadow(MeshShader::ShadowShaderInstance, noTexUnits, ListMatNormalMap::Arguments); - renderShadow(MeshShader::RefShadowShaderInstance, std::vector{ MeshShader::RefShadowShaderInstance->TU_tex }, ListMatAlphaRef::Arguments); - renderShadow(MeshShader::GrassShadowShaderInstance, std::vector{ MeshShader::GrassShadowShaderInstance->TU_tex }, ListMatGrass::Arguments); + renderShadow(noTexUnits, ListMatDefault::Arguments); + renderShadow(noTexUnits, ListMatSphereMap::Arguments); + renderShadow(noTexUnits, ListMatUnlit::Arguments); + renderShadow(noTexUnits, ListMatDetails::Arguments); + renderShadow(noTexUnits, ListMatSplatting::Arguments); + renderShadow(noTexUnits, ListMatNormalMap::Arguments); + renderShadow(std::vector{ MeshShader::RefShadowShader::getInstance()->TU_tex }, ListMatAlphaRef::Arguments); + renderShadow(std::vector{ MeshShader::GrassShadowShader::getInstance()->TU_tex }, ListMatGrass::Arguments); glDisable(GL_POLYGON_OFFSET_FILL); diff --git a/src/graphics/shaders.cpp b/src/graphics/shaders.cpp index ad02bf0c7..da0df2802 100644 --- a/src/graphics/shaders.cpp +++ b/src/graphics/shaders.cpp @@ -408,15 +408,7 @@ void Shaders::loadShaders() MeshShader::BubbleShader::init(); MeshShader::BillboardShader::init(); LightShader::PointLightShader::init(); - MeshShader::DisplaceShaderInstance = new MeshShader::DisplaceShader(); - MeshShader::DisplaceMaskShaderInstance = new MeshShader::DisplaceMaskShader(); - MeshShader::ShadowShaderInstance = new MeshShader::ShadowShader(); MeshShader::RSMShader::init(); - MeshShader::InstancedShadowShaderInstance = new MeshShader::InstancedShadowShader(); - MeshShader::RefShadowShaderInstance = new MeshShader::RefShadowShader(); - MeshShader::InstancedRefShadowShaderInstance = new MeshShader::InstancedRefShadowShader(); - MeshShader::GrassShadowShaderInstance = new MeshShader::GrassShadowShader(); - MeshShader::InstancedGrassShadowShaderInstance = new MeshShader::InstancedGrassShadowShader(); MeshShader::SkyboxShader::init(); MeshShader::ViewFrustrumShader::init(); ParticleShader::FlipParticleRender::init(); @@ -1051,8 +1043,6 @@ namespace MeshShader glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0); } - ShadowShader *ShadowShaderInstance; - GLuint RSMShader::Program; GLuint RSMShader::uniform_MM; GLuint RSMShader::uniform_RSMMatrix; @@ -1100,8 +1090,6 @@ namespace MeshShader glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0); } - InstancedShadowShader *InstancedShadowShaderInstance; - RefShadowShader::RefShadowShader() { // Geometry shader needed @@ -1128,8 +1116,6 @@ namespace MeshShader AssignTextureUnit(Program, { TexUnit(TU_tex, "tex") }); } - RefShadowShader *RefShadowShaderInstance; - InstancedRefShadowShader::InstancedRefShadowShader() { // Geometry shader needed @@ -1156,8 +1142,6 @@ namespace MeshShader glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0); } - InstancedRefShadowShader *InstancedRefShadowShaderInstance; - GrassShadowShader::GrassShadowShader() { // Geometry shader needed @@ -1184,8 +1168,6 @@ namespace MeshShader AssignTextureUnit(Program, { TexUnit(TU_tex, "tex") }); } - GrassShadowShader *GrassShadowShaderInstance; - InstancedGrassShadowShader::InstancedGrassShadowShader() { // Geometry shader needed @@ -1214,8 +1196,6 @@ namespace MeshShader glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0); } - InstancedGrassShadowShader *InstancedGrassShadowShaderInstance; - DisplaceMaskShader::DisplaceMaskShader() { Program = LoadProgram( @@ -1227,8 +1207,6 @@ namespace MeshShader glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0); } - DisplaceMaskShader *DisplaceMaskShaderInstance; - DisplaceShader::DisplaceShader() { @@ -1250,8 +1228,6 @@ namespace MeshShader glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0); } - DisplaceShader *DisplaceShaderInstance; - GLuint SkyboxShader::Program; GLuint SkyboxShader::attrib_position; GLuint SkyboxShader::uniform_MM; diff --git a/src/graphics/shaders.hpp b/src/graphics/shaders.hpp index 2a6ccf60d..d1edda6e2 100644 --- a/src/graphics/shaders.hpp +++ b/src/graphics/shaders.hpp @@ -106,35 +106,6 @@ struct UniformHelper void bypassUBO(GLuint Program); GLuint getUniformLocation(GLuint program, const char* name); -template -class ShaderHelper -{ -protected: - std::vector uniforms; - - void AssignUniforms(const char* name) - { - uniforms.push_back(getUniformLocation(Program, name)); - } - - template - void AssignUniforms(const char* name, T... rest) - { - uniforms.push_back(getUniformLocation(Program, name)); - AssignUniforms(rest...); - } - -public: - GLuint Program; - - void setUniforms(const Args & ... args) const - { - if (needsUBO()) - bypassUBO(Program); - UniformHelper::setUniformsHelper(uniforms, args...); - } -}; - template class ShaderHelperSingleton : public Singleton { @@ -348,14 +319,12 @@ public: static void setUniforms(const core::matrix4 &ModelMatrix, float r, float g, float b); }; -class ShadowShader : public ShaderHelper +class ShadowShader : public ShaderHelperSingleton { public: ShadowShader(); }; -extern ShadowShader *ShadowShaderInstance; - class RSMShader { public: @@ -367,61 +336,47 @@ public: static void setUniforms(const core::matrix4 &RSMMatrix, const core::matrix4 &ModelMatrix); }; -class InstancedShadowShader : public ShaderHelper<> +class InstancedShadowShader : public ShaderHelperSingleton { public: InstancedShadowShader(); }; -extern InstancedShadowShader *InstancedShadowShaderInstance; - -class RefShadowShader : public ShaderHelper +class RefShadowShader : public ShaderHelperSingleton { public: GLuint TU_tex; - RefShadowShader(); }; -extern RefShadowShader *RefShadowShaderInstance; - -class InstancedRefShadowShader : public ShaderHelper<> +class InstancedRefShadowShader : public ShaderHelperSingleton { public: GLuint TU_tex; - InstancedRefShadowShader(); }; -extern InstancedRefShadowShader *InstancedRefShadowShaderInstance; - -class GrassShadowShader : public ShaderHelper +class GrassShadowShader : public ShaderHelperSingleton { public: GLuint TU_tex; GrassShadowShader(); }; -extern GrassShadowShader *GrassShadowShaderInstance; - -class InstancedGrassShadowShader : public ShaderHelper +class InstancedGrassShadowShader : public ShaderHelperSingleton { public: GLuint TU_tex; InstancedGrassShadowShader(); }; -extern InstancedGrassShadowShader *InstancedGrassShadowShaderInstance; - -class DisplaceMaskShader : public ShaderHelper +class DisplaceMaskShader : public ShaderHelperSingleton { public: DisplaceMaskShader(); }; -extern DisplaceMaskShader *DisplaceMaskShaderInstance; - -class DisplaceShader : public ShaderHelper +class DisplaceShader : public ShaderHelperSingleton { public: GLuint TU_displacement_tex, TU_mask_tex, TU_color_tex, TU_tex; @@ -429,8 +384,6 @@ public: DisplaceShader(); }; -extern DisplaceShader *DisplaceShaderInstance; - class SkyboxShader { public: diff --git a/src/graphics/stkinstancedscenenode.cpp b/src/graphics/stkinstancedscenenode.cpp index e1c6f543f..ce092faf9 100644 --- a/src/graphics/stkinstancedscenenode.cpp +++ b/src/graphics/stkinstancedscenenode.cpp @@ -156,7 +156,7 @@ static void drawShadowDefault(GLMesh &mesh, size_t instance_count) GLenum itype = mesh.IndexType; size_t count = mesh.IndexCount; - MeshShader::InstancedShadowShaderInstance->setUniforms(); + MeshShader::InstancedShadowShader::getInstance()->setUniforms(); glBindVertexArray(mesh.vao_shadow_pass); glDrawElementsInstanced(ptype, count, itype, 0, 4 * instance_count); @@ -185,8 +185,8 @@ static void drawShadowAlphaRefTexture(GLMesh &mesh, size_t instance_count) size_t count = mesh.IndexCount; compressTexture(mesh.textures[0], true); - setTexture(MeshShader::InstancedRefShadowShaderInstance->TU_tex, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true); - MeshShader::InstancedRefShadowShaderInstance->setUniforms(); + setTexture(MeshShader::InstancedRefShadowShader::getInstance()->TU_tex, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true); + MeshShader::InstancedRefShadowShader::getInstance()->setUniforms(); glBindVertexArray(mesh.vao_shadow_pass); glDrawElementsInstanced(ptype, count, itype, 0, 4 * instance_count); @@ -200,8 +200,8 @@ static void drawShadowGrass(GLMesh &mesh, const core::vector3df &windDir, size_t size_t count = mesh.IndexCount; compressTexture(mesh.textures[0], true); - setTexture(MeshShader::InstancedGrassShadowShaderInstance->TU_tex, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true); - MeshShader::InstancedGrassShadowShaderInstance->setUniforms(windDir); + setTexture(MeshShader::InstancedGrassShadowShader::getInstance()->TU_tex, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true); + MeshShader::InstancedGrassShadowShader::getInstance()->setUniforms(windDir); glBindVertexArray(mesh.vao_shadow_pass); glDrawElementsInstanced(ptype, count, itype, 0, 4 * instance_count); @@ -356,17 +356,17 @@ void STKInstancedSceneNode::render() if (irr_driver->getPhase() == SHADOW_PASS) { if (!MeshSolidMaterial[MAT_DEFAULT].empty()) - glUseProgram(MeshShader::InstancedShadowShaderInstance->Program); + glUseProgram(MeshShader::InstancedShadowShader::getInstance()->Program); for (unsigned i = 0; i < MeshSolidMaterial[MAT_DEFAULT].size(); i++) drawShadowDefault(*MeshSolidMaterial[MAT_DEFAULT][i], instance_pos.size() / 9); if (!MeshSolidMaterial[MAT_ALPHA_REF].empty()) - glUseProgram(MeshShader::InstancedRefShadowShaderInstance->Program); + glUseProgram(MeshShader::InstancedRefShadowShader::getInstance()->Program); for (unsigned i = 0; i < MeshSolidMaterial[MAT_ALPHA_REF].size(); i++) drawShadowAlphaRefTexture(*MeshSolidMaterial[MAT_ALPHA_REF][i], instance_pos.size() / 9); if (!MeshSolidMaterial[MAT_GRASS].empty()) - glUseProgram(MeshShader::InstancedGrassShadowShaderInstance->Program); + glUseProgram(MeshShader::InstancedGrassShadowShader::getInstance()->Program); for (unsigned i = 0; i < MeshSolidMaterial[MAT_GRASS].size(); i++) drawShadowGrass(*MeshSolidMaterial[MAT_GRASS][i], windDir, instance_pos.size() / 9); return; From 79fba1779e3d284034a53fcd9e03b559cea770a6 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Thu, 7 Aug 2014 00:52:44 +0200 Subject: [PATCH 02/13] Port stkbillboard to singleton shader --- data/shaders/billboard.vert | 11 +++++----- src/graphics/shaders.cpp | 38 ++++++++--------------------------- src/graphics/shaders.hpp | 16 +++++++++------ src/graphics/stkbillboard.cpp | 12 +++++------ 4 files changed, 29 insertions(+), 48 deletions(-) diff --git a/data/shaders/billboard.vert b/data/shaders/billboard.vert index 53751f9c2..a6eb64557 100644 --- a/data/shaders/billboard.vert +++ b/data/shaders/billboard.vert @@ -2,16 +2,15 @@ uniform mat4 ModelViewMatrix; uniform vec3 Position; uniform vec2 Size; -#if __VERSION__ >= 130 +#if __VERSION__ >= 330 +layout(location = 0) in vec2 Corner; +layout(location = 3) in vec2 Texcoord; +#else in vec2 Corner; in vec2 Texcoord; -out vec2 uv; -#else -attribute vec2 Corner; -attribute vec2 Texcoord; -varying vec2 uv; #endif +out vec2 uv; void main(void) { diff --git a/src/graphics/shaders.cpp b/src/graphics/shaders.cpp index da0df2802..bf77beee9 100644 --- a/src/graphics/shaders.cpp +++ b/src/graphics/shaders.cpp @@ -406,7 +406,6 @@ void Shaders::loadShaders() FullScreenShader::MLAAGatherSHader::init(); MeshShader::ColorizeShader::init(); MeshShader::BubbleShader::init(); - MeshShader::BillboardShader::init(); LightShader::PointLightShader::init(); MeshShader::RSMShader::init(); MeshShader::SkyboxShader::init(); @@ -960,40 +959,19 @@ namespace MeshShader AssignTextureUnit(Program, TexUnit(TU_tex, "tex")); } - GLuint BillboardShader::Program; - GLuint BillboardShader::attrib_corner; - GLuint BillboardShader::attrib_texcoord; - GLuint BillboardShader::uniform_MV; - GLuint BillboardShader::uniform_P; - GLuint BillboardShader::uniform_tex; - GLuint BillboardShader::uniform_Position; - GLuint BillboardShader::uniform_Size; - - void BillboardShader::init() + BillboardShader::BillboardShader() { Program = LoadProgram( GL_VERTEX_SHADER, file_manager->getAsset("shaders/billboard.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/billboard.frag").c_str()); - attrib_corner = glGetAttribLocation(Program, "Corner"); - attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); - uniform_MV = glGetUniformLocation(Program, "ModelViewMatrix"); - uniform_P = glGetUniformLocation(Program, "ProjectionMatrix"); - uniform_Position = glGetUniformLocation(Program, "Position"); - uniform_Size = glGetUniformLocation(Program, "Size"); - uniform_tex = glGetUniformLocation(Program, "tex"); - } - void BillboardShader::setUniforms(const core::matrix4 &ModelViewMatrix, - const core::matrix4 &ProjectionMatrix, - const core::vector3df &Position, - const core::dimension2d &size, - unsigned TU_tex) - { - glUniformMatrix4fv(uniform_MV, 1, GL_FALSE, ModelViewMatrix.pointer()); - glUniformMatrix4fv(uniform_P, 1, GL_FALSE, ProjectionMatrix.pointer()); - glUniform3f(uniform_Position, Position.X, Position.Y, Position.Z); - glUniform2f(uniform_Size, size.Width, size.Height); - glUniform1i(uniform_tex, TU_tex); + GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData"); + glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0); + AssignUniforms("ModelViewMatrix", "ProjectionMatrix", "Position", "Size"); + + TU_tex = 0; + + AssignTextureUnit(Program, TexUnit(TU_tex, "tex")); } GLuint ColorizeShader::Program; diff --git a/src/graphics/shaders.hpp b/src/graphics/shaders.hpp index d1edda6e2..fdccf3b07 100644 --- a/src/graphics/shaders.hpp +++ b/src/graphics/shaders.hpp @@ -94,6 +94,13 @@ struct UniformHelper setUniformsHelper(uniforms, arg...); } + template + static void setUniformsHelper(const std::vector &uniforms, const core::dimension2df &v, Args... arg) + { + glUniform2fWraper(uniforms[N], v.X, v.Y); + setUniformsHelper(uniforms, arg...); + } + template static void setUniformsHelper(const std::vector &uniforms, float f, Args... arg) { @@ -297,15 +304,12 @@ public: TransparentFogShader(); }; -class BillboardShader +class BillboardShader : public ShaderHelperSingleton { public: - static GLuint Program; - static GLuint attrib_corner, attrib_texcoord; - static GLuint uniform_MV, uniform_P, uniform_tex, uniform_Position, uniform_Size; + GLuint TU_tex; - static void init(); - static void setUniforms(const core::matrix4 &ModelViewMatrix, const core::matrix4 &ProjectionMatrix, const core::vector3df &Position, const core::dimension2d &size, unsigned TU_tex); + BillboardShader(); }; diff --git a/src/graphics/stkbillboard.cpp b/src/graphics/stkbillboard.cpp index d654463bd..d2713f032 100644 --- a/src/graphics/stkbillboard.cpp +++ b/src/graphics/stkbillboard.cpp @@ -13,10 +13,10 @@ static void createbillboardvao() glGenVertexArrays(1, &billboardvao); glBindVertexArray(billboardvao); glBindBuffer(GL_ARRAY_BUFFER, SharedObject::billboardvbo); - glEnableVertexAttribArray(MeshShader::BillboardShader::attrib_corner); - glEnableVertexAttribArray(MeshShader::BillboardShader::attrib_texcoord); - glVertexAttribPointer(MeshShader::BillboardShader::attrib_corner, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), 0); - glVertexAttribPointer(MeshShader::BillboardShader::attrib_texcoord, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (GLvoid*) (2 * sizeof(float))); + glEnableVertexAttribArray(0); + glEnableVertexAttribArray(3); + glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), 0); + glVertexAttribPointer(3, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (GLvoid*) (2 * sizeof(float))); glBindVertexArray(0); } @@ -50,8 +50,8 @@ void STKBillboard::render() compressTexture(tex, true, true); GLuint texid = getTextureGLuint(tex); setTexture(0, texid, GL_LINEAR, GL_LINEAR); - glUseProgram(MeshShader::BillboardShader::Program); - MeshShader::BillboardShader::setUniforms(irr_driver->getViewMatrix(), irr_driver->getProjMatrix(), pos, Size, 0); + glUseProgram(MeshShader::BillboardShader::getInstance()->Program); + MeshShader::BillboardShader::getInstance()->setUniforms(irr_driver->getViewMatrix(), irr_driver->getProjMatrix(), pos, Size); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glBindVertexArray(0); return; From 986fd8050a478b798a09c12247132a25a72051f4 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Thu, 7 Aug 2014 01:02:30 +0200 Subject: [PATCH 03/13] Fix ambient term. --- src/graphics/render_skybox.cpp | 8 ++++++++ src/graphics/shaders.hpp | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/graphics/render_skybox.cpp b/src/graphics/render_skybox.cpp index 6d9c2b806..17d8014b6 100644 --- a/src/graphics/render_skybox.cpp +++ b/src/graphics/render_skybox.cpp @@ -504,6 +504,14 @@ void IrrDriver::generateDiffuseCoefficients() testSH(sh_rgba, sh_w, sh_h, blueSHCoeff, greenSHCoeff, redSHCoeff); + // Diffuse env map is x 0.25, compensate + for (unsigned i = 0; i < 9; i++) + { + blueSHCoeff[i] *= 4; + greenSHCoeff[i] *= 4; + redSHCoeff[i] *= 4; + } + for (unsigned i = 0; i < 6; i++) delete[] sh_rgba[i]; } diff --git a/src/graphics/shaders.hpp b/src/graphics/shaders.hpp index fdccf3b07..f39391255 100644 --- a/src/graphics/shaders.hpp +++ b/src/graphics/shaders.hpp @@ -97,7 +97,7 @@ struct UniformHelper template static void setUniformsHelper(const std::vector &uniforms, const core::dimension2df &v, Args... arg) { - glUniform2fWraper(uniforms[N], v.X, v.Y); + glUniform2fWraper(uniforms[N], v.Width, v.Height); setUniformsHelper(uniforms, arg...); } From 024f6f3fee023baad2c88b5a3d6019e43108b7e7 Mon Sep 17 00:00:00 2001 From: Marianne Gagnon Date: Wed, 6 Aug 2014 19:33:09 -0400 Subject: [PATCH 04/13] clean up billboard text code --- src/graphics/stk_text_billboard.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/graphics/stk_text_billboard.cpp b/src/graphics/stk_text_billboard.cpp index 42f9eb88c..7f69c723d 100644 --- a/src/graphics/stk_text_billboard.cpp +++ b/src/graphics/stk_text_billboard.cpp @@ -29,7 +29,6 @@ STKTextBillboard::STKTextBillboard(core::stringw text, gui::ScalableFont* font, createGLMeshes(); Mesh->drop(); //setAutomaticCulling(0); - setReloadEachFrame(true); // FIXME: should not need that!! updateAbsolutePosition(); } @@ -157,13 +156,14 @@ void STKTextBillboard::OnRegisterSceneNode() { if (IsVisible) { - SceneManager->registerNodeForRendering(this, scene::ESNRP_TRANSPARENT); + SceneManager->registerNodeForRendering(this, scene::ESNRP_SOLID); scene::ICameraSceneNode* curr_cam = irr_driver->getSceneManager()->getActiveCamera(); core::vector3df cam_pos = curr_cam->getPosition(); core::vector3df text_pos = this->getAbsolutePosition(); float angle = atan2(text_pos.X - cam_pos.X, text_pos.Z - cam_pos.Z); this->setRotation(core::vector3df(0.0f, angle * 180.0f / M_PI, 0.0f)); + updateAbsolutePosition(); } ISceneNode::OnRegisterSceneNode(); From c0d57100a7fa4c6b8f2b25c109c20f96f556fad5 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Thu, 7 Aug 2014 01:50:53 +0200 Subject: [PATCH 05/13] Enable ref + vertex color for unlit mat. --- data/shaders/object_unlit.frag | 14 +++++--------- src/graphics/render_geometry.cpp | 2 +- src/graphics/stkanimatedmesh.cpp | 2 +- src/graphics/stkmesh.cpp | 2 +- src/graphics/stkmesh.hpp | 2 +- src/graphics/stkmeshscenenode.cpp | 2 +- 6 files changed, 10 insertions(+), 14 deletions(-) diff --git a/data/shaders/object_unlit.frag b/data/shaders/object_unlit.frag index 5c60f9f43..1d7fbb460 100644 --- a/data/shaders/object_unlit.frag +++ b/data/shaders/object_unlit.frag @@ -1,17 +1,13 @@ uniform sampler2D tex; -#if __VERSION__ >= 130 in vec2 uv; +in vec4 color; out vec4 FragColor; -#else -varying vec2 uv; -#define FragColor gl_FragColor -#endif - void main(void) { - vec4 color = texture(tex, uv); - if (color.a < 0.5) discard; - FragColor = vec4(color.xyz, 1.); + vec4 col = texture(tex, uv); + col.xyz *= pow(color.xyz, vec3(2.2)); + if (col.a * color.a < 0.5) discard; + FragColor = vec4(col.xyz, 1.); } diff --git a/src/graphics/render_geometry.cpp b/src/graphics/render_geometry.cpp index f5d2681c6..bb79c663b 100644 --- a/src/graphics/render_geometry.cpp +++ b/src/graphics/render_geometry.cpp @@ -212,9 +212,9 @@ void IrrDriver::renderSolidFirstPass() std::vector object_pass1_texunits = TexUnits(TexUnit(MeshShader::ObjectPass1Shader::getInstance()->TU_tex, true) ); renderMeshes1stPass(object_pass1_texunits, ListMatDefault::Arguments); renderMeshes1stPass(object_pass1_texunits, ListMatSphereMap::Arguments); - renderMeshes1stPass(object_pass1_texunits, ListMatUnlit::Arguments); renderMeshes1stPass(object_pass1_texunits, ListMatDetails::Arguments); renderMeshes1stPass(object_pass1_texunits, ListMatSplatting::Arguments); + renderMeshes1stPass(object_pass1_texunits, ListMatUnlit::Arguments); renderMeshes1stPass(TexUnits(TexUnit(MeshShader::ObjectRefPass1Shader::getInstance()->TU_tex, true)), ListMatAlphaRef::Arguments); renderMeshes1stPass(TexUnits(TexUnit(MeshShader::GrassPass1Shader::getInstance()->TU_tex, true)), ListMatGrass::Arguments); renderMeshes1stPass(TexUnits( diff --git a/src/graphics/stkanimatedmesh.cpp b/src/graphics/stkanimatedmesh.cpp index c331311c1..a79285d9d 100644 --- a/src/graphics/stkanimatedmesh.cpp +++ b/src/graphics/stkanimatedmesh.cpp @@ -151,7 +151,7 @@ void STKAnimatedMesh::render() pushVector(ListMatDetails::Arguments, mesh, AbsoluteTransformation, invmodel, mesh->TextureMatrix); for_in(mesh, MeshSolidMaterial[MAT_UNLIT]) - pushVector(ListMatUnlit::Arguments, mesh, AbsoluteTransformation, core::matrix4::EM4CONST_IDENTITY); + pushVector(ListMatUnlit::Arguments, mesh, AbsoluteTransformation, core::matrix4::EM4CONST_IDENTITY, mesh->TextureMatrix); return; } diff --git a/src/graphics/stkmesh.cpp b/src/graphics/stkmesh.cpp index 9b9fe2f91..201f73ad1 100644 --- a/src/graphics/stkmesh.cpp +++ b/src/graphics/stkmesh.cpp @@ -298,7 +298,7 @@ std::vector > std::vector > ListMatSphereMap::Arguments; std::vector > ListMatDetails::Arguments; std::vector > ListMatGrass::Arguments; -std::vector > ListMatUnlit::Arguments; +std::vector > ListMatUnlit::Arguments; std::vector > ListMatSplatting::Arguments; std::vector > ListMatNormalMap::Arguments; diff --git a/src/graphics/stkmesh.hpp b/src/graphics/stkmesh.hpp index af22ac89e..450610fcf 100644 --- a/src/graphics/stkmesh.hpp +++ b/src/graphics/stkmesh.hpp @@ -98,7 +98,7 @@ public: class ListMatUnlit { public: - static std::vector > Arguments; + static std::vector > Arguments; }; class ListMatDetails diff --git a/src/graphics/stkmeshscenenode.cpp b/src/graphics/stkmeshscenenode.cpp index c0918ae3d..9eb02ea03 100644 --- a/src/graphics/stkmeshscenenode.cpp +++ b/src/graphics/stkmeshscenenode.cpp @@ -265,7 +265,7 @@ void STKMeshSceneNode::render() pushVector(ListMatGrass::Arguments, mesh, AbsoluteTransformation, invmodel, windDir); for_in(mesh, MeshSolidMaterials[MAT_UNLIT]) - pushVector(ListMatUnlit::Arguments, mesh, AbsoluteTransformation, core::matrix4::EM4CONST_IDENTITY); + pushVector(ListMatUnlit::Arguments, mesh, AbsoluteTransformation, core::matrix4::EM4CONST_IDENTITY, mesh->TextureMatrix); for_in(mesh, MeshSolidMaterials[MAT_SPLATTING]) pushVector(ListMatSplatting::Arguments, mesh, AbsoluteTransformation, invmodel); From 8dcf9f6a21ef3a3a0c9573334a5f28ef415ca188 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Thu, 7 Aug 2014 01:51:10 +0200 Subject: [PATCH 06/13] Text billboard uses unlit material. --- src/graphics/stk_text_billboard.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/graphics/stk_text_billboard.cpp b/src/graphics/stk_text_billboard.cpp index 7f69c723d..1365d0ee6 100644 --- a/src/graphics/stk_text_billboard.cpp +++ b/src/graphics/stk_text_billboard.cpp @@ -92,7 +92,7 @@ scene::IMesh* STKTextBillboard::getTextMesh(core::stringw text, gui::ScalableFon { buffer = new scene::SMeshBuffer(); buffer->getMaterial().setTexture(0, m_chars[i].m_texture); - buffer->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF; + buffer->getMaterial().MaterialType = irr_driver->getShader(ES_OBJECT_UNLIT); buffers[m_chars[i].m_texture] = buffer; } else @@ -147,7 +147,7 @@ scene::IMesh* STKTextBillboard::getTextMesh(core::stringw text, gui::ScalableFon map_itr->second->drop(); } - getMaterial(0).MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF; + getMaterial(0).MaterialType = irr_driver->getShader(ES_OBJECT_UNLIT); return Mesh; } From 858b78941944cb3ad136f8b3ed771f15c175e8fa Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Thu, 7 Aug 2014 02:11:55 +0200 Subject: [PATCH 07/13] Support vertex color for alpha ref material. --- data/shaders/objectref_pass2.frag | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/data/shaders/objectref_pass2.frag b/data/shaders/objectref_pass2.frag index 0d5e8f304..c20b7e82e 100644 --- a/data/shaders/objectref_pass2.frag +++ b/data/shaders/objectref_pass2.frag @@ -1,19 +1,16 @@ uniform sampler2D Albedo; -#if __VERSION__ >= 130 in vec2 uv; +in vec4 color; out vec4 FragColor; -#else -varying vec2 uv; -#define FragColor gl_FragColor -#endif vec3 getLightFactor(float specMapValue); void main(void) { - vec4 color = texture(Albedo, uv); - if (color.a < 0.5) discard; + vec4 col = texture(Albedo, uv); + col.xyz *= pow(color.xyz, vec3(2.2)); + if (col.a * color.a < 0.5) discard; vec3 LightFactor = getLightFactor(1.); - FragColor = vec4(color.xyz * LightFactor, 1.); + FragColor = vec4(col.xyz * LightFactor, 1.); } From 87bf24216464449a7905cd23000dab4d87e1a3ab Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Thu, 7 Aug 2014 02:12:13 +0200 Subject: [PATCH 08/13] Fix shadows for unlit with alpha ref. --- data/shaders/object_unlit.frag | 2 +- src/graphics/render_geometry.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/data/shaders/object_unlit.frag b/data/shaders/object_unlit.frag index 1d7fbb460..bf5c5f3c9 100644 --- a/data/shaders/object_unlit.frag +++ b/data/shaders/object_unlit.frag @@ -8,6 +8,6 @@ void main(void) { vec4 col = texture(tex, uv); col.xyz *= pow(color.xyz, vec3(2.2)); - if (col.a * color.a < 0.5) discard; + if (col.a < 0.5) discard; FragColor = vec4(col.xyz, 1.); } diff --git a/src/graphics/render_geometry.cpp b/src/graphics/render_geometry.cpp index bb79c663b..25d5204f4 100644 --- a/src/graphics/render_geometry.cpp +++ b/src/graphics/render_geometry.cpp @@ -553,11 +553,11 @@ void IrrDriver::renderShadows() std::vector noTexUnits; renderShadow(noTexUnits, ListMatDefault::Arguments); renderShadow(noTexUnits, ListMatSphereMap::Arguments); - renderShadow(noTexUnits, ListMatUnlit::Arguments); renderShadow(noTexUnits, ListMatDetails::Arguments); renderShadow(noTexUnits, ListMatSplatting::Arguments); renderShadow(noTexUnits, ListMatNormalMap::Arguments); renderShadow(std::vector{ MeshShader::RefShadowShader::getInstance()->TU_tex }, ListMatAlphaRef::Arguments); + renderShadow(std::vector{ MeshShader::RefShadowShader::getInstance()->TU_tex }, ListMatUnlit::Arguments); renderShadow(std::vector{ MeshShader::GrassShadowShader::getInstance()->TU_tex }, ListMatGrass::Arguments); glDisable(GL_POLYGON_OFFSET_FILL); From 926fc3ac7ced0b3df0c161929e070bd87b8189ff Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Thu, 7 Aug 2014 02:29:13 +0200 Subject: [PATCH 09/13] Use singletonshader template for colorize --- src/graphics/shaders.cpp | 18 ++---------------- src/graphics/shaders.hpp | 8 ++------ src/graphics/stkmeshscenenode.cpp | 4 ++-- 3 files changed, 6 insertions(+), 24 deletions(-) diff --git a/src/graphics/shaders.cpp b/src/graphics/shaders.cpp index bf77beee9..883332f6a 100644 --- a/src/graphics/shaders.cpp +++ b/src/graphics/shaders.cpp @@ -404,7 +404,6 @@ void Shaders::loadShaders() FullScreenShader::MLAAColorEdgeDetectionSHader::init(); FullScreenShader::MLAABlendWeightSHader::init(); FullScreenShader::MLAAGatherSHader::init(); - MeshShader::ColorizeShader::init(); MeshShader::BubbleShader::init(); LightShader::PointLightShader::init(); MeshShader::RSMShader::init(); @@ -974,30 +973,17 @@ namespace MeshShader AssignTextureUnit(Program, TexUnit(TU_tex, "tex")); } - GLuint ColorizeShader::Program; - GLuint ColorizeShader::uniform_MM; - GLuint ColorizeShader::uniform_col; - - void ColorizeShader::init() + ColorizeShader::ColorizeShader() { Program = LoadProgram( GL_VERTEX_SHADER, file_manager->getAsset("shaders/object_pass.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/colorize.frag").c_str()); - uniform_MM = glGetUniformLocation(Program, "ModelMatrix"); - uniform_col = glGetUniformLocation(Program, "col"); + AssignUniforms("ModelMatrix", "col"); GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData"); glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0); } - void ColorizeShader::setUniforms(const core::matrix4 &ModelMatrix, float r, float g, float b) - { - if (irr_driver->needUBOWorkaround()) - bypassUBO(Program); - glUniformMatrix4fv(uniform_MM, 1, GL_FALSE, ModelMatrix.pointer()); - glUniform3f(uniform_col, r, g, b); - } - ShadowShader::ShadowShader() { // Geometry shader needed diff --git a/src/graphics/shaders.hpp b/src/graphics/shaders.hpp index f39391255..2d5b4c29c 100644 --- a/src/graphics/shaders.hpp +++ b/src/graphics/shaders.hpp @@ -313,14 +313,10 @@ public: }; -class ColorizeShader +class ColorizeShader : public ShaderHelperSingleton { public: - static GLuint Program; - static GLuint uniform_MM, uniform_col; - - static void init(); - static void setUniforms(const core::matrix4 &ModelMatrix, float r, float g, float b); + ColorizeShader(); }; class ShadowShader : public ShaderHelperSingleton diff --git a/src/graphics/stkmeshscenenode.cpp b/src/graphics/stkmeshscenenode.cpp index 9eb02ea03..986e72cdf 100644 --- a/src/graphics/stkmeshscenenode.cpp +++ b/src/graphics/stkmeshscenenode.cpp @@ -142,7 +142,7 @@ void STKMeshSceneNode::drawGlow(const GLMesh &mesh) GLenum itype = mesh.IndexType; size_t count = mesh.IndexCount; - MeshShader::ColorizeShader::setUniforms(AbsoluteTransformation, cb->getRed(), cb->getGreen(), cb->getBlue()); + MeshShader::ColorizeShader::getInstance()->setUniforms(AbsoluteTransformation, video::SColorf(cb->getRed(), cb->getGreen(), cb->getBlue())); glDrawElementsBaseVertex(ptype, count, itype, (GLvoid *)mesh.vaoOffset, mesh.vaoBaseVertex); } @@ -312,7 +312,7 @@ void STKMeshSceneNode::render() if (irr_driver->getPhase() == GLOW_PASS) { - glUseProgram(MeshShader::ColorizeShader::Program); + glUseProgram(MeshShader::ColorizeShader::getInstance()->Program); for (u32 i = 0; i < Mesh->getMeshBufferCount(); ++i) { scene::IMeshBuffer* mb = Mesh->getMeshBuffer(i); From 27d3d3bfb352e204ad69a8c2fc995bce5ad4cc93 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Thu, 7 Aug 2014 02:37:53 +0200 Subject: [PATCH 10/13] Add a static assert. Check if we pass correct count of uniforms name to AssignUniforms(). --- src/graphics/shaders.cpp | 20 ++++++++++---------- src/graphics/shaders.hpp | 13 +++++++++---- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/graphics/shaders.cpp b/src/graphics/shaders.cpp index 883332f6a..1727c3508 100644 --- a/src/graphics/shaders.cpp +++ b/src/graphics/shaders.cpp @@ -703,7 +703,7 @@ namespace MeshShader GL_VERTEX_SHADER, file_manager->getAsset("shaders/object_pass.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getLightFactor.frag").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/object_pass2.frag").c_str()); - AssignUniforms("ModelMatrix", "TextureMatrix", "ambient"); + AssignUniforms("ModelMatrix", "TextureMatrix"); GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData"); glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0); @@ -725,7 +725,7 @@ namespace MeshShader GL_VERTEX_SHADER, file_manager->getAsset("shaders/instanced_object_pass.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getLightFactor.frag").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/object_pass2.frag").c_str()); - AssignUniforms("ambient"); + AssignUniforms(); TU_Albedo = 3; AssignTextureUnit(Program, @@ -747,11 +747,11 @@ namespace MeshShader GL_VERTEX_SHADER, file_manager->getAsset("shaders/instanced_object_pass.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getLightFactor.frag").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/objectref_pass2.frag").c_str()); - AssignUniforms("ambient"); + AssignUniforms(); TU_Albedo = 3; AssignTextureUnit(Program, - TexUnit(0, "DiffuseMap"), + TexUnit(0, "DiffuseMap"), TexUnit(1, "SpecularMap"), TexUnit(2, "SSAO"), TexUnit(TU_Albedo, "Albedo") @@ -767,7 +767,7 @@ namespace MeshShader GL_VERTEX_SHADER, file_manager->getAsset("shaders/object_pass.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getLightFactor.frag").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/detailledobject_pass2.frag").c_str()); - AssignUniforms("ModelMatrix", "ambient"); + AssignUniforms("ModelMatrix"); GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData"); glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0); TU_Albedo = 3; @@ -803,7 +803,7 @@ namespace MeshShader GL_VERTEX_SHADER, file_manager->getAsset("shaders/object_pass.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getLightFactor.frag").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/objectref_pass2.frag").c_str()); - AssignUniforms("ModelMatrix", "TextureMatrix", "ambient"); + AssignUniforms("ModelMatrix", "TextureMatrix"); GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData"); glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0); @@ -824,7 +824,7 @@ namespace MeshShader GL_VERTEX_SHADER, file_manager->getAsset("shaders/grass_pass.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getLightFactor.frag").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/grass_pass2.frag").c_str()); - AssignUniforms("ModelMatrix", "windDir", "ambient"); + AssignUniforms("ModelMatrix", "windDir"); TU_Albedo = 3; AssignTextureUnit(Program, @@ -842,7 +842,7 @@ namespace MeshShader GL_VERTEX_SHADER, file_manager->getAsset("shaders/instanced_grass.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getLightFactor.frag").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/grass_pass2.frag").c_str()); - AssignUniforms("windDir", "SunDir", "ambient"); + AssignUniforms("windDir", "SunDir"); TU_Albedo = 3; TU_dtex = 4; @@ -865,7 +865,7 @@ namespace MeshShader GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getLightFactor.frag").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getPosFromUVDepth.frag").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/objectpass_spheremap.frag").c_str()); - AssignUniforms("ModelMatrix", "InverseModelMatrix", "ambient"); + AssignUniforms("ModelMatrix", "InverseModelMatrix"); GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData"); glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0); @@ -885,7 +885,7 @@ namespace MeshShader Program = LoadProgram( GL_VERTEX_SHADER, file_manager->getAsset("shaders/object_pass.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/splatting.frag").c_str()); - AssignUniforms("ModelMatrix", "ambient"); + AssignUniforms("ModelMatrix"); TU_tex_layout = 3; TU_tex_detail0 = 4; TU_tex_detail1 = 5; diff --git a/src/graphics/shaders.hpp b/src/graphics/shaders.hpp index 2d5b4c29c..ef163c110 100644 --- a/src/graphics/shaders.hpp +++ b/src/graphics/shaders.hpp @@ -119,16 +119,21 @@ class ShaderHelperSingleton : public Singleton protected: std::vector uniforms; - void AssignUniforms(const char* name) + void AssignUniforms_impl() { - uniforms.push_back(getUniformLocation(Program, name)); } template - void AssignUniforms(const char* name, U... rest) + void AssignUniforms_impl(const char* name, U... rest) { uniforms.push_back(getUniformLocation(Program, name)); - AssignUniforms(rest...); + AssignUniforms_impl(rest...); + } + + template + void AssignUniforms(U... rest) + { + static_assert(sizeof...(rest) == sizeof...(Args), "Count of Uniform's name mismatch"); } public: From 506dca47eb7638ba605c725510e6d5488d7d4432 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Thu, 7 Aug 2014 02:42:23 +0200 Subject: [PATCH 11/13] Better if we dont remove the real function call... --- src/graphics/shaders.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/graphics/shaders.hpp b/src/graphics/shaders.hpp index ef163c110..6b4cda5af 100644 --- a/src/graphics/shaders.hpp +++ b/src/graphics/shaders.hpp @@ -134,6 +134,7 @@ protected: void AssignUniforms(U... rest) { static_assert(sizeof...(rest) == sizeof...(Args), "Count of Uniform's name mismatch"); + AssignUniforms_impl(rest); } public: From 7c31275704870b0fae95f5ba7ede8bd3e8b3f9c0 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Thu, 7 Aug 2014 02:43:21 +0200 Subject: [PATCH 12/13] Forget the ... --- src/graphics/shaders.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/graphics/shaders.hpp b/src/graphics/shaders.hpp index 6b4cda5af..127de8d65 100644 --- a/src/graphics/shaders.hpp +++ b/src/graphics/shaders.hpp @@ -134,7 +134,7 @@ protected: void AssignUniforms(U... rest) { static_assert(sizeof...(rest) == sizeof...(Args), "Count of Uniform's name mismatch"); - AssignUniforms_impl(rest); + AssignUniforms_impl(rest...); } public: From 8544ff10e92d7c60c1a4d47ce5228547a1d31e0e Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Thu, 7 Aug 2014 02:47:07 +0200 Subject: [PATCH 13/13] Disable depth test in non dynamic light mode. Just in case... --- src/graphics/render.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/graphics/render.cpp b/src/graphics/render.cpp index 2b3bb5903..7c9a4a821 100644 --- a/src/graphics/render.cpp +++ b/src/graphics/render.cpp @@ -383,6 +383,8 @@ void IrrDriver::renderScene(scene::ICameraSceneNode * const camnode, unsigned po if (!UserConfigParams::m_dynamic_lights && !forceRTT) { glDisable(GL_FRAMEBUFFER_SRGB); + glDisable(GL_DEPTH_TEST); + glDepthMask(GL_FALSE); return; }