Skip to content

Commit

Permalink
Reflect derived traits on all components and resources: bevy_pbr (#15224
Browse files Browse the repository at this point in the history
)

Solves #15187 for bevy_pbr
  • Loading branch information
blazepaws authored Sep 15, 2024
1 parent d878e2f commit b6b28a6
Show file tree
Hide file tree
Showing 15 changed files with 37 additions and 27 deletions.
5 changes: 3 additions & 2 deletions crates/bevy_pbr/src/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use bevy_asset::Handle;
use bevy_derive::{Deref, DerefMut};
use bevy_ecs::entity::{Entity, EntityHashMap};
use bevy_ecs::{bundle::Bundle, component::Component, reflect::ReflectComponent};
use bevy_reflect::std_traits::ReflectDefault;
use bevy_reflect::Reflect;
use bevy_render::{
mesh::Mesh,
Expand Down Expand Up @@ -50,14 +51,14 @@ impl<M: Material> Default for MaterialMeshBundle<M> {
/// This component contains all mesh entities visible from the current light view.
/// The collection is updated automatically by [`crate::SimulationLightSystems`].
#[derive(Component, Clone, Debug, Default, Reflect, Deref, DerefMut)]
#[reflect(Component)]
#[reflect(Component, Debug, Default)]
pub struct VisibleMeshEntities {
#[reflect(ignore)]
pub entities: Vec<Entity>,
}

#[derive(Component, Clone, Debug, Default, Reflect)]
#[reflect(Component)]
#[reflect(Component, Debug, Default)]
pub struct CubemapVisibleEntities {
#[reflect(ignore)]
data: [VisibleMeshEntities; 6],
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_pbr/src/cluster/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pub struct ClusterZConfig {

/// Configuration of the clustering strategy for clustered forward rendering
#[derive(Debug, Copy, Clone, Component, Reflect)]
#[reflect(Component)]
#[reflect(Component, Debug, Default)]
pub enum ClusterConfig {
/// Disable cluster calculations for this view
None,
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_pbr/src/fog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ use bevy_render::{extract_component::ExtractComponent, prelude::Camera};
/// [`StandardMaterial`](crate::StandardMaterial) instances via the `fog_enabled` flag.
#[derive(Debug, Clone, Component, Reflect, ExtractComponent)]
#[extract_component_filter(With<Camera>)]
#[reflect(Component, Default)]
#[reflect(Component, Default, Debug)]
pub struct DistanceFog {
/// The color of the fog effect.
///
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_pbr/src/light/ambient_light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use super::*;
/// }
/// ```
#[derive(Resource, Clone, Debug, ExtractResource, Reflect)]
#[reflect(Resource)]
#[reflect(Resource, Debug, Default)]
pub struct AmbientLight {
pub color: Color,
/// A direct scale factor multiplied with `color` before being passed to the shader.
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_pbr/src/light/directional_light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ use super::*;
/// .insert_resource(DirectionalLightShadowMap { size: 2048 });
/// ```
#[derive(Component, Debug, Clone, Reflect)]
#[reflect(Component, Default)]
#[reflect(Component, Default, Debug)]
pub struct DirectionalLight {
pub color: Color,
/// Illuminance in lux (lumens per square meter), representing the amount of
Expand Down
16 changes: 8 additions & 8 deletions crates/bevy_pbr/src/light/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub mod light_consts {
}

#[derive(Resource, Clone, Debug, Reflect)]
#[reflect(Resource)]
#[reflect(Resource, Debug, Default)]
pub struct PointLightShadowMap {
pub size: usize,
}
Expand All @@ -105,7 +105,7 @@ pub type WithLight = Or<(With<PointLight>, With<SpotLight>, With<DirectionalLigh

/// Controls the resolution of [`DirectionalLight`] shadow maps.
#[derive(Resource, Clone, Debug, Reflect)]
#[reflect(Resource)]
#[reflect(Resource, Debug, Default)]
pub struct DirectionalLightShadowMap {
pub size: usize,
}
Expand All @@ -130,7 +130,7 @@ impl Default for DirectionalLightShadowMap {
/// }.into();
/// ```
#[derive(Component, Clone, Debug, Reflect)]
#[reflect(Component, Default)]
#[reflect(Component, Default, Debug)]
pub struct CascadeShadowConfig {
/// The (positive) distance to the far boundary of each cascade.
pub bounds: Vec<f32>,
Expand Down Expand Up @@ -271,7 +271,7 @@ impl From<CascadeShadowConfigBuilder> for CascadeShadowConfig {
}

#[derive(Component, Clone, Debug, Default, Reflect)]
#[reflect(Component)]
#[reflect(Component, Debug, Default)]
pub struct Cascades {
/// Map from a view to the configuration of each of its [`Cascade`]s.
pub(crate) cascades: EntityHashMap<Vec<Cascade>>,
Expand Down Expand Up @@ -439,15 +439,15 @@ fn calculate_cascade(
}
/// Add this component to make a [`Mesh`] not cast shadows.
#[derive(Debug, Component, Reflect, Default)]
#[reflect(Component, Default)]
#[reflect(Component, Default, Debug)]
pub struct NotShadowCaster;
/// Add this component to make a [`Mesh`] not receive shadows.
///
/// **Note:** If you're using diffuse transmission, setting [`NotShadowReceiver`] will
/// cause both “regular” shadows as well as diffusely transmitted shadows to be disabled,
/// even when [`TransmittedShadowReceiver`] is being used.
#[derive(Debug, Component, Reflect, Default)]
#[reflect(Component, Default)]
#[reflect(Component, Default, Debug)]
pub struct NotShadowReceiver;
/// Add this component to make a [`Mesh`] using a PBR material with [`diffuse_transmission`](crate::pbr_material::StandardMaterial::diffuse_transmission)`> 0.0`
/// receive shadows on its diffuse transmission lobe. (i.e. its “backside”)
Expand All @@ -457,7 +457,7 @@ pub struct NotShadowReceiver;
///
/// **Note:** Using [`NotShadowReceiver`] overrides this component.
#[derive(Debug, Component, Reflect, Default)]
#[reflect(Component, Default)]
#[reflect(Component, Default, Debug)]
pub struct TransmittedShadowReceiver;

/// Add this component to a [`Camera3d`](bevy_core_pipeline::core_3d::Camera3d)
Expand All @@ -466,7 +466,7 @@ pub struct TransmittedShadowReceiver;
/// The different modes use different approaches to
/// [Percentage Closer Filtering](https://developer.nvidia.com/gpugems/gpugems/part-ii-lighting-and-shadows/chapter-11-shadow-map-antialiasing).
#[derive(Debug, Component, ExtractComponent, Reflect, Clone, Copy, PartialEq, Eq, Default)]
#[reflect(Component, Default)]
#[reflect(Component, Default, Debug, PartialEq)]
pub enum ShadowFilteringMethod {
/// Hardware 2x2.
///
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_pbr/src/light/point_light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use super::*;
///
/// Source: [Wikipedia](https://en.wikipedia.org/wiki/Lumen_(unit)#Lighting)
#[derive(Component, Debug, Clone, Copy, Reflect)]
#[reflect(Component, Default)]
#[reflect(Component, Default, Debug)]
pub struct PointLight {
/// The color of this light source.
pub color: Color,
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_pbr/src/light/spot_light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use super::*;
/// shines light only in a given direction. The direction is taken from
/// the transform, and can be specified with [`Transform::looking_at`](Transform::looking_at).
#[derive(Component, Debug, Clone, Copy, Reflect)]
#[reflect(Component, Default)]
#[reflect(Component, Default, Debug)]
pub struct SpotLight {
pub color: Color,
/// Luminous power in lumens, representing the amount of light emitted by this source in all directions.
Expand Down
5 changes: 4 additions & 1 deletion crates/bevy_pbr/src/light_probe/environment_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@

use bevy_asset::{AssetId, Handle};
use bevy_ecs::{
bundle::Bundle, component::Component, query::QueryItem, system::lifetimeless::Read,
bundle::Bundle, component::Component, query::QueryItem, reflect::ReflectComponent,
system::lifetimeless::Read,
};
use bevy_math::Quat;
use bevy_reflect::std_traits::ReflectDefault;
use bevy_reflect::Reflect;
use bevy_render::{
extract_instances::ExtractInstance,
Expand Down Expand Up @@ -84,6 +86,7 @@ pub const ENVIRONMENT_MAP_SHADER_HANDLE: Handle<Shader> =
///
/// See [`crate::environment_map`] for detailed information.
#[derive(Clone, Component, Reflect)]
#[reflect(Component, Default)]
pub struct EnvironmentMapLight {
/// The blurry image that represents diffuse radiance surrounding a region.
pub diffuse_map: Handle<Image>,
Expand Down
4 changes: 3 additions & 1 deletion crates/bevy_pbr/src/light_probe/irradiance_volume.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
//!
//! [Why ambient cubes?]: #why-ambient-cubes

use bevy_ecs::component::Component;
use bevy_ecs::{component::Component, reflect::ReflectComponent};
use bevy_render::{
render_asset::RenderAssets,
render_resource::{
Expand All @@ -145,6 +145,7 @@ use bevy_render::{
use std::{num::NonZero, ops::Deref};

use bevy_asset::{AssetId, Handle};
use bevy_reflect::std_traits::ReflectDefault;
use bevy_reflect::Reflect;

use crate::{
Expand All @@ -166,6 +167,7 @@ pub(crate) const IRRADIANCE_VOLUMES_ARE_USABLE: bool = cfg!(not(target_arch = "w
///
/// See [`crate::irradiance_volume`] for detailed information.
#[derive(Clone, Default, Reflect, Component, Debug)]
#[reflect(Component, Default, Debug)]
pub struct IrradianceVolume {
/// The 3D texture that represents the ambient cubes, encoded in the format
/// described in [`crate::irradiance_volume`].
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_pbr/src/light_probe/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ pub struct LightProbePlugin;
/// specific technique but rather to a class of techniques. Developers familiar
/// with other engines should be aware of this terminology difference.
#[derive(Component, Debug, Clone, Copy, Default, Reflect)]
#[reflect(Component, Default)]
#[reflect(Component, Default, Debug)]
pub struct LightProbe;

/// A GPU type that stores information about a light probe.
Expand Down
2 changes: 2 additions & 0 deletions crates/bevy_pbr/src/material.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use bevy_ecs::{
prelude::*,
system::{lifetimeless::SRes, SystemParamItem},
};
use bevy_reflect::std_traits::ReflectDefault;
use bevy_reflect::Reflect;
use bevy_render::{
camera::TemporalJitter,
Expand Down Expand Up @@ -825,6 +826,7 @@ pub fn queue_material_meshes<M: Material>(

/// Default render method used for opaque materials.
#[derive(Default, Resource, Clone, Debug, ExtractResource, Reflect)]
#[reflect(Resource, Default, Debug)]
pub struct DefaultOpaqueRendererMethod(OpaqueRendererMethod);

impl DefaultOpaqueRendererMethod {
Expand Down
3 changes: 2 additions & 1 deletion crates/bevy_pbr/src/ssao/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use bevy_ecs::{
system::{Commands, Query, Res, ResMut, Resource},
world::{FromWorld, World},
};
use bevy_reflect::std_traits::ReflectDefault;
use bevy_reflect::Reflect;
use bevy_render::{
camera::{ExtractedCamera, TemporalJitter},
Expand Down Expand Up @@ -154,7 +155,7 @@ pub struct ScreenSpaceAmbientOcclusionBundle {
///
/// SSAO is not supported on `WebGL2`, and is not currently supported on `WebGPU` or `DirectX12`.
#[derive(Component, ExtractComponent, Reflect, PartialEq, Eq, Hash, Clone, Default, Debug)]
#[reflect(Component)]
#[reflect(Component, Debug, Default, Hash, PartialEq)]
#[doc(alias = "Ssao")]
pub struct ScreenSpaceAmbientOcclusion {
pub quality_level: ScreenSpaceAmbientOcclusionQualityLevel,
Expand Down
7 changes: 4 additions & 3 deletions crates/bevy_pbr/src/volumetric_fog/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ use bevy_math::{
primitives::{Cuboid, Plane3d},
Vec2, Vec3,
};
use bevy_reflect::std_traits::ReflectDefault;
use bevy_reflect::Reflect;
use bevy_render::{
mesh::{Mesh, Meshable},
Expand Down Expand Up @@ -71,14 +72,14 @@ pub struct VolumetricFogPlugin;
///
/// This allows the light to generate light shafts/god rays.
#[derive(Clone, Copy, Component, Default, Debug, Reflect)]
#[reflect(Component)]
#[reflect(Component, Default, Debug)]
pub struct VolumetricLight;

/// When placed on a [`bevy_core_pipeline::core_3d::Camera3d`], enables
/// volumetric fog and volumetric lighting, also known as light shafts or god
/// rays.
#[derive(Clone, Copy, Component, Debug, Reflect)]
#[reflect(Component)]
#[reflect(Component, Default, Debug)]
pub struct VolumetricFog {
/// Color of the ambient light.
///
Expand Down Expand Up @@ -138,7 +139,7 @@ pub struct FogVolumeBundle {
}

#[derive(Clone, Component, Debug, Reflect)]
#[reflect(Component)]
#[reflect(Component, Default, Debug)]
pub struct FogVolume {
/// The color of the fog.
///
Expand Down
8 changes: 4 additions & 4 deletions crates/bevy_pbr/src/wireframe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl Plugin for WireframePlugin {
///
/// This requires the [`WireframePlugin`] to be enabled.
#[derive(Component, Debug, Clone, Default, Reflect, Eq, PartialEq)]
#[reflect(Component, Default)]
#[reflect(Component, Default, Debug, PartialEq)]
pub struct Wireframe;

/// Sets the color of the [`Wireframe`] of the entity it is attached to.
Expand All @@ -69,7 +69,7 @@ pub struct Wireframe;
// This could blow up in size if people use random colored wireframes for each mesh.
// It will also be important to remove unused materials from the cache.
#[derive(Component, Debug, Clone, Default, Reflect)]
#[reflect(Component, Default)]
#[reflect(Component, Default, Debug)]
pub struct WireframeColor {
pub color: Color,
}
Expand All @@ -79,11 +79,11 @@ pub struct WireframeColor {
///
/// This requires the [`WireframePlugin`] to be enabled.
#[derive(Component, Debug, Clone, Default, Reflect, Eq, PartialEq)]
#[reflect(Component, Default)]
#[reflect(Component, Default, Debug, PartialEq)]
pub struct NoWireframe;

#[derive(Resource, Debug, Clone, Default, ExtractResource, Reflect)]
#[reflect(Resource)]
#[reflect(Resource, Debug, Default)]
pub struct WireframeConfig {
/// Whether to show wireframes for all meshes.
/// Can be overridden for individual meshes by adding a [`Wireframe`] or [`NoWireframe`] component.
Expand Down

0 comments on commit b6b28a6

Please sign in to comment.