Avoid windows with a physical size of zero (#4098)
# Objective Fix #4097 ## Solution Return `None` from `RenderTarget::get_physical_size` if either dimension is zero.
This commit is contained in:
parent
3b81a50a1a
commit
0d2b527faf
@ -389,6 +389,13 @@ impl Clusters {
|
|||||||
// NOTE: Maximum 4096 clusters due to uniform buffer size constraints
|
// NOTE: Maximum 4096 clusters due to uniform buffer size constraints
|
||||||
debug_assert!(self.dimensions.x * self.dimensions.y * self.dimensions.z <= 4096);
|
debug_assert!(self.dimensions.x * self.dimensions.y * self.dimensions.z <= 4096);
|
||||||
}
|
}
|
||||||
|
fn clear(&mut self) {
|
||||||
|
self.tile_size = UVec2::ONE;
|
||||||
|
self.dimensions = UVec3::ONE;
|
||||||
|
self.near = 0.0;
|
||||||
|
self.far = 0.0;
|
||||||
|
self.lights.clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn clip_to_view(inverse_projection: Mat4, clip: Vec4) -> Vec4 {
|
fn clip_to_view(inverse_projection: Mat4, clip: Vec4) -> Vec4 {
|
||||||
@ -722,17 +729,22 @@ pub(crate) fn assign_lights_to_clusters(
|
|||||||
for (view_entity, camera_transform, camera, frustum, config, clusters, mut visible_lights) in
|
for (view_entity, camera_transform, camera, frustum, config, clusters, mut visible_lights) in
|
||||||
views.iter_mut()
|
views.iter_mut()
|
||||||
{
|
{
|
||||||
|
let clusters = clusters.into_inner();
|
||||||
|
|
||||||
if matches!(config, ClusterConfig::None) && visible_lights.is_some() {
|
if matches!(config, ClusterConfig::None) && visible_lights.is_some() {
|
||||||
commands.entity(view_entity).remove::<VisiblePointLights>();
|
commands.entity(view_entity).remove::<VisiblePointLights>();
|
||||||
|
clusters.clear();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
let clusters = clusters.into_inner();
|
let screen_size =
|
||||||
let screen_size = camera.target.get_physical_size(&windows, &images);
|
if let Some(screen_size) = camera.target.get_physical_size(&windows, &images) {
|
||||||
|
screen_size
|
||||||
|
} else {
|
||||||
|
clusters.clear();
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
|
||||||
clusters.lights.clear();
|
|
||||||
|
|
||||||
let screen_size = screen_size.unwrap_or_default();
|
|
||||||
let mut requested_cluster_dimensions = config.dimensions_for_screen_size(screen_size);
|
let mut requested_cluster_dimensions = config.dimensions_for_screen_size(screen_size);
|
||||||
|
|
||||||
let view_transform = camera_transform.compute_matrix();
|
let view_transform = camera_transform.compute_matrix();
|
||||||
@ -862,10 +874,6 @@ pub(crate) fn assign_lights_to_clusters(
|
|||||||
VisiblePointLights::default,
|
VisiblePointLights::default,
|
||||||
);
|
);
|
||||||
|
|
||||||
if screen_size.x == 0 || screen_size.y == 0 {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Calculate the x/y/z cluster frustum planes in view space
|
// Calculate the x/y/z cluster frustum planes in view space
|
||||||
let mut x_planes = Vec::with_capacity(clusters.dimensions.x as usize + 1);
|
let mut x_planes = Vec::with_capacity(clusters.dimensions.x as usize + 1);
|
||||||
let mut y_planes = Vec::with_capacity(clusters.dimensions.y as usize + 1);
|
let mut y_planes = Vec::with_capacity(clusters.dimensions.y as usize + 1);
|
||||||
@ -923,16 +931,7 @@ pub(crate) fn assign_lights_to_clusters(
|
|||||||
z_planes.push(Plane::new(normal.extend(d)));
|
z_planes.push(Plane::new(normal.extend(d)));
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut visible_lights_scratch = Vec::new();
|
let mut update_from_light_intersections = |visible_lights: &mut Vec<Entity>| {
|
||||||
|
|
||||||
{
|
|
||||||
// reuse existing visible lights Vec, if it exists
|
|
||||||
let visible_lights = if let Some(visible_lights) = visible_lights.as_mut() {
|
|
||||||
visible_lights.entities.clear();
|
|
||||||
&mut visible_lights.entities
|
|
||||||
} else {
|
|
||||||
&mut visible_lights_scratch
|
|
||||||
};
|
|
||||||
for light in lights.iter() {
|
for light in lights.iter() {
|
||||||
let light_sphere = Sphere {
|
let light_sphere = Sphere {
|
||||||
center: Vec3A::from(light.translation),
|
center: Vec3A::from(light.translation),
|
||||||
@ -1085,12 +1084,18 @@ pub(crate) fn assign_lights_to_clusters(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
if visible_lights.is_none() {
|
// reuse existing visible lights Vec, if it exists
|
||||||
commands.entity(view_entity).insert(VisiblePointLights {
|
if let Some(visible_lights) = visible_lights.as_mut() {
|
||||||
entities: visible_lights_scratch,
|
visible_lights.entities.clear();
|
||||||
});
|
update_from_light_intersections(&mut visible_lights.entities);
|
||||||
|
} else {
|
||||||
|
let mut entities = Vec::new();
|
||||||
|
update_from_light_intersections(&mut entities);
|
||||||
|
commands
|
||||||
|
.entity(view_entity)
|
||||||
|
.insert(VisiblePointLights { entities });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -79,6 +79,7 @@ impl RenderTarget {
|
|||||||
UVec2::new(width, height)
|
UVec2::new(width, height)
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
|
.filter(|size| size.x > 0 && size.y > 0)
|
||||||
}
|
}
|
||||||
pub fn get_logical_size(&self, windows: &Windows, images: &Assets<Image>) -> Option<Vec2> {
|
pub fn get_logical_size(&self, windows: &Windows, images: &Assets<Image>) -> Option<Vec2> {
|
||||||
match self {
|
match self {
|
||||||
@ -312,8 +313,8 @@ pub fn extract_cameras<M: Component + Default>(
|
|||||||
ExtractedView {
|
ExtractedView {
|
||||||
projection: camera.projection_matrix,
|
projection: camera.projection_matrix,
|
||||||
transform: *transform,
|
transform: *transform,
|
||||||
width: size.x.max(1),
|
width: size.x,
|
||||||
height: size.y.max(1),
|
height: size.y,
|
||||||
near: camera.near,
|
near: camera.near,
|
||||||
far: camera.far,
|
far: camera.far,
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user