Skip to content

Commit

Permalink
Disable alpha depth in the editor.
Browse files Browse the repository at this point in the history
  • Loading branch information
bawr committed Oct 20, 2022
1 parent b73765c commit 982b2f2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
7 changes: 7 additions & 0 deletions drivers/gles3/rasterizer_scene_gles3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3871,6 +3871,12 @@ void RasterizerSceneGLES3::_post_process(Environment *env, const CameraMatrix &p
glGetFramebufferAttachmentParameteriv(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME, &depth_texture_id);
glBindTexture(GL_TEXTURE_2D, depth_texture_id);

if (Engine::get_singleton()->is_editor_hint()) {
state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_ALPHA_DEPTH_CHANNEL, false);
} else {
state.tonemap_shader.set_conditional(TonemapShaderGLES3::USE_ALPHA_DEPTH_CHANNEL, true);
}

glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, composite_from);
if (env) {
Expand Down Expand Up @@ -3998,6 +4004,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::USE_ALPHA_DEPTH_CHANNEL, false);
}

bool RasterizerSceneGLES3::_element_needs_directional_add(RenderList::Element *e) {
Expand Down
8 changes: 6 additions & 2 deletions drivers/gles3/shaders/tonemap.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -475,11 +475,15 @@ void main() {
color = apply_color_correction(color, color_correction);
#endif

#ifdef USE_ALPHA_DEPTH_CHANNEL
highp float depth = textureLod(sdepth, uv_interp, 0.0f).r;
const float d_min = 0.01; // camera near
const float d_max = 1000; // camera far
const float d_min = 0.01f; // camera near
const float d_max = 1000f; // camera far
depth = d_min / ((1.0 - depth) + (d_min / d_max));
depth = clamp(1.0 / (depth + 0.5), 0.0, 1.0);
#else
float depth = 1.0f;
#endif

frag_color = vec4(color, depth);
}

0 comments on commit 982b2f2

Please sign in to comment.