Skip to content

Commit

Permalink
Merge pull request #74910 from paddy-exe/fix-ndc-depth-gles3
Browse files Browse the repository at this point in the history
Fix ndc calculation for LinearSceneDepth VS node in GLES3
  • Loading branch information
YuriSizov authored Mar 16, 2023
2 parents dd8841a + e3802d5 commit bdefdc8
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions scene/resources/visual_shader_nodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1709,8 +1709,11 @@ String VisualShaderNodeLinearSceneDepth::generate_code(Shader::Mode p_mode, Visu
code += " {\n";

code += " float __log_depth = textureLod(" + make_unique_id(p_type, p_id, "depth_tex") + ", SCREEN_UV, 0.0).x;\n";
code += " vec3 __depth_ndc = vec3(SCREEN_UV * 2.0 - 1.0, __log_depth);\n";
code += " vec4 __depth_view = INV_PROJECTION_MATRIX * vec4(__depth_ndc, 1.0);\n";
if (!RenderingServer::get_singleton()->is_low_end()) {
code += " vec4 __depth_view = INV_PROJECTION_MATRIX * vec4(SCREEN_UV * 2.0 - 1.0, __log_depth, 1.0);\n";
} else {
code += " vec4 __depth_view = INV_PROJECTION_MATRIX * vec4(vec3(SCREEN_UV, __log_depth) * 2.0 - 1.0, 1.0);\n";
}
code += " __depth_view.xyz /= __depth_view.w;\n";
code += vformat(" %s = -__depth_view.z;\n", p_output_vars[0]);

Expand Down

0 comments on commit bdefdc8

Please sign in to comment.