Skip to content
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's world_pos is calculated incorrectly when in gl_compatibility #89966

Closed
wants to merge 1 commit into from

Conversation

jsjtxietian
Copy link
Contributor

@jsjtxietian jsjtxietian commented Mar 28, 2024

Fixes #89942

OpenGL ndc's z range is-1.0 to 1.0 by default while the Vulkan is 0.0 to 1.0.

@Calinou Calinou added this to the 4.3 milestone Mar 28, 2024
@Calinou Calinou added the cherrypick:4.2 Considered for cherry-picking into a future 4.2.x release label Mar 28, 2024
Comment on lines +1623 to +1625
if (OS::get_singleton()->get_current_rendering_method() == "gl_compatibility") {
code += " depth_tex = depth_tex * 2.0 - 1.0;";
}
Copy link
Member

@Calinou Calinou Mar 28, 2024

Choose a reason for hiding this comment

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

Could we make this part be introduced by the shader preprocessor, instead of a C++ condition? This way, if you convert the BaseMaterial3D to a ShaderMaterial (making its shader code fixed), it'll keep working if you switch rendering methods afterwards. This is also important to handle situations where a project can fall back to Compatibility if Vulkan isn't supported.

(Also, I thought we already had automatic depth correction when using the Compatibility rendering method, so we wouldn't have to do this.)

Copy link

Choose a reason for hiding this comment

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

Indeed it would be great if the depth_texture was driver agnostic, so the same shader code would work regardless of renderer. Or a preprocessor macro that converts it into 0-1 (and does nothing if Vulkan).

Copy link
Contributor Author

@jsjtxietian jsjtxietian Apr 1, 2024

Choose a reason for hiding this comment

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

I'm sorry for my previous explaination of this problem, let me put it more clearly: depth is 0-1 but the ndc is different in opengl and vulkan. It's introduced in #54285, it changed to vulkan way of ndc so it caused this issue.

Visual shader also use an if here, see #74910. But we'd better not use this approach as Calinou mentioned.

Copy link
Contributor

Choose a reason for hiding this comment

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

In 4.4+ we now have a way to do this with preprocessor defines. I made a PR: #100220.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In 4.4+ we now have a way to do this with preprocessor defines. I made a PR: #100220.

Seems pretty reasonable. Closing this pr now.

Copy link
Contributor

Choose a reason for hiding this comment

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

Your approach may still end up being the right one, actually. It looks like preprocessor macros don't quite work right now in the generated shaders in materials. We'll see if that ends up being considered a bug or not.

Copy link
Contributor Author

@jsjtxietian jsjtxietian Dec 10, 2024

Choose a reason for hiding this comment

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

It looks like preprocessor macros don't quite work right now in the generated shaders in materials.

I suppose this can be tweaked a little? Not sure it's a bug or not, but worth investigating.

@jsjtxietian jsjtxietian changed the title Fix proximity fade's depth_tex is set incorrectly in gl_compatibility rendering method Fix proximity fade's world_posx is calculated incorrectly when in gl_compatibility rendering method Apr 1, 2024
@jsjtxietian jsjtxietian changed the title Fix proximity fade's world_posx is calculated incorrectly when in gl_compatibility rendering method Fix proximity fade's world_pos is calculated incorrectly when in gl_compatibility Apr 1, 2024
@jsjtxietian jsjtxietian marked this pull request as draft April 8, 2024 15:59
@clayjohn clayjohn modified the milestones: 4.3, 4.4 Jul 24, 2024
@AThousandShips AThousandShips added the cherrypick:4.3 Considered for cherry-picking into a future 4.3.x release label Jul 25, 2024
@jsjtxietian jsjtxietian marked this pull request as ready for review December 10, 2024 03:52
@jsjtxietian jsjtxietian requested review from a team as code owners December 10, 2024 03:52
@jsjtxietian jsjtxietian deleted the proximity-fade branch December 10, 2024 03:52
@AThousandShips AThousandShips removed this from the 4.4 milestone Dec 10, 2024
@AThousandShips AThousandShips added archived and removed cherrypick:4.2 Considered for cherry-picking into a future 4.2.x release cherrypick:4.3 Considered for cherry-picking into a future 4.3.x release labels Dec 10, 2024
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