Add color buffer to compute proper space screen reflexion

This commit is contained in:
samuncle 2019-03-09 11:10:47 +01:00
parent 13d121e45d
commit a5e40f9a8a
4 changed files with 17 additions and 9 deletions

View File

@ -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;

View File

@ -168,7 +168,7 @@ public:
};
// ============================================================================
class IBLShader : public TextureShader<IBLShader, 3>
class IBLShader : public TextureShader<IBLShader, 4>
{
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

View File

@ -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,

View File

@ -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();