-
-
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
Enable rendering with unbounded far distance #99986
base: master
Are you sure you want to change the base?
Conversation
Rebased and fixed style issues to allow CI to run. |
06693c1
to
b8eda47
Compare
Rebased on top of #99974 |
This can probably be worked around by assuming the object is visible when it's further away from the camera than this distance (and skipping any occlusion culling checks). Embree doesn't support double precision, so |
Haven't got back to this PR yet, but I think it's likely caused by an overflow with 1e19 ~ 1e20 is the threshold value that exceeds the maximum representable float value when squared (~1e38). If this overflow happens in Embree then yes, we don't have any other choice but trying to work around it. Will take a look at your suggestion once I complete the work on another incoming related PR : uncapping zfar in the editor itself. |
I got the culprit : indeed a call to
Just issued #100907 that solves the problem, and enables proper occlusion culling even on very far away objects. Edit : turns out that this fix inadvertently reverts another fix. I'm figuring out alternatives |
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