-
-
Notifications
You must be signed in to change notification settings - Fork 21.9k
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 Camera3D::project_position()
when depth == zfar
#98489
Conversation
df2c085
to
3e731da
Compare
As a side note, I just realized that The first thing to do would be to write unit tests for |
3e731da
to
771e561
Compare
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'm approving as the code makes sense to me and I trust the tests. I'll admit though, without doing a deep dive into the geometry I'm at a loss why this works better than the old code.
For future reference, the key change is really this : - Projection cm = _get_camera_projection(p_z_depth);
+ Projection cm = _get_camera_projection(_near); It avoids using a modified camera projection where the near plane is replaced by the user input The rest just replaces the call to Hope it clarifies. Note : As it's not called anywhere else after this PR but with the current camera's near plane as an argument (which defeats the purpose of having an argument at all ...), I'd take this opportunity to change the definition and completely remove the argument. It's a very small breaking change - as this function is |
Thanks! Congratulations on your first merged contribution! 🎉 |
Camera3D::project_position()
when depth == zfar
Fixes #95786.
Edit : Fixes #46010
This PR computes the viewport half-extents directly by finding the intersection of the camera top and right planes with a camera-facing plane positioned at the user provided depth.
Without this PR, a second projection matrix was built from the camera projection by overriding its near distance with the user provided depth (
Projection cm = _get_camera_projection(p_z_depth);
).When
p_z_depth
equals the camera far distance, the near and far distances become equal and :PROJECTION_PERSPECTIVE
mode, a subsequent call toProjection::set_perspective()
returns an identity projection. This leads to an incorrect projection of the user provided position to the view space. This is the case that is reported in Camera3D.project_position(point,z_depth) return wrong value when z_depth==far #95786PROJECTION_FRUSTUM
mode, a subsequent call toProjection::set_frustum()
raises an exceptionPROJECTION_ORTHOGONAL
mode, a subsequent call toProjection::set_orthogonal()
generates a division by zero.This PR also updates unit tests of class
Camera3D
to add the case where the provided depth = zfar.Note :
After this PR,
Camera3D::_get_camera_projection(real_t p_near)
is now exclusively called with its own camera's near value across the code (this PR removes the one and only case it was called with an user providedp_near
).It could be worth considering removing this function's parameter for the sake of code simplicity.
Note that it's a
protected
function member which means that it could be theoritically used in user modules by classes inheritingCamera3D
.I can definitely make this change in this PR or in another one if there is a consensus on making this small breaking change.