From 9927515254042619b42c1306204e390df551ef1c Mon Sep 17 00:00:00 2001 From: clayjohn Date: Tue, 24 May 2022 14:10:21 -0700 Subject: [PATCH] Disable alpha in post process when using opaque framebuffer --- drivers/gles2/rasterizer_scene_gles2.cpp | 2 ++ drivers/gles2/shaders/tonemap.glsl | 4 ++++ drivers/gles3/rasterizer_scene_gles3.cpp | 2 ++ drivers/gles3/shaders/tonemap.glsl | 4 ++++ 4 files changed, 12 insertions(+) diff --git a/drivers/gles2/rasterizer_scene_gles2.cpp b/drivers/gles2/rasterizer_scene_gles2.cpp index 107010a2d92..3e82bd33907 100644 --- a/drivers/gles2/rasterizer_scene_gles2.cpp +++ b/drivers/gles2/rasterizer_scene_gles2.cpp @@ -3192,6 +3192,7 @@ void RasterizerSceneGLES2::_post_process(Environment *env, const CameraMatrix &p } } + state.tonemap_shader.set_conditional(TonemapShaderGLES2::DISABLE_ALPHA, !storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_TRANSPARENT]); state.tonemap_shader.bind(); if (env) { if (max_glow_level >= 0) { @@ -3230,6 +3231,7 @@ void RasterizerSceneGLES2::_post_process(Environment *env, const CameraMatrix &p state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_MULTI_TEXTURE_GLOW, false); state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_BCS, false); state.tonemap_shader.set_conditional(TonemapShaderGLES2::USE_COLOR_CORRECTION, false); + state.tonemap_shader.set_conditional(TonemapShaderGLES2::DISABLE_ALPHA, false); } void RasterizerSceneGLES2::render_scene(const Transform &p_cam_transform, const CameraMatrix &p_cam_projection, const int p_eye, bool p_cam_ortogonal, InstanceBase **p_cull_result, int p_cull_count, RID *p_light_cull_result, int p_light_cull_count, RID *p_reflection_probe_cull_result, int p_reflection_probe_cull_count, RID p_environment, RID p_shadow_atlas, RID p_reflection_atlas, RID p_reflection_probe, int p_reflection_probe_pass) { diff --git a/drivers/gles2/shaders/tonemap.glsl b/drivers/gles2/shaders/tonemap.glsl index aaa6ae5498f..a35826642b3 100644 --- a/drivers/gles2/shaders/tonemap.glsl +++ b/drivers/gles2/shaders/tonemap.glsl @@ -357,4 +357,8 @@ void main() { #endif gl_FragColor = color; + +#ifdef DISABLE_ALPHA + gl_FragColor.a = 1.0; +#endif } diff --git a/drivers/gles3/rasterizer_scene_gles3.cpp b/drivers/gles3/rasterizer_scene_gles3.cpp index c6641e1bc6f..f1d21a0865e 100644 --- a/drivers/gles3/rasterizer_scene_gles3.cpp +++ b/drivers/gles3/rasterizer_scene_gles3.cpp @@ -4001,6 +4001,7 @@ void RasterizerSceneGLES3::_post_process(Environment *env, const CameraMatrix &p } } + state.tonemap_shader.set_conditional(TonemapShaderGLES3::DISABLE_ALPHA, !storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_TRANSPARENT]); state.tonemap_shader.set_conditional(TonemapShaderGLES3::V_FLIP, storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_VFLIP]); state.tonemap_shader.bind(); @@ -4064,6 +4065,7 @@ void RasterizerSceneGLES3::_post_process(Environment *env, const CameraMatrix &p state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_BCS, false); state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_COLOR_CORRECTION, false); state.tonemap_shader.set_conditional(TonemapShaderGLES3::V_FLIP, false); + state.tonemap_shader.set_conditional(TonemapShaderGLES3::DISABLE_ALPHA, false); } bool RasterizerSceneGLES3::_element_needs_directional_add(RenderList::Element *e) { diff --git a/drivers/gles3/shaders/tonemap.glsl b/drivers/gles3/shaders/tonemap.glsl index f2639772ce6..5f160e22eca 100644 --- a/drivers/gles3/shaders/tonemap.glsl +++ b/drivers/gles3/shaders/tonemap.glsl @@ -489,4 +489,8 @@ void main() { #endif frag_color = color; + +#ifdef DISABLE_ALPHA + frag_color.a = 1.0; +#endif }