-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Introduce support for far culling when using PerspectiveProjection
#16789
base: main
Are you sure you want to change the base?
Conversation
Welcome, new contributor! Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨ |
@@ -241,18 +241,24 @@ impl Frustum { | |||
|
|||
/// Returns a frustum derived from `clip_from_world`, | |||
/// but with a custom far plane. | |||
/// If `far` is `None` behavior is identical to [`Frustum::from_clip_from_world`] |
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 seems like the least expectation defying change but not sure it's the best approach?
let world_from_local = transform.affine(); | ||
let model_sphere = Sphere { | ||
center: world_from_local.transform_point3a(model_aabb.center), | ||
radius: transform.radius_vec3a(model_aabb.half_extents), | ||
}; | ||
// Do quick sphere-based frustum culling | ||
if !frustum.intersects_sphere(&model_sphere, false) { | ||
if !frustum.intersects_sphere(&model_sphere, use_far_culling) { |
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 thought this would preserve existing behaviour when using the default projections, but maybe I'm misunderstanding as OrthographicProjection
previously far culled even though we always passed false
here and to intersects_obb
?
let cursor_ray_len = cam_ortho.far - cam_ortho.near; | ||
let cursor_ray_len = cam_ortho | ||
.far | ||
.unwrap_or(OrthographicProjection::DEFAULT_FAR_PLANE) |
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 is definitely wrong and I'm open to suggestions. Would also allow DEFAULT_FAR_PLANE
not to be pub
.
let mut projection = PerspectiveProjection::default(); | ||
projection.far = projection.far.max(size * 10.0); | ||
projection.far = projection |
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 preserves the existing intention (I think...) but feels odd as the default would be an essentialy infinite far plane anyway?
b336c59
to
a555da5
Compare
Note
An update of #8205 for 0.15 and with review suggestions.
All credit to @NotoriousENG
Objective
PerspectiveProjection
would only account for near, left, right, top, and bottom planes with no trivial user facing overridesfar
#16746Solution
CameraProjection::far()
and it's impls fromf32
toOption<f32>
far
defaults toOrthographicProjection
andPerspectiveProjection
OrthographicProjection
=Some(OrthographicProjection::DEFAULT_FAR_PLANE)
Equivalent to existing behaviour of far clipping at
1000.0
PerspectiveProjection
=None
Equivalent to existing behaviour of not far clipping at all
Frustum::from_clip_from_world_custom_far
to account forfar
becoming optionalbevy_render::view::visibility::check_visibility
to perform far culling when appropriateChangelog
OrthographicProjection
andPerspectiveProjection
with an explicitfar
value will need to wrap the value inSome
CameraProjection
will need updating to account for the changed return type offar()
Frustum::from_clip_from_world_custom_far
in downstream code will need updating to account for the changed type of thefar
parameter