-
-
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
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 |
Is this issue being worked on? I'm trying to make a spaceflight simulation game that has objects both near and far. |
Yes it is, although I couldn't spare time the past weeks. Note that if the farthest objects in your scene are under ~1e19m close to the camera you will not encounter any occlusion culling issue with this PR. Also you can still exclude individual objects from occlusion culling processing in case they're farther than that. |
Just worked around this issue by skipping occlusion checks when the object is too far away as @Calinou suggested : A clean fix would be to move the occlusion culling buffer back to linear z instead of the linear euclidian distance to the fragment. This would get rid of This was actually already implemented in #97712 but abandoned for other reasons (see below). The occlusion culling buffer was recently moved to euclidian distance by #98257 as one way of solving #94210. I wrapped my mind around it since then and I believe the abandoned option was actually the best choice performance wise and that the edge case is not worth the overhead introduced by the merged PR. See the discussion in #100907 |
For reference - Talking points from today's rendering meeting, with my comments added.
Not specifically, but it doesn’t prevent it either.
Yes it can. This is one of the key benefits of this PR.
This is not how it works. This PR doesn't force zfar to inf or to anything.
More context needed |
dc22261
to
03fa4af
Compare
I just fixed the crash with SDFGI (see #104120). |
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.
Tested locally, it works as expected. I've tested all 3D demo projects with all rendering methods and couldn't notice a visual regression. I also made a testing project that showcases an exponentially faster-moving camera and spheres, inspired by this demo:
Testing project: test_pr_99986.zip
I suggest modifying the 3D editor's View configuration dialog to allow using larger Z far values than 1 million units:
For comparison, this is already allowed in the Camera3D node properties.
Setting the maximum to INT32_MAX - 1
should be good enough, I suppose. (If double-precision builds support higher values, then the maximum value should be adjusted accordingly when using a double-precision build.)
Thanks @Calinou for giving it a test.
Very large z-far in editor comes with another round of numerical precision issues with picking and gizmos. |
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.
Also need to resolve the previous suggestions marked as resolved
Thanks @AThousandShips. Did I miss anything specific on the previous reviews? Will take a closer look. |
All the comments on the comments format by arkology that you marked as resolved |
Oh I see. I can't remember how I could close them without fixing... My bad. Will do it ASAP |
dad54d2
to
a69004f
Compare
The latest pushes :
Footnotes
|
Added a bunch of comments to make the use of |
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.
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 focuses on in-game rendering and camera preview in Editor.
On top of it, PR #100896 allows editing very distant objects right in Godot's editor
TODOs (now complete)
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.
Effects compatibility
I spent a considerable amount of time making sure all effects work with large zfar.
Some require additional PRs to be merged.
Test project for effects : effects.zip (make sure to preview the large znear camera in each scene)
Caveats
Optional dependencies
#99961 and #99962 may help ensuring non-regression on
Viewport
andCamera3D
.Closes godotengine/godot-proposals#10515
Closes #55070
Supersedes #95944