From 96ca7a205d5e7bbdac1ead253f06083a71c464d8 Mon Sep 17 00:00:00 2001 From: Kaleb Reid <78945904+Kaleb-Reid@users.noreply.github.com> Date: Sat, 4 Oct 2025 02:03:31 -0700 Subject: [PATCH] Use correct ndc equation in Compatibility refraction --- scene/resources/material.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp index 48e8fd8e8ce..64d4fd8e176 100644 --- a/scene/resources/material.cpp +++ b/scene/resources/material.cpp @@ -1813,7 +1813,8 @@ void fragment() {)"; float ref_amount = 1.0 - albedo.a * albedo_tex.a; float refraction_depth_tex = textureLod(depth_texture, ref_ofs, 0.0).r; - vec4 refraction_view_pos = INV_PROJECTION_MATRIX * vec4(SCREEN_UV * 2.0 - 1.0, refraction_depth_tex, 1.0); + vec4 ndc = OUTPUT_IS_SRGB ? vec4(vec3(SCREEN_UV, refraction_depth_tex) * 2.0 - 1.0, 1.0) : vec4(SCREEN_UV * 2.0 - 1.0, refraction_depth_tex, 1.0); + vec4 refraction_view_pos = INV_PROJECTION_MATRIX * ndc; refraction_view_pos.xyz /= refraction_view_pos.w; // If the depth buffer is lower then the model's Z position, use the refracted UV, otherwise use the normal screen UV.