-
-
Notifications
You must be signed in to change notification settings - Fork 21.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix proximity fade in Compatibility renderer #100220
base: master
Are you sure you want to change the base?
Conversation
@@ -1716,7 +1716,11 @@ void fragment() {)"; | |||
code += R"( | |||
// Proximity Fade: Enabled | |||
float proximity_depth_tex = textureLod(depth_texture, SCREEN_UV, 0.0).r; | |||
#if CURRENT_RENDERER == RENDERER_COMPATIBILITY | |||
vec4 proximity_view_pos = INV_PROJECTION_MATRIX * vec4(SCREEN_UV * 2.0 - 1.0, proximity_depth_tex * 2.0 - 1.0, 1.0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternately:
vec4 proximity_view_pos = INV_PROJECTION_MATRIX * vec4(SCREEN_UV * 2.0 - 1.0, proximity_depth_tex * 2.0 - 1.0, 1.0); | |
vec4 proximity_view_pos = INV_PROJECTION_MATRIX * vec4(vec3(SCREEN_UV, proximity_depth_tex) * 2.0 - 1.0, 1.0); |
We could also do something more like this, leaving the "default" case of Forward+/Mobile implicit:
float proximity_depth_tex = textureLod(depth_texture, SCREEN_UV, 0.0).r;
#if CURRENT_RENDERER == RENDERER_COMPATIBILITY
proximity_depth_tex = proximity_depth_tex * 2.0 - 1.0;
#endif
vec4 proximity_view_pos = INV_PROJECTION_MATRIX * vec4(SCREEN_UV * 2.0 - 1.0, proximity_depth_tex, 1.0);
But I think the current form is the most explicit and clear about exactly what changes between the renderers.
Looks like this runs into the same problem as #97646 (comment) - the preprocessor is not available in BaseMaterial3D. Either that's an engine bug that can be fixed, or this PR is not actually the right approach, and something more like #89966 is right.
|
Instead of using the preprocessor, you can do the |
Yeah, the hope was to avoid that, so that the material is correct in multiple renderers even after being converted to a ShaderMaterial. The superseded PR already takes a similar approach with conditionally added C++, and was apparently deferred for a while in the hope that we could use the preprocessor somehow instead. |
Fixes #89942.
Supersedes #89966.
Uses the correct NDC for the Compatibility renderer.
Uses the preprocessor defines for the current renderer introduced in 4.4 in #98549. We also document a nearly identical reconstruction of world space using NDC in this tutorial, which now uses the preprocessor defines to be renderer-independent.