diff --git a/data/shaders/IBL.frag b/data/shaders/IBL.frag index 3759cdb68..b1e015485 100644 --- a/data/shaders/IBL.frag +++ b/data/shaders/IBL.frag @@ -1,6 +1,6 @@ uniform sampler2D ntex; uniform sampler2D dtex; -uniform sampler2D colorBuffer; +uniform sampler2D albedo; #ifdef GL_ES layout (location = 0) out vec4 Diff; @@ -26,7 +26,7 @@ vec3 getXcYcZc(int x, int y, float zC) float makeLinear(float f, float n, float z) { - return pow(z, 10);//(2 * n) / (f + n - z * (f - n)); + return (2 * n) / (f + n - z * (f - n)); } @@ -66,7 +66,7 @@ vec3 RayCast(vec3 dir, inout vec3 hitCoord, out float dDepth, in sampler2D Depth if ((projectedCoord.x > 0.0 && projectedCoord.x < 1.0) && (projectedCoord.y > 0.0 && projectedCoord.y < 1.0)) { // Mix with fallback (black area should be dark anyway) - vec3 finalColor = textureLod(ntex, projectedCoord.xy, 1.0).rgb; + vec3 finalColor = textureLod(albedo, projectedCoord.xy, 1.0).rgb; if ((finalColor.r + finalColor.g + finalColor.b) > 0.) { return finalColor; diff --git a/src/graphics/lighting_passes.cpp b/src/graphics/lighting_passes.cpp index 051a59b17..159e816fd 100644 --- a/src/graphics/lighting_passes.cpp +++ b/src/graphics/lighting_passes.cpp @@ -168,7 +168,7 @@ public: }; // ============================================================================ -class IBLShader : public TextureShader +class IBLShader : public TextureShader { public: IBLShader() @@ -178,7 +178,8 @@ public: assignUniforms(); assignSamplerNames(0, "ntex", ST_NEAREST_FILTERED, 1, "dtex", ST_NEAREST_FILTERED, - 2, "probe", ST_TRILINEAR_CUBEMAP); + 2, "probe", ST_TRILINEAR_CUBEMAP, + 3, "albedo",ST_NEAREST_FILTERED); } // IBLShader }; // IBLShader @@ -293,7 +294,8 @@ static void renderPointLights(unsigned count, // ---------------------------------------------------------------------------- void LightingPasses::renderEnvMap(GLuint normal_depth_texture, GLuint depth_stencil_texture, - GLuint specular_probe) + GLuint specular_probe, + GLuint albedo_buffer) { glDisable(GL_DEPTH_TEST); glEnable(GL_BLEND); @@ -317,7 +319,8 @@ void LightingPasses::renderEnvMap(GLuint normal_depth_texture, IBLShader::getInstance()->setTextureUnits( normal_depth_texture, depth_stencil_texture, - specular_probe); + specular_probe, + albedo_buffer); IBLShader::getInstance()->setUniforms(); } @@ -426,6 +429,7 @@ void LightingPasses::updateLightsInfo(scene::ICameraSceneNode * const camnode, void LightingPasses::renderLights( bool has_shadow, GLuint normal_depth_texture, GLuint depth_stencil_texture, + GLuint albedo_texture, const FrameBuffer* shadow_framebuffer, GLuint specular_probe) { @@ -433,7 +437,8 @@ void LightingPasses::renderLights( bool has_shadow, ScopedGPUTimer timer(irr_driver->getGPUTimer(Q_ENVMAP)); renderEnvMap(normal_depth_texture, depth_stencil_texture, - specular_probe); + specular_probe, + albedo_texture); } // Render sunlight if and only if track supports shadow diff --git a/src/graphics/lighting_passes.hpp b/src/graphics/lighting_passes.hpp index 522c2782b..441706471 100644 --- a/src/graphics/lighting_passes.hpp +++ b/src/graphics/lighting_passes.hpp @@ -34,7 +34,8 @@ private: void renderEnvMap(GLuint normal_depth_texture, GLuint depth_stencil_texture, - GLuint specular_probe); + GLuint specular_probe, + GLuint albedo_buffer); /** Generate diffuse and specular map */ void renderSunlight(const core::vector3df &direction, @@ -50,6 +51,7 @@ public: void renderLights( bool has_shadow, GLuint normal_depth_texture, GLuint depth_stencil_texture, + GLuint albedo_texture, const FrameBuffer* shadow_framebuffer, GLuint specular_probe); void renderLightsScatter(GLuint depth_stencil_texture, diff --git a/src/graphics/shader_based_renderer.cpp b/src/graphics/shader_based_renderer.cpp index 433a15a01..70924b3dd 100644 --- a/src/graphics/shader_based_renderer.cpp +++ b/src/graphics/shader_based_renderer.cpp @@ -279,6 +279,7 @@ void ShaderBasedRenderer::renderSceneDeferred(scene::ICameraSceneNode * const ca m_lighting_passes.renderLights( hasShadow, m_rtts->getRenderTarget(RTT_NORMAL_AND_DEPTH), m_rtts->getDepthStencilTexture(), + m_rtts->getRenderTarget(RTT_SP_DIFF_COLOR), m_rtts->getShadowFrameBuffer(), specular_probe); PROFILER_POP_CPU_MARKER();