Skip to content

armgit / godot

Public Imported from GitHub
0

Godot Engine – Multi-platform 2D and 3D game engine

Fixed duplicate variable names when refraction and proximity fade are enabled in BaseMaterial3D

GameBeast428098a71128
diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp
index 8dddb418736..35852bf103d 100644
--- a/scene/resources/material.cpp
+++ b/scene/resources/material.cpp
@@ -1803,8 +1803,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 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;
+ vec4 refraction_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 * refraction_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.
@@ -1833,8 +1833,8 @@ void fragment() {)";
code += vformat(R"(
// Proximity Fade: Enabled
float proximity_depth_tex = textureLod(depth_texture, SCREEN_UV, 0.0).r;
- vec4 ndc = OUTPUT_IS_SRGB ? vec4(vec3(SCREEN_UV, proximity_depth_tex) * 2.0 - 1.0, 1.0) : vec4(SCREEN_UV * 2.0 - 1.0, proximity_depth_tex, 1.0);
- vec4 proximity_view_pos = INV_PROJECTION_MATRIX * ndc;
+ vec4 proximity_ndc = OUTPUT_IS_SRGB ? vec4(vec3(SCREEN_UV, proximity_depth_tex) * 2.0 - 1.0, 1.0) : vec4(SCREEN_UV * 2.0 - 1.0, proximity_depth_tex, 1.0);
+ vec4 proximity_view_pos = INV_PROJECTION_MATRIX * proximity_ndc;
proximity_view_pos.xyz /= proximity_view_pos.w;
ALPHA *= clamp(1.0 - smoothstep(proximity_view_pos.z %s proximity_fade_distance, proximity_view_pos.z, VERTEX.z), 0.0, 1.0);
)",