From dbcf60003bedfd16e2bb16e8278c4d0730b82a8a Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Mon, 27 Jan 2014 20:08:59 +0100 Subject: [PATCH] SunLight: Use DepthBuffer --- data/shaders/sunlight.frag | 3 ++- src/graphics/post_processing.cpp | 6 +++--- src/graphics/shaders.cpp | 6 +++++- src/graphics/shaders.hpp | 4 ++-- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/data/shaders/sunlight.frag b/data/shaders/sunlight.frag index 4075937af..fd31744c1 100644 --- a/data/shaders/sunlight.frag +++ b/data/shaders/sunlight.frag @@ -1,5 +1,6 @@ #version 130 uniform sampler2D ntex; +uniform sampler2D dtex; //uniform sampler2D cloudtex; uniform vec3 direction; @@ -14,7 +15,7 @@ out vec4 Spec; out vec4 SpecularMap; void main() { - float z = texture(ntex, uv).a; + float z = texture(dtex, uv).x; vec4 xpos = 2.0 * vec4(uv, z, 1.0) - 1.0; xpos = invproj * xpos; xpos.xyz /= xpos.w; diff --git a/src/graphics/post_processing.cpp b/src/graphics/post_processing.cpp index 186930c39..e02352216 100644 --- a/src/graphics/post_processing.cpp +++ b/src/graphics/post_processing.cpp @@ -335,9 +335,9 @@ void PostProcessing::renderSunlight() glUseProgram(FullScreenShader::SunLightShader::Program); glBindVertexArray(FullScreenShader::SunLightShader::vao); - GLuint ntex_id = static_cast(irr_driver->getRTT(RTT_NORMAL_AND_DEPTH))->getOpenGLTextureName(); - setTexture(0, ntex_id, GL_NEAREST, GL_NEAREST); - FullScreenShader::SunLightShader::setUniforms(cb->getPosition(), irr_driver->getInvProjMatrix(), cb->getRed(), cb->getGreen(), cb->getBlue(), 0); + setTexture(0, static_cast(irr_driver->getRTT(RTT_NORMAL_AND_DEPTH))->getOpenGLTextureName(), GL_NEAREST, GL_NEAREST); + setTexture(1, static_cast(irr_driver->getRTT(RTT_NORMAL_AND_DEPTH))->DepthBufferTexture, GL_NEAREST, GL_NEAREST); + FullScreenShader::SunLightShader::setUniforms(cb->getPosition(), irr_driver->getInvProjMatrix(), cb->getRed(), cb->getGreen(), cb->getBlue(), 0, 1); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glBindVertexArray(0); } diff --git a/src/graphics/shaders.cpp b/src/graphics/shaders.cpp index 091ffd991..35abd5d6a 100644 --- a/src/graphics/shaders.cpp +++ b/src/graphics/shaders.cpp @@ -1146,6 +1146,7 @@ namespace FullScreenShader GLuint SunLightShader::Program; GLuint SunLightShader::uniform_ntex; + GLuint SunLightShader::uniform_dtex; GLuint SunLightShader::uniform_direction; GLuint SunLightShader::uniform_col; GLuint SunLightShader::uniform_invproj; @@ -1155,18 +1156,21 @@ namespace FullScreenShader { Program = LoadProgram(file_manager->getAsset("shaders/screenquad.vert").c_str(), file_manager->getAsset("shaders/sunlight.frag").c_str()); uniform_ntex = glGetUniformLocation(Program, "ntex"); + uniform_dtex = glGetUniformLocation(Program, "dtex"); uniform_direction = glGetUniformLocation(Program, "direction"); uniform_col = glGetUniformLocation(Program, "col"); uniform_invproj = glGetUniformLocation(Program, "invproj"); vao = createVAO(Program); + printf("uniform %d\n", uniform_ntex); } - void SunLightShader::setUniforms(const core::vector3df &direction, const core::matrix4 &InvProjMatrix, float r, float g, float b, unsigned TU_ntex) + void SunLightShader::setUniforms(const core::vector3df &direction, const core::matrix4 &InvProjMatrix, float r, float g, float b, unsigned TU_ntex, unsigned TU_dtex) { glUniformMatrix4fv(uniform_invproj, 1, GL_FALSE, InvProjMatrix.pointer()); glUniform3f(uniform_direction, direction.X, direction.Y, direction.Z); glUniform3f(uniform_col, r, g, b); glUniform1i(uniform_ntex, TU_ntex); + glUniform1i(uniform_dtex, TU_dtex); } GLuint LightBlendShader::Program; diff --git a/src/graphics/shaders.hpp b/src/graphics/shaders.hpp index 9a754c8b4..e62ee331a 100644 --- a/src/graphics/shaders.hpp +++ b/src/graphics/shaders.hpp @@ -334,11 +334,11 @@ class SunLightShader { public: static GLuint Program; - static GLuint uniform_ntex, uniform_direction, uniform_col, uniform_invproj; + static GLuint uniform_ntex, uniform_dtex, uniform_direction, uniform_col, uniform_invproj; static GLuint vao; static void init(); - static void setUniforms(const core::vector3df &direction, const core::matrix4 &InvProjMatrix, float r, float g, float b, unsigned TU_ntex); + static void setUniforms(const core::vector3df &direction, const core::matrix4 &InvProjMatrix, float r, float g, float b, unsigned TU_ntex, unsigned TU_dtex); }; class LightBlendShader