Skip to content

Commit 6ece891

Browse files
committed
Merge pull request godotengine#110684 from Kaleb-Reid/fix-compat-refraction
Use correct screen-space to ndc equation in Compatibility refraction
2 parents 6febc2b + 96ca7a2 commit 6ece891

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

scene/resources/material.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1813,7 +1813,8 @@ void fragment() {)";
18131813
float ref_amount = 1.0 - albedo.a * albedo_tex.a;
18141814
18151815
float refraction_depth_tex = textureLod(depth_texture, ref_ofs, 0.0).r;
1816-
vec4 refraction_view_pos = INV_PROJECTION_MATRIX * vec4(SCREEN_UV * 2.0 - 1.0, refraction_depth_tex, 1.0);
1816+
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);
1817+
vec4 refraction_view_pos = INV_PROJECTION_MATRIX * ndc;
18171818
refraction_view_pos.xyz /= refraction_view_pos.w;
18181819
18191820
// If the depth buffer is lower then the model's Z position, use the refracted UV, otherwise use the normal screen UV.

0 commit comments

Comments
 (0)