Skip to content

Commit e62be79

Browse files
committed
Merge pull request godotengine#100350 from Namey5/visualshader-worldposfromdepth-fix
Fix space transformations in WorldPositionFromDepth visual shader node generation
2 parents 53f3143 + a85b027 commit e62be79

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

scene/resources/visual_shader_nodes.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1757,12 +1757,13 @@ String VisualShaderNodeWorldPositionFromDepth::generate_code(Shader::Mode p_mode
17571757

17581758
code += " float __log_depth = textureLod(" + make_unique_id(p_type, p_id, "depth_tex") + ", " + uv + ", 0.0).x;\n";
17591759
if (!RenderingServer::get_singleton()->is_low_end()) {
1760-
code += " vec4 __depth_view = INV_PROJECTION_MATRIX * vec4(" + uv + " * 2.0 - 1.0, __log_depth, 1.0);\n";
1760+
code += " vec4 __ndc = vec4(" + uv + " * 2.0 - 1.0, __log_depth, 1.0);\n";
17611761
} else {
1762-
code += " vec4 __depth_view = INV_PROJECTION_MATRIX * vec4(vec3(" + uv + ", __log_depth) * 2.0 - 1.0, 1.0);\n";
1762+
code += " vec4 __ndc = vec4(vec3(" + uv + ", __log_depth) * 2.0 - 1.0, 1.0);\n";
17631763
}
1764-
code += " __depth_view.xyz /= __depth_view.w;\n";
1765-
code += vformat(" %s = (INV_VIEW_MATRIX * __depth_view).xyz;\n", p_output_vars[0]);
1764+
code += " vec4 __position_world = INV_VIEW_MATRIX * INV_PROJECTION_MATRIX * __ndc;\n";
1765+
code += " __position_world.xyz /= __position_world.w;\n";
1766+
code += vformat(" %s = __position_world.xyz;\n", p_output_vars[0]);
17661767

17671768
code += " }\n";
17681769
return code;

0 commit comments

Comments
 (0)