Skip to content

Commit 0b771d9

Browse files
authored
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
1 parent 7aaf4bb commit 0b771d9

File tree

3 files changed

+53
-48
lines changed

3 files changed

+53
-48
lines changed

crates/bevy_pbr/src/cluster/assign.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
//! Assigning objects to clusters.
22
3+
use bevy_camera::{
4+
primitives::{Aabb, Frustum, HalfSpace, Sphere},
5+
visibility::{RenderLayers, ViewVisibility},
6+
Camera,
7+
};
38
use bevy_ecs::{
49
entity::Entity,
510
query::{Has, With},
@@ -9,20 +14,18 @@ use bevy_math::{
914
ops::{self, sin_cos},
1015
Mat4, UVec3, Vec2, Vec3, Vec3A, Vec3Swizzles as _, Vec4, Vec4Swizzles as _,
1116
};
12-
use bevy_render::{
13-
camera::Camera,
14-
primitives::{Aabb, Frustum, HalfSpace, Sphere},
15-
view::{RenderLayers, ViewVisibility},
16-
};
1717
use bevy_transform::components::GlobalTransform;
1818
use bevy_utils::prelude::default;
1919
use tracing::warn;
2020

21+
use super::{
22+
ClusterConfig, ClusterFarZMode, ClusteredDecal, Clusters, GlobalClusterSettings,
23+
GlobalVisibleClusterableObjects, ViewClusterBindings, VisibleClusterableObjects,
24+
MAX_UNIFORM_BUFFER_CLUSTERABLE_OBJECTS,
25+
};
2126
use crate::{
22-
decal::clustered::ClusteredDecal, prelude::EnvironmentMapLight, ClusterConfig, ClusterFarZMode,
23-
Clusters, ExtractedPointLight, GlobalClusterSettings, GlobalVisibleClusterableObjects,
24-
LightProbe, PointLight, SpotLight, ViewClusterBindings, VisibleClusterableObjects,
25-
VolumetricLight, MAX_UNIFORM_BUFFER_CLUSTERABLE_OBJECTS,
27+
prelude::EnvironmentMapLight, ExtractedPointLight, LightProbe, PointLight, SpotLight,
28+
VolumetricLight,
2629
};
2730

2831
const NDC_MIN: Vec2 = Vec2::NEG_ONE;

crates/bevy_pbr/src/cluster/mod.rs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
33
use core::num::NonZero;
44

5+
use bevy_asset::Handle;
6+
use bevy_camera::visibility;
57
use bevy_core_pipeline::core_3d::Camera3d;
68
use bevy_ecs::{
79
component::Component,
@@ -12,23 +14,27 @@ use bevy_ecs::{
1214
system::{Commands, Query, Res},
1315
world::{FromWorld, World},
1416
};
17+
use bevy_image::Image;
1518
use bevy_math::{uvec4, AspectRatio, UVec2, UVec3, UVec4, Vec3Swizzles as _, Vec4};
1619
use bevy_platform::collections::HashSet;
1720
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
1821
use bevy_render::{
1922
camera::Camera,
23+
extract_component::ExtractComponent,
2024
render_resource::{
2125
BindingResource, BufferBindingType, ShaderSize as _, ShaderType, StorageBuffer,
2226
UniformBuffer,
2327
},
2428
renderer::{RenderAdapter, RenderDevice, RenderQueue},
2529
sync_world::RenderEntity,
30+
view::{Visibility, VisibilityClass},
2631
Extract,
2732
};
33+
use bevy_transform::components::Transform;
2834
use tracing::warn;
2935

3036
pub(crate) use crate::cluster::assign::assign_objects_to_clusters;
31-
use crate::MeshPipeline;
37+
use crate::{LightVisibilityClass, MeshPipeline};
3238

3339
pub(crate) mod assign;
3440

@@ -230,6 +236,34 @@ struct ClusterableObjectCounts {
230236
decals: u32,
231237
}
232238

239+
/// An object that projects a decal onto surfaces within its bounds.
240+
///
241+
/// Conceptually, a clustered decal is a 1×1×1 cube centered on its origin. It
242+
/// projects the given [`Self::image`] onto surfaces in the -Z direction (thus
243+
/// you may find [`Transform::looking_at`] useful).
244+
///
245+
/// Clustered decals are the highest-quality types of decals that Bevy supports,
246+
/// but they require bindless textures. This means that they presently can't be
247+
/// used on WebGL 2, WebGPU, macOS, or iOS. Bevy's clustered decals can be used
248+
/// with forward or deferred rendering and don't require a prepass.
249+
#[derive(Component, Debug, Clone, Reflect, ExtractComponent)]
250+
#[reflect(Component, Debug, Clone)]
251+
#[require(Transform, Visibility, VisibilityClass)]
252+
#[component(on_add = visibility::add_visibility_class::<LightVisibilityClass>)]
253+
pub struct ClusteredDecal {
254+
/// The image that the clustered decal projects.
255+
///
256+
/// This must be a 2D image. If it has an alpha channel, it'll be alpha
257+
/// blended with the underlying surface and/or other decals. All decal
258+
/// images in the scene must use the same sampler.
259+
pub image: Handle<Image>,
260+
261+
/// An application-specific tag you can use for any purpose you want.
262+
///
263+
/// See the `clustered_decals` example for an example of use.
264+
pub tag: u32,
265+
}
266+
233267
enum ExtractedClusterableObjectElement {
234268
ClusterHeader(ClusterableObjectCounts),
235269
ClusterableObjectEntity(Entity),

crates/bevy_pbr/src/decal/clustered.rs

Lines changed: 6 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,10 @@
1717
use core::{num::NonZero, ops::Deref};
1818

1919
use bevy_app::{App, Plugin};
20-
use bevy_asset::{AssetId, Handle};
20+
use bevy_asset::AssetId;
2121
use bevy_derive::{Deref, DerefMut};
2222
use bevy_ecs::{
23-
component::Component,
2423
entity::{Entity, EntityHashMap},
25-
prelude::ReflectComponent,
2624
query::With,
2725
resource::Resource,
2826
schedule::IntoScheduleConfigs as _,
@@ -31,10 +29,9 @@ use bevy_ecs::{
3129
use bevy_image::Image;
3230
use bevy_math::Mat4;
3331
use bevy_platform::collections::HashMap;
34-
use bevy_reflect::Reflect;
3532
pub use bevy_render::primitives::CubemapLayout;
3633
use bevy_render::{
37-
extract_component::{ExtractComponent, ExtractComponentPlugin},
34+
extract_component::ExtractComponentPlugin,
3835
load_shader_library,
3936
render_asset::RenderAssets,
4037
render_resource::{
@@ -44,15 +41,14 @@ use bevy_render::{
4441
renderer::{RenderAdapter, RenderDevice, RenderQueue},
4542
sync_world::RenderEntity,
4643
texture::{FallbackImage, GpuImage},
47-
view::{self, ViewVisibility, Visibility, VisibilityClass},
44+
view::ViewVisibility,
4845
Extract, ExtractSchedule, Render, RenderApp, RenderSystems,
4946
};
50-
use bevy_transform::{components::GlobalTransform, prelude::Transform};
47+
use bevy_transform::components::GlobalTransform;
5148
use bytemuck::{Pod, Zeroable};
5249

53-
use crate::{
54-
binding_arrays_are_usable, prepare_lights, GlobalClusterableObjectMeta, LightVisibilityClass,
55-
};
50+
pub use crate::ClusteredDecal;
51+
use crate::{binding_arrays_are_usable, prepare_lights, GlobalClusterableObjectMeta};
5652
pub use crate::{DirectionalLightTexture, PointLightTexture, SpotLightTexture};
5753

5854
/// The maximum number of decals that can be present in a view.
@@ -68,34 +64,6 @@ pub(crate) const MAX_VIEW_DECALS: usize = 8;
6864
/// can still be added to a scene, but they won't project any decals.
6965
pub struct ClusteredDecalPlugin;
7066

71-
/// An object that projects a decal onto surfaces within its bounds.
72-
///
73-
/// Conceptually, a clustered decal is a 1×1×1 cube centered on its origin. It
74-
/// projects the given [`Self::image`] onto surfaces in the -Z direction (thus
75-
/// you may find [`Transform::looking_at`] useful).
76-
///
77-
/// Clustered decals are the highest-quality types of decals that Bevy supports,
78-
/// but they require bindless textures. This means that they presently can't be
79-
/// used on WebGL 2, WebGPU, macOS, or iOS. Bevy's clustered decals can be used
80-
/// with forward or deferred rendering and don't require a prepass.
81-
#[derive(Component, Debug, Clone, Reflect, ExtractComponent)]
82-
#[reflect(Component, Debug, Clone)]
83-
#[require(Transform, Visibility, VisibilityClass)]
84-
#[component(on_add = view::add_visibility_class::<LightVisibilityClass>)]
85-
pub struct ClusteredDecal {
86-
/// The image that the clustered decal projects.
87-
///
88-
/// This must be a 2D image. If it has an alpha channel, it'll be alpha
89-
/// blended with the underlying surface and/or other decals. All decal
90-
/// images in the scene must use the same sampler.
91-
pub image: Handle<Image>,
92-
93-
/// An application-specific tag you can use for any purpose you want.
94-
///
95-
/// See the `clustered_decals` example for an example of use.
96-
pub tag: u32,
97-
}
98-
9967
/// Stores information about all the clustered decals in the scene.
10068
#[derive(Resource, Default)]
10169
pub struct RenderClusteredDecals {

0 commit comments

Comments
 (0)