move ClusteredDecal to cluster module (#19959)
# Objective - Make bevy_light possible by making it possible to split out clusterable into bevy_camera ## Solution - move ClusteredDecal to cluster module - Depends on #19957 (because of the imports shuffling around) (draft until thats merged) ## Testing - 3d_scene runs Note: no breaking changes thanks to re-exports
This commit is contained in:
parent
7aaf4bbd94
commit
0b771d9f59
@ -1,5 +1,10 @@
|
|||||||
//! Assigning objects to clusters.
|
//! Assigning objects to clusters.
|
||||||
|
|
||||||
|
use bevy_camera::{
|
||||||
|
primitives::{Aabb, Frustum, HalfSpace, Sphere},
|
||||||
|
visibility::{RenderLayers, ViewVisibility},
|
||||||
|
Camera,
|
||||||
|
};
|
||||||
use bevy_ecs::{
|
use bevy_ecs::{
|
||||||
entity::Entity,
|
entity::Entity,
|
||||||
query::{Has, With},
|
query::{Has, With},
|
||||||
@ -9,20 +14,18 @@ use bevy_math::{
|
|||||||
ops::{self, sin_cos},
|
ops::{self, sin_cos},
|
||||||
Mat4, UVec3, Vec2, Vec3, Vec3A, Vec3Swizzles as _, Vec4, Vec4Swizzles as _,
|
Mat4, UVec3, Vec2, Vec3, Vec3A, Vec3Swizzles as _, Vec4, Vec4Swizzles as _,
|
||||||
};
|
};
|
||||||
use bevy_render::{
|
|
||||||
camera::Camera,
|
|
||||||
primitives::{Aabb, Frustum, HalfSpace, Sphere},
|
|
||||||
view::{RenderLayers, ViewVisibility},
|
|
||||||
};
|
|
||||||
use bevy_transform::components::GlobalTransform;
|
use bevy_transform::components::GlobalTransform;
|
||||||
use bevy_utils::prelude::default;
|
use bevy_utils::prelude::default;
|
||||||
use tracing::warn;
|
use tracing::warn;
|
||||||
|
|
||||||
|
use super::{
|
||||||
|
ClusterConfig, ClusterFarZMode, ClusteredDecal, Clusters, GlobalClusterSettings,
|
||||||
|
GlobalVisibleClusterableObjects, ViewClusterBindings, VisibleClusterableObjects,
|
||||||
|
MAX_UNIFORM_BUFFER_CLUSTERABLE_OBJECTS,
|
||||||
|
};
|
||||||
use crate::{
|
use crate::{
|
||||||
decal::clustered::ClusteredDecal, prelude::EnvironmentMapLight, ClusterConfig, ClusterFarZMode,
|
prelude::EnvironmentMapLight, ExtractedPointLight, LightProbe, PointLight, SpotLight,
|
||||||
Clusters, ExtractedPointLight, GlobalClusterSettings, GlobalVisibleClusterableObjects,
|
VolumetricLight,
|
||||||
LightProbe, PointLight, SpotLight, ViewClusterBindings, VisibleClusterableObjects,
|
|
||||||
VolumetricLight, MAX_UNIFORM_BUFFER_CLUSTERABLE_OBJECTS,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const NDC_MIN: Vec2 = Vec2::NEG_ONE;
|
const NDC_MIN: Vec2 = Vec2::NEG_ONE;
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
use core::num::NonZero;
|
use core::num::NonZero;
|
||||||
|
|
||||||
|
use bevy_asset::Handle;
|
||||||
|
use bevy_camera::visibility;
|
||||||
use bevy_core_pipeline::core_3d::Camera3d;
|
use bevy_core_pipeline::core_3d::Camera3d;
|
||||||
use bevy_ecs::{
|
use bevy_ecs::{
|
||||||
component::Component,
|
component::Component,
|
||||||
@ -12,23 +14,27 @@ use bevy_ecs::{
|
|||||||
system::{Commands, Query, Res},
|
system::{Commands, Query, Res},
|
||||||
world::{FromWorld, World},
|
world::{FromWorld, World},
|
||||||
};
|
};
|
||||||
|
use bevy_image::Image;
|
||||||
use bevy_math::{uvec4, AspectRatio, UVec2, UVec3, UVec4, Vec3Swizzles as _, Vec4};
|
use bevy_math::{uvec4, AspectRatio, UVec2, UVec3, UVec4, Vec3Swizzles as _, Vec4};
|
||||||
use bevy_platform::collections::HashSet;
|
use bevy_platform::collections::HashSet;
|
||||||
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
|
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
|
||||||
use bevy_render::{
|
use bevy_render::{
|
||||||
camera::Camera,
|
camera::Camera,
|
||||||
|
extract_component::ExtractComponent,
|
||||||
render_resource::{
|
render_resource::{
|
||||||
BindingResource, BufferBindingType, ShaderSize as _, ShaderType, StorageBuffer,
|
BindingResource, BufferBindingType, ShaderSize as _, ShaderType, StorageBuffer,
|
||||||
UniformBuffer,
|
UniformBuffer,
|
||||||
},
|
},
|
||||||
renderer::{RenderAdapter, RenderDevice, RenderQueue},
|
renderer::{RenderAdapter, RenderDevice, RenderQueue},
|
||||||
sync_world::RenderEntity,
|
sync_world::RenderEntity,
|
||||||
|
view::{Visibility, VisibilityClass},
|
||||||
Extract,
|
Extract,
|
||||||
};
|
};
|
||||||
|
use bevy_transform::components::Transform;
|
||||||
use tracing::warn;
|
use tracing::warn;
|
||||||
|
|
||||||
pub(crate) use crate::cluster::assign::assign_objects_to_clusters;
|
pub(crate) use crate::cluster::assign::assign_objects_to_clusters;
|
||||||
use crate::MeshPipeline;
|
use crate::{LightVisibilityClass, MeshPipeline};
|
||||||
|
|
||||||
pub(crate) mod assign;
|
pub(crate) mod assign;
|
||||||
|
|
||||||
@ -230,6 +236,34 @@ struct ClusterableObjectCounts {
|
|||||||
decals: u32,
|
decals: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// An object that projects a decal onto surfaces within its bounds.
|
||||||
|
///
|
||||||
|
/// Conceptually, a clustered decal is a 1×1×1 cube centered on its origin. It
|
||||||
|
/// projects the given [`Self::image`] onto surfaces in the -Z direction (thus
|
||||||
|
/// you may find [`Transform::looking_at`] useful).
|
||||||
|
///
|
||||||
|
/// Clustered decals are the highest-quality types of decals that Bevy supports,
|
||||||
|
/// but they require bindless textures. This means that they presently can't be
|
||||||
|
/// used on WebGL 2, WebGPU, macOS, or iOS. Bevy's clustered decals can be used
|
||||||
|
/// with forward or deferred rendering and don't require a prepass.
|
||||||
|
#[derive(Component, Debug, Clone, Reflect, ExtractComponent)]
|
||||||
|
#[reflect(Component, Debug, Clone)]
|
||||||
|
#[require(Transform, Visibility, VisibilityClass)]
|
||||||
|
#[component(on_add = visibility::add_visibility_class::<LightVisibilityClass>)]
|
||||||
|
pub struct ClusteredDecal {
|
||||||
|
/// The image that the clustered decal projects.
|
||||||
|
///
|
||||||
|
/// This must be a 2D image. If it has an alpha channel, it'll be alpha
|
||||||
|
/// blended with the underlying surface and/or other decals. All decal
|
||||||
|
/// images in the scene must use the same sampler.
|
||||||
|
pub image: Handle<Image>,
|
||||||
|
|
||||||
|
/// An application-specific tag you can use for any purpose you want.
|
||||||
|
///
|
||||||
|
/// See the `clustered_decals` example for an example of use.
|
||||||
|
pub tag: u32,
|
||||||
|
}
|
||||||
|
|
||||||
enum ExtractedClusterableObjectElement {
|
enum ExtractedClusterableObjectElement {
|
||||||
ClusterHeader(ClusterableObjectCounts),
|
ClusterHeader(ClusterableObjectCounts),
|
||||||
ClusterableObjectEntity(Entity),
|
ClusterableObjectEntity(Entity),
|
||||||
|
@ -17,12 +17,10 @@
|
|||||||
use core::{num::NonZero, ops::Deref};
|
use core::{num::NonZero, ops::Deref};
|
||||||
|
|
||||||
use bevy_app::{App, Plugin};
|
use bevy_app::{App, Plugin};
|
||||||
use bevy_asset::{AssetId, Handle};
|
use bevy_asset::AssetId;
|
||||||
use bevy_derive::{Deref, DerefMut};
|
use bevy_derive::{Deref, DerefMut};
|
||||||
use bevy_ecs::{
|
use bevy_ecs::{
|
||||||
component::Component,
|
|
||||||
entity::{Entity, EntityHashMap},
|
entity::{Entity, EntityHashMap},
|
||||||
prelude::ReflectComponent,
|
|
||||||
query::With,
|
query::With,
|
||||||
resource::Resource,
|
resource::Resource,
|
||||||
schedule::IntoScheduleConfigs as _,
|
schedule::IntoScheduleConfigs as _,
|
||||||
@ -31,10 +29,9 @@ use bevy_ecs::{
|
|||||||
use bevy_image::Image;
|
use bevy_image::Image;
|
||||||
use bevy_math::Mat4;
|
use bevy_math::Mat4;
|
||||||
use bevy_platform::collections::HashMap;
|
use bevy_platform::collections::HashMap;
|
||||||
use bevy_reflect::Reflect;
|
|
||||||
pub use bevy_render::primitives::CubemapLayout;
|
pub use bevy_render::primitives::CubemapLayout;
|
||||||
use bevy_render::{
|
use bevy_render::{
|
||||||
extract_component::{ExtractComponent, ExtractComponentPlugin},
|
extract_component::ExtractComponentPlugin,
|
||||||
load_shader_library,
|
load_shader_library,
|
||||||
render_asset::RenderAssets,
|
render_asset::RenderAssets,
|
||||||
render_resource::{
|
render_resource::{
|
||||||
@ -44,15 +41,14 @@ use bevy_render::{
|
|||||||
renderer::{RenderAdapter, RenderDevice, RenderQueue},
|
renderer::{RenderAdapter, RenderDevice, RenderQueue},
|
||||||
sync_world::RenderEntity,
|
sync_world::RenderEntity,
|
||||||
texture::{FallbackImage, GpuImage},
|
texture::{FallbackImage, GpuImage},
|
||||||
view::{self, ViewVisibility, Visibility, VisibilityClass},
|
view::ViewVisibility,
|
||||||
Extract, ExtractSchedule, Render, RenderApp, RenderSystems,
|
Extract, ExtractSchedule, Render, RenderApp, RenderSystems,
|
||||||
};
|
};
|
||||||
use bevy_transform::{components::GlobalTransform, prelude::Transform};
|
use bevy_transform::components::GlobalTransform;
|
||||||
use bytemuck::{Pod, Zeroable};
|
use bytemuck::{Pod, Zeroable};
|
||||||
|
|
||||||
use crate::{
|
pub use crate::ClusteredDecal;
|
||||||
binding_arrays_are_usable, prepare_lights, GlobalClusterableObjectMeta, LightVisibilityClass,
|
use crate::{binding_arrays_are_usable, prepare_lights, GlobalClusterableObjectMeta};
|
||||||
};
|
|
||||||
pub use crate::{DirectionalLightTexture, PointLightTexture, SpotLightTexture};
|
pub use crate::{DirectionalLightTexture, PointLightTexture, SpotLightTexture};
|
||||||
|
|
||||||
/// The maximum number of decals that can be present in a view.
|
/// The maximum number of decals that can be present in a view.
|
||||||
@ -68,34 +64,6 @@ pub(crate) const MAX_VIEW_DECALS: usize = 8;
|
|||||||
/// can still be added to a scene, but they won't project any decals.
|
/// can still be added to a scene, but they won't project any decals.
|
||||||
pub struct ClusteredDecalPlugin;
|
pub struct ClusteredDecalPlugin;
|
||||||
|
|
||||||
/// An object that projects a decal onto surfaces within its bounds.
|
|
||||||
///
|
|
||||||
/// Conceptually, a clustered decal is a 1×1×1 cube centered on its origin. It
|
|
||||||
/// projects the given [`Self::image`] onto surfaces in the -Z direction (thus
|
|
||||||
/// you may find [`Transform::looking_at`] useful).
|
|
||||||
///
|
|
||||||
/// Clustered decals are the highest-quality types of decals that Bevy supports,
|
|
||||||
/// but they require bindless textures. This means that they presently can't be
|
|
||||||
/// used on WebGL 2, WebGPU, macOS, or iOS. Bevy's clustered decals can be used
|
|
||||||
/// with forward or deferred rendering and don't require a prepass.
|
|
||||||
#[derive(Component, Debug, Clone, Reflect, ExtractComponent)]
|
|
||||||
#[reflect(Component, Debug, Clone)]
|
|
||||||
#[require(Transform, Visibility, VisibilityClass)]
|
|
||||||
#[component(on_add = view::add_visibility_class::<LightVisibilityClass>)]
|
|
||||||
pub struct ClusteredDecal {
|
|
||||||
/// The image that the clustered decal projects.
|
|
||||||
///
|
|
||||||
/// This must be a 2D image. If it has an alpha channel, it'll be alpha
|
|
||||||
/// blended with the underlying surface and/or other decals. All decal
|
|
||||||
/// images in the scene must use the same sampler.
|
|
||||||
pub image: Handle<Image>,
|
|
||||||
|
|
||||||
/// An application-specific tag you can use for any purpose you want.
|
|
||||||
///
|
|
||||||
/// See the `clustered_decals` example for an example of use.
|
|
||||||
pub tag: u32,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Stores information about all the clustered decals in the scene.
|
/// Stores information about all the clustered decals in the scene.
|
||||||
#[derive(Resource, Default)]
|
#[derive(Resource, Default)]
|
||||||
pub struct RenderClusteredDecals {
|
pub struct RenderClusteredDecals {
|
||||||
|
Loading…
Reference in New Issue
Block a user