-
-
Notifications
You must be signed in to change notification settings - Fork 22k
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 space transformations in WorldPositionFromDepth visual shader node generation #100350
Merged
Repiteo
merged 1 commit into
godotengine:master
from
Namey5:visualshader-worldposfromdepth-fix
Jan 22, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is z still supposed to be not reversed in low end ?
I thought reverse-z was introduced in all 3 renderers.
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.
I believe this isn't reverse-z, but rather the difference in how z is represented in NDC-space between OpenGL [-1, 1] and everything else [0, 1]
https://gamedev.stackexchange.com/questions/29018/why-does-opengl-require-all-coordinates-in-1-1-ndc
I'm not sure specifically what Godot does with depth in the OpenGL renderer (without a floating point depth buffer in [0,1] range reverse-z wouldn't really help, but it also wouldn't hurt and would keep things consistent) but these changes do appear to work in all 3 renderers.
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.
It seems like
is_low_end()
returnsfalse
in all cases :godot/servers/rendering/renderer_compositor.cpp
Lines 39 to 40 in ba2c5c1
I'm wondering if we shouldn't completely remove this branch.
Anybody please step in.
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.
It does appear to be overridden in the GLES3 backend:
godot/drivers/gles3/rasterizer_gles3.h
Line 124 in ba2c5c1
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.
Ah yeah good catch.
But isn't GLES supposed to have [0,1] Zs too ? Sorry if this brings confusion, but I'm confused myself now 😄
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.
Would it be worth adding a comment for this branch directly in
generate_code()
just to make it clearer? The same NDC branch is used in a couple of other nodes in this file.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.
Do you mean a comment in the C++ code or a comment in the generated shader (that will be visible to end users)? Either way I'm not opposed, but I'm also not sure if that's idiomatic for these visual shader nodes. So let's also get a second opinion.
If you add a comment for it, I think you should only add it to this specific shader node, not the others, to keep the changes localized.
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.
Yeah just a comment in the C++ code, the branch wouldn't exist in the generated output. I think most of the confusion is the use of
RenderingServer::is_low_end()
- would be nice if there was an equivalent to the above mentionedCLIP_SPACE_FAR
in C++ (or even better-er to useCLIP_SPACE_FAR
directly in the generated output itself so people copying it get correct outputs regardless of renderer).I'll leave it as-is for now though as it does match the behaviour in the existing nodes.
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.
This will make it a bit clearer already #100384
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.
I think it's fine to defer the potential comments or other code changes for later.