Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use bevy_render::{
*,
},
renderer::RenderDevice,
sync_component::SyncComponent,
view::{ExtractedView, ViewTarget},
Render, RenderApp, RenderStartup, RenderSystems,
};
Expand Down Expand Up @@ -75,10 +76,13 @@ pub struct CasUniform {
sharpness: f32,
}

impl SyncComponent for ContrastAdaptiveSharpening {
type Out = (DenoiseCas, CasUniform);
}

impl ExtractComponent for ContrastAdaptiveSharpening {
type QueryData = &'static Self;
type QueryFilter = With<Camera>;
type Out = (DenoiseCas, CasUniform);

fn extract_component(item: QueryItem<Self::QueryData>) -> Option<Self::Out> {
if !item.enabled || item.sharpening_strength == 0.0 {
Expand Down
6 changes: 5 additions & 1 deletion crates/bevy_anti_alias/src/taa/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use bevy_render::{
TextureFormat, TextureSampleType, TextureUsages, Variants,
},
renderer::{RenderContext, RenderDevice, ViewQuery},
sync_component::SyncComponentPlugin,
sync_component::{SyncComponent, SyncComponentPlugin},
sync_world::RenderEntity,
texture::{CachedTexture, TextureCache},
view::{ExtractedView, Msaa, ViewTarget},
Expand Down Expand Up @@ -133,6 +133,10 @@ impl Default for TemporalAntiAliasing {
}
}

impl SyncComponent for TemporalAntiAliasing {
type Out = Self;
}

fn temporal_anti_alias(
view: ViewQuery<(
&ExtractedCamera,
Expand Down
8 changes: 5 additions & 3 deletions crates/bevy_pbr/src/atmosphere/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ use bevy_reflect::{std_traits::ReflectDefault, Reflect};
use bevy_render::{
extract_component::UniformComponentPlugin,
render_resource::{DownlevelFlags, ShaderType, SpecializedRenderPipelines},
sync_component::SyncComponent,
sync_world::RenderEntity,
Extract, ExtractSchedule, RenderStartup,
};
Expand Down Expand Up @@ -361,13 +362,14 @@ impl From<AtmosphereSettings> for GpuAtmosphereSettings {
}
}

impl SyncComponent for GpuAtmosphereSettings {
type Out = Self;
}

impl ExtractComponent for GpuAtmosphereSettings {
type QueryData = Read<AtmosphereSettings>;

type QueryFilter = (With<Camera3d>, With<Atmosphere>);

type Out = GpuAtmosphereSettings;

fn extract_component(item: QueryItem<'_, '_, Self::QueryData>) -> Option<Self::Out> {
Some(item.clone().into())
}
Expand Down
6 changes: 5 additions & 1 deletion crates/bevy_pbr/src/contact_shadows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use bevy_render::{
extract_component::{ExtractComponent, ExtractComponentPlugin},
render_resource::{DynamicUniformBuffer, ShaderType},
renderer::{RenderDevice, RenderQueue},
sync_component::SyncComponent,
view::ExtractedView,
Render, RenderApp, RenderSystems,
};
Expand Down Expand Up @@ -79,10 +80,13 @@ impl From<ContactShadows> for ContactShadowsUniform {
}
}

impl SyncComponent for ContactShadows {
type Out = Self;
}

impl ExtractComponent for ContactShadows {
type QueryData = &'static ContactShadows;
type QueryFilter = ();
type Out = ContactShadows;

fn extract_component(settings: QueryItem<'_, '_, Self::QueryData>) -> Option<Self::Out> {
Some(*settings)
Expand Down
8 changes: 6 additions & 2 deletions crates/bevy_pbr/src/decal/clustered.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ use bevy_render::{
},
renderer::{RenderAdapter, RenderDevice, RenderQueue},
settings::WgpuFeatures,
sync_component::SyncComponentPlugin,
sync_component::{SyncComponent, SyncComponentPlugin},
sync_world::RenderEntity,
texture::{FallbackImage, GpuImage},
Extract, ExtractSchedule, Render, RenderApp, RenderSystems,
Expand Down Expand Up @@ -147,7 +147,7 @@ impl Plugin for ClusteredDecalPlugin {
fn build(&self, app: &mut App) {
load_shader_library!(app, "clustered.wgsl");

app.add_plugins(SyncComponentPlugin::<ClusteredDecal>::default());
app.add_plugins(SyncComponentPlugin::<ClusteredDecal, Self>::default());

let Some(render_app) = app.get_sub_app_mut(RenderApp) else {
return;
Expand All @@ -170,6 +170,10 @@ impl Plugin for ClusteredDecalPlugin {
}
}

impl SyncComponent<ClusteredDecalPlugin> for ClusteredDecal {
type Out = Self;
}

// This is needed because of the orphan rule not allowing implementing
// foreign trait ExtractComponent on foreign type ClusteredDecal
fn extract_clustered_decal(
Expand Down
27 changes: 22 additions & 5 deletions crates/bevy_pbr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ mod atmosphere;
mod cluster;
mod components;
pub mod contact_shadows;
use bevy_render::sync_component::SyncComponent;
pub use contact_shadows::{
ContactShadows, ContactShadowsBuffer, ContactShadowsPlugin, ContactShadowsUniform,
ViewContactShadowsUniformOffset,
Expand Down Expand Up @@ -201,7 +202,7 @@ impl Plugin for PbrPlugin {
ScreenSpaceAmbientOcclusionPlugin,
FogPlugin,
ExtractResourcePlugin::<DefaultOpaqueRendererMethod>::default(),
SyncComponentPlugin::<ShadowFilteringMethod>::default(),
SyncComponentPlugin::<ShadowFilteringMethod, Self>::default(),
LightmapPlugin,
LightProbePlugin,
GpuMeshPreprocessPlugin {
Expand All @@ -215,10 +216,10 @@ impl Plugin for PbrPlugin {
))
.add_plugins((
decal::ForwardDecalPlugin,
SyncComponentPlugin::<DirectionalLight>::default(),
SyncComponentPlugin::<PointLight>::default(),
SyncComponentPlugin::<SpotLight>::default(),
SyncComponentPlugin::<AmbientLight>::default(),
SyncComponentPlugin::<DirectionalLight, Self>::default(),
SyncComponentPlugin::<PointLight, Self>::default(),
SyncComponentPlugin::<SpotLight, Self>::default(),
SyncComponentPlugin::<AmbientLight, Self>::default(),
))
.add_plugins((ScatteringMediumPlugin, AtmospherePlugin))
.configure_sets(
Expand Down Expand Up @@ -366,3 +367,19 @@ pub fn stbn_placeholder() -> Image {
copy_on_resize: false,
}
}

impl SyncComponent<PbrPlugin> for DirectionalLight {
type Out = Self;
}
impl SyncComponent<PbrPlugin> for PointLight {
type Out = Self;
}
impl SyncComponent<PbrPlugin> for SpotLight {
type Out = Self;
}
impl SyncComponent<PbrPlugin> for AmbientLight {
type Out = Self;
}
impl SyncComponent<PbrPlugin> for ShadowFilteringMethod {
type Out = Self;
}
8 changes: 6 additions & 2 deletions crates/bevy_pbr/src/light_probe/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use bevy_render::{
},
renderer::{RenderAdapter, RenderContext, RenderDevice, RenderQueue},
settings::WgpuFeatures,
sync_component::SyncComponentPlugin,
sync_component::{SyncComponent, SyncComponentPlugin},
sync_world::RenderEntity,
texture::{CachedTexture, GpuImage, TextureCache},
Extract, ExtractSchedule, Render, RenderApp, RenderStartup, RenderSystems,
Expand Down Expand Up @@ -128,7 +128,7 @@ impl Plugin for EnvironmentMapGenerationPlugin {
embedded_asset!(app, "environment_filter.wgsl");
embedded_asset!(app, "copy.wgsl");

app.add_plugins(SyncComponentPlugin::<GeneratedEnvironmentMapLight>::default())
app.add_plugins(SyncComponentPlugin::<EnvironmentMapLight, Self>::default())
.add_systems(Update, generate_environment_map_light);

let Some(render_app) = app.get_sub_app_mut(RenderApp) else {
Expand Down Expand Up @@ -1108,3 +1108,7 @@ pub fn generate_environment_map_light(
});
}
}

impl SyncComponent<EnvironmentMapGenerationPlugin> for EnvironmentMapLight {
type Out = GeneratedEnvironmentMapLight;
}
8 changes: 5 additions & 3 deletions crates/bevy_pbr/src/ssr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ use bevy_render::{
TextureViewDimension,
},
renderer::{RenderAdapter, RenderContext, RenderDevice, RenderQueue, ViewQuery},
sync_component::SyncComponent,
texture::GpuImage,
view::{ExtractedView, Msaa, ViewTarget, ViewUniformOffset},
Render, RenderApp, RenderStartup, RenderSystems,
Expand Down Expand Up @@ -511,13 +512,14 @@ pub fn prepare_ssr_settings(
}
}

impl SyncComponent for ScreenSpaceReflections {
type Out = ScreenSpaceReflectionsUniform;
}

impl ExtractComponent for ScreenSpaceReflections {
type QueryData = Read<ScreenSpaceReflections>;

type QueryFilter = ();

type Out = ScreenSpaceReflectionsUniform;

fn extract_component(settings: QueryItem<'_, '_, Self::QueryData>) -> Option<Self::Out> {
if !DEPTH_TEXTURE_SAMPLING_SUPPORTED {
once!(info!(
Expand Down
9 changes: 7 additions & 2 deletions crates/bevy_pbr/src/volumetric_fog/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ use bevy_math::{
};
use bevy_mesh::{Mesh, Meshable};
use bevy_render::{
render_resource::SpecializedRenderPipelines, sync_component::SyncComponentPlugin,
render_resource::SpecializedRenderPipelines,
sync_component::{SyncComponent, SyncComponentPlugin},
ExtractSchedule, Render, RenderApp, RenderStartup, RenderSystems,
};
use render::{volumetric_fog, VolumetricFogPipeline, VolumetricFogUniformBuffer};
Expand All @@ -69,7 +70,7 @@ impl Plugin for VolumetricFogPlugin {
let plane_mesh = meshes.add(Plane3d::new(Vec3::Z, Vec2::ONE).mesh());
let cube_mesh = meshes.add(Cuboid::new(1.0, 1.0, 1.0).mesh());

app.add_plugins(SyncComponentPlugin::<FogVolume>::default());
app.add_plugins(SyncComponentPlugin::<FogVolume, Self>::default());

let Some(render_app) = app.get_sub_app_mut(RenderApp) else {
return;
Expand Down Expand Up @@ -102,3 +103,7 @@ impl Plugin for VolumetricFogPlugin {
);
}
}

impl SyncComponent<VolumetricFogPlugin> for FogVolume {
type Out = Self;
}
8 changes: 5 additions & 3 deletions crates/bevy_post_process/src/bloom/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use bevy_ecs::{
};
use bevy_math::{AspectRatio, URect, UVec4, Vec2, Vec4};
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
use bevy_render::extract_component::ExtractComponent;
use bevy_render::{extract_component::ExtractComponent, sync_component::SyncComponent};

/// Applies a bloom effect to an HDR-enabled 2d or 3d camera.
///
Expand Down Expand Up @@ -222,11 +222,13 @@ pub enum BloomCompositeMode {
Additive,
}

impl SyncComponent for Bloom {
type Out = (Self, BloomUniforms);
}

impl ExtractComponent for Bloom {
type QueryData = (&'static Self, &'static Camera);

type QueryFilter = With<Hdr>;
type Out = (Self, BloomUniforms);

fn extract_component((bloom, camera): QueryItem<'_, '_, Self::QueryData>) -> Option<Self::Out> {
match (
Expand Down
23 changes: 13 additions & 10 deletions crates/bevy_post_process/src/dof/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ use bevy_render::{
TextureDescriptor, TextureDimension, TextureFormat, TextureSampleType, TextureUsages,
},
renderer::{RenderContext, RenderDevice, ViewQuery},
sync_component::SyncComponentPlugin,
sync_component::{SyncComponent, SyncComponentPlugin},
sync_world::RenderEntity,
texture::{CachedTexture, TextureCache},
view::{
Expand Down Expand Up @@ -653,6 +653,16 @@ impl SpecializedRenderPipeline for DepthOfFieldPipeline {
}
}

impl SyncComponent for DepthOfField {
type Out = (
DepthOfField,
DepthOfFieldUniform,
DepthOfFieldPipelines,
AuxiliaryDepthOfFieldTexture,
ViewDepthOfFieldBindGroupLayouts,
);
}

/// Extracts all [`DepthOfField`] components into the render world.
fn extract_depth_of_field_settings(
mut commands: Commands,
Expand All @@ -672,15 +682,8 @@ fn extract_depth_of_field_settings(

// Depth of field is nonsensical without a perspective projection.
let Projection::Perspective(ref perspective_projection) = *projection else {
// TODO: needs better strategy for cleaning up
entity_commands.remove::<(
DepthOfField,
DepthOfFieldUniform,
// components added in prepare systems (because `DepthOfFieldNode` does not query extracted components)
DepthOfFieldPipelines,
AuxiliaryDepthOfFieldTexture,
ViewDepthOfFieldBindGroupLayouts,
)>();
entity_commands.remove::<<DepthOfField as SyncComponent>::Out>();

continue;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ use bevy_ecs::{
};
use bevy_image::Image;
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
use bevy_render::{extract_component::ExtractComponent, render_resource::ShaderType};
use bevy_render::{
extract_component::ExtractComponent, render_resource::ShaderType, sync_component::SyncComponent,
};

/// The raw RGBA data for the default chromatic aberration gradient.
///
Expand Down Expand Up @@ -83,13 +85,14 @@ impl Default for ChromaticAberration {
}
}

impl SyncComponent for ChromaticAberration {
type Out = Self;
}

impl ExtractComponent for ChromaticAberration {
type QueryData = Read<ChromaticAberration>;

type QueryFilter = With<Camera>;

type Out = ChromaticAberration;

fn extract_component(
chromatic_aberration: QueryItem<'_, '_, Self::QueryData>,
) -> Option<Self::Out> {
Expand Down
11 changes: 7 additions & 4 deletions crates/bevy_post_process/src/effect_stack/vignette.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ use bevy_ecs::{
};
use bevy_math::{Vec2, Vec4};
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
use bevy_render::{extract_component::ExtractComponent, render_resource::ShaderType};
use bevy_render::{
extract_component::ExtractComponent, render_resource::ShaderType, sync_component::SyncComponent,
};

/// The default vignette intensity amount.
const DEFAULT_VIGNETTE_INTENSITY: f32 = 1.00;
Expand Down Expand Up @@ -100,13 +102,14 @@ impl Default for Vignette {
}
}

impl SyncComponent for Vignette {
type Out = Self;
}

impl ExtractComponent for Vignette {
type QueryData = Read<Vignette>;

type QueryFilter = With<Camera>;

type Out = Vignette;

fn extract_component(vignette: QueryItem<'_, '_, Self::QueryData>) -> Option<Self::Out> {
// Skip the postprocessing phase entirely if the intensity is zero.
if vignette.intensity > 0.0 {
Expand Down
Loading