From 547018f0ab4079e080b0e842d54eefa0478d446e Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Fri, 22 Aug 2014 00:30:14 +0200 Subject: [PATCH] Port PointLight shader --- data/shaders/pointlight.frag | 1 - src/graphics/render_lighting.cpp | 11 ++++----- src/graphics/shaders.cpp | 41 +++++++------------------------- src/graphics/shaders.hpp | 13 ++++------ 4 files changed, 17 insertions(+), 49 deletions(-) diff --git a/data/shaders/pointlight.frag b/data/shaders/pointlight.frag index c8913fd50..c479ec7ce 100644 --- a/data/shaders/pointlight.frag +++ b/data/shaders/pointlight.frag @@ -1,6 +1,5 @@ uniform sampler2D ntex; uniform sampler2D dtex; -uniform float spec; flat in vec3 center; flat in float energy; diff --git a/src/graphics/render_lighting.cpp b/src/graphics/render_lighting.cpp index ded49f872..6017141c8 100644 --- a/src/graphics/render_lighting.cpp +++ b/src/graphics/render_lighting.cpp @@ -45,17 +45,14 @@ static void renderPointLights(unsigned count) glEnable(GL_DEPTH_TEST); glDepthMask(GL_FALSE); - glUseProgram(LightShader::PointLightShader::Program); - glBindVertexArray(LightShader::PointLightShader::vao); - glBindBuffer(GL_ARRAY_BUFFER, LightShader::PointLightShader::vbo); + glUseProgram(LightShader::PointLightShader::getInstance()->Program); + glBindVertexArray(LightShader::PointLightShader::getInstance()->vao); + glBindBuffer(GL_ARRAY_BUFFER, LightShader::PointLightShader::getInstance()->vbo); glBufferSubData(GL_ARRAY_BUFFER, 0, count * sizeof(LightShader::PointLightInfo), PointLightsInfo); setTexture(0, irr_driver->getRenderTargetTexture(RTT_NORMAL_AND_DEPTH), GL_NEAREST, GL_NEAREST); setTexture(1, irr_driver->getDepthStencilTexture(), GL_NEAREST, GL_NEAREST); - LightShader::PointLightShader - ::setUniforms(core::vector2df(float(UserConfigParams::m_width), - float(UserConfigParams::m_height)), - 200, 0, 1); + LightShader::PointLightShader::getInstance()->setUniforms(); glDrawArraysInstanced(GL_TRIANGLE_STRIP, 0, 4, count); } diff --git a/src/graphics/shaders.cpp b/src/graphics/shaders.cpp index c33a982cf..dc5fa8733 100644 --- a/src/graphics/shaders.cpp +++ b/src/graphics/shaders.cpp @@ -408,7 +408,6 @@ void Shaders::loadShaders() initShadowVPMUBO(); initParticleQuadVBO(); MeshShader::BubbleShader::init(); - LightShader::PointLightShader::init(); MeshShader::SkyboxShader::init(); MeshShader::ViewFrustrumShader::init(); UtilShader::ColoredLine::init(); @@ -1421,19 +1420,7 @@ namespace MeshShader namespace LightShader { - - GLuint PointLightShader::Program; - GLuint PointLightShader::attrib_Position; - GLuint PointLightShader::attrib_Color; - GLuint PointLightShader::attrib_Energy; - GLuint PointLightShader::attrib_Radius; - GLuint PointLightShader::uniform_ntex; - GLuint PointLightShader::uniform_dtex; - GLuint PointLightShader::uniform_spec; - GLuint PointLightShader::vbo; - GLuint PointLightShader::vao; - - void PointLightShader::init() + PointLightShader::PointLightShader() { Program = LoadProgram( GL_VERTEX_SHADER, file_manager->getAsset("shaders/pointlight.vert").c_str(), @@ -1441,13 +1428,9 @@ namespace LightShader GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getSpecular.frag").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getPosFromUVDepth.frag").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/pointlight.frag").c_str()); - attrib_Position = glGetAttribLocation(Program, "Position"); - attrib_Color = glGetAttribLocation(Program, "Color"); - attrib_Energy = glGetAttribLocation(Program, "Energy"); - attrib_Radius = glGetAttribLocation(Program, "Radius"); - uniform_ntex = glGetUniformLocation(Program, "ntex"); - uniform_dtex = glGetUniformLocation(Program, "dtex"); - uniform_spec = glGetUniformLocation(Program, "spec"); + + AssignUniforms(); + AssignSamplerNames(Program, 0, "ntex", 1, "dtex"); glGenVertexArrays(1, &vao); glBindVertexArray(vao); @@ -1456,6 +1439,11 @@ namespace LightShader glBindBuffer(GL_ARRAY_BUFFER, vbo); glBufferData(GL_ARRAY_BUFFER, MAXLIGHT * sizeof(PointLightInfo), 0, GL_DYNAMIC_DRAW); + GLuint attrib_Position = glGetAttribLocation(Program, "Position"); + GLuint attrib_Color = glGetAttribLocation(Program, "Color"); + GLuint attrib_Energy = glGetAttribLocation(Program, "Energy"); + GLuint attrib_Radius = glGetAttribLocation(Program, "Radius"); + glEnableVertexAttribArray(attrib_Position); glVertexAttribPointer(attrib_Position, 3, GL_FLOAT, GL_FALSE, sizeof(PointLightInfo), 0); glEnableVertexAttribArray(attrib_Energy); @@ -1470,17 +1458,6 @@ namespace LightShader glVertexAttribDivisor(attrib_Color, 1); glVertexAttribDivisor(attrib_Radius, 1); } - - void PointLightShader::setUniforms(const core::vector2df &screen, unsigned spec, unsigned TU_ntex, unsigned TU_dtex) - { - if (irr_driver->needUBOWorkaround()) - bypassUBO(Program); - glUniform1f(uniform_spec, 200); - - glUniform1i(uniform_ntex, TU_ntex); - glUniform1i(uniform_dtex, TU_dtex); - } - } diff --git a/src/graphics/shaders.hpp b/src/graphics/shaders.hpp index c2d009081..7fac9fd87 100644 --- a/src/graphics/shaders.hpp +++ b/src/graphics/shaders.hpp @@ -691,17 +691,12 @@ namespace LightShader }; - class PointLightShader + class PointLightShader : public ShaderHelperSingleton, TextureRead { public: - static GLuint Program; - static GLuint attrib_Position, attrib_Energy, attrib_Color, attrib_Radius; - static GLuint uniform_ntex, uniform_dtex, uniform_spec; - static GLuint vbo; - static GLuint vao; - - static void init(); - static void setUniforms(const core::vector2df &screen, unsigned spec, unsigned TU_ntex, unsigned TU_dtex); + GLuint vbo; + GLuint vao; + PointLightShader(); }; }