Merge pull request #110684 from Kaleb-Reid/fix-compat-refraction

Use correct screen-space to ndc equation in Compatibility refraction
This commit is contained in:
Thaddeus Crews 2025-10-06 09:06:43 -05:00
commit 6ece891ae6
No known key found for this signature in database
GPG key ID: 8C6E5FEB5FC03CCC

View file

@ -1813,7 +1813,8 @@ void fragment() {)";
float ref_amount = 1.0 - albedo.a * albedo_tex.a; float ref_amount = 1.0 - albedo.a * albedo_tex.a;
float refraction_depth_tex = textureLod(depth_texture, ref_ofs, 0.0).r; 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; 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. // If the depth buffer is lower then the model's Z position, use the refracted UV, otherwise use the normal screen UV.