X Tutup
Skip to content

Use correct ndc for proximity fade in Compatibility#111437

Merged
Repiteo merged 1 commit intogodotengine:masterfrom
Kaleb-Reid:compat-fix-proximity-fade
Oct 22, 2025
Merged

Use correct ndc for proximity fade in Compatibility#111437
Repiteo merged 1 commit intogodotengine:masterfrom
Kaleb-Reid:compat-fix-proximity-fade

Conversation

@Kaleb-Reid
Copy link
Contributor

I believe this is the only other place in BaseMaterial where the depth texture is used aside from refraction, which requires different math between the RD renderers and Compatibility. The other prs either fail shader compilation or output sub-optimal shader code when converting to ShaderMaterial in the editor.

Fixes #89942

Supersedes #100220

@AThousandShips AThousandShips added this to the 4.6 milestone Oct 9, 2025
@AThousandShips AThousandShips requested a review from a team October 9, 2025 08:16
@AThousandShips AThousandShips added the cherrypick:4.5 Considered for cherry-picking into a future 4.5.x release label Oct 9, 2025
Comment on lines +1845 to +1846
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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a comment to explain why this is done:

Suggested change
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;
// Use correct normalized device coordinates on Compatibility.
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;

Copy link
Member

@Calinou Calinou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

Ideally, we'd use the shader preprocessor to avoid (static) branching, but this is better than the status quo.

@clayjohn
Copy link
Member

Looks good to me.

Ideally, we'd use the shader preprocessor to avoid (static) branching, but this is better than the status quo.

This code will get optimized at compile time since OUTPUT_IS_SRGB is a compile time constant. The run time performance will be the same as using the shader preprocessor

@Repiteo Repiteo merged commit 8f3e76c into godotengine:master Oct 22, 2025
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Oct 22, 2025

Thanks!

@akien-mga
Copy link
Member

Cherry-picked for 4.5.2.

@akien-mga akien-mga removed the cherrypick:4.5 Considered for cherry-picking into a future 4.5.x release label Jan 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Proximity Fade broken in Compatibility (OpenGL)

6 participants

X Tutup