-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Enable rendering with unbounded far distance #99986
Open
Flarkk
wants to merge
1
commit into
godotengine:master
Choose a base branch
from
Flarkk:large_zfar
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
+782
−199
Conversation
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
arkology
reviewed
Dec 4, 2024
Rebased and fixed style issues to allow CI to run. |
Flarkk
force-pushed
the
large_zfar
branch
3 times, most recently
from
December 4, 2024 09:09
06693c1
to
b8eda47
Compare
23 tasks
Flarkk
changed the title
Unbound camera zfar for scene rendering
Enable rendering with unbounded far distance
Dec 5, 2024
Rebased on top of #99974 |
4 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR allows rendering with unlimited camera zfar - or rather limited by the sole floating point range i.e. ~3.4e+38 in single precision.
This effectively untaps the potential of reverse-z depth buffer with single precision build, in all 3 renderers Forward+, Mobile and Compatibility. XR is not covered though (see notes below).
Outline
Currently zfar cannot be pushed further than barely ~1e6 times znear because of numerical precision limitations with some methods of struct
Projection
.With the default znear = 0.05 this sets the maximum view distance to ~50 km.
While it's enough in most cases, it can be a hard limitation for open worlds, space games, and any very large scene.
Beyond this limit, scene rendering currently breaks and Godot starts spaming errors.
This PR removes this limitation with 3 key changes :
Frustum
with a few helper methods for convenience. This avoids relying ofVector<Plane>
everywhere and improves readabilityThis PR is in a good enough state to get first reviews. There are still a few details to be ironed out though :
Demo : full-scale scene
large_zfar.zip
Vegetation is ~1m tall and ~10m from the observer
The terrain is 10 km large
The moon's radius is 1,700 km and is 400,000 km from the observer
The Andromeda galaxy is 152,000 light-years wide and is 2.5 million light years from the observer
Performance
This PR improves very slightly the frame process time of an empty scene by ~ 0.5%.
This is likely due to the significant number of planes retrieval operations avoided by the fact the 6 planes are already made available.
Notes
Test project for effects : effects.zip (make sure to preview the large znear camera in each scene)
Camera3D
frustum functions #99961 and Add tests forViewport
's camera override functions #99962 help ensuring non-regression onViewport
andCamera3D
Closes godotengine/godot-proposals#10515
Closes #55070
Supersedes #95944