From 2158f3d91f7df12a54b656d54e2eab44b28160e2 Mon Sep 17 00:00:00 2001 From: Sunil Thunga <76161837+Cioraz@users.noreply.github.com> Date: Sat, 20 Jul 2024 23:42:24 +0530 Subject: [PATCH] Using Cas instead of CAS #14341 (#14357) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Objective - Replacing CAS with Cas in CASPlugin - Closes #14341 ## Solution - Simple replace --------- Co-authored-by: François Mockers Co-authored-by: Jan Hohenheim Co-authored-by: François Mockers --- .../src/contrast_adaptive_sharpening/mod.rs | 52 +++++++++---------- .../src/contrast_adaptive_sharpening/node.rs | 18 +++---- crates/bevy_core_pipeline/src/lib.rs | 4 +- 3 files changed, 37 insertions(+), 37 deletions(-) diff --git a/crates/bevy_core_pipeline/src/contrast_adaptive_sharpening/mod.rs b/crates/bevy_core_pipeline/src/contrast_adaptive_sharpening/mod.rs index 5be54e87bc..f76e063672 100644 --- a/crates/bevy_core_pipeline/src/contrast_adaptive_sharpening/mod.rs +++ b/crates/bevy_core_pipeline/src/contrast_adaptive_sharpening/mod.rs @@ -23,7 +23,7 @@ use bevy_render::{ mod node; -pub use node::CASNode; +pub use node::CasNode; /// Applies a contrast adaptive sharpening (CAS) filter to the camera. /// @@ -66,28 +66,28 @@ impl Default for ContrastAdaptiveSharpeningSettings { #[derive(Component, Default, Reflect, Clone)] #[reflect(Component)] -pub struct DenoiseCAS(bool); +pub struct DenoiseCas(bool); /// The uniform struct extracted from [`ContrastAdaptiveSharpeningSettings`] attached to a [`Camera`]. /// Will be available for use in the CAS shader. #[doc(hidden)] #[derive(Component, ShaderType, Clone)] -pub struct CASUniform { +pub struct CasUniform { sharpness: f32, } impl ExtractComponent for ContrastAdaptiveSharpeningSettings { type QueryData = &'static Self; type QueryFilter = With; - type Out = (DenoiseCAS, CASUniform); + type Out = (DenoiseCas, CasUniform); fn extract_component(item: QueryItem) -> Option { if !item.enabled || item.sharpening_strength == 0.0 { return None; } Some(( - DenoiseCAS(item.denoise), - CASUniform { + DenoiseCas(item.denoise), + CasUniform { // above 1.0 causes extreme artifacts and fireflies sharpness: item.sharpening_strength.clamp(0.0, 1.0), }, @@ -99,9 +99,9 @@ const CONTRAST_ADAPTIVE_SHARPENING_SHADER_HANDLE: Handle = Handle::weak_from_u128(6925381244141981602); /// Adds Support for Contrast Adaptive Sharpening (CAS). -pub struct CASPlugin; +pub struct CasPlugin; -impl Plugin for CASPlugin { +impl Plugin for CasPlugin { fn build(&self, app: &mut App) { load_internal_asset!( app, @@ -113,19 +113,19 @@ impl Plugin for CASPlugin { app.register_type::(); app.add_plugins(( ExtractComponentPlugin::::default(), - UniformComponentPlugin::::default(), + UniformComponentPlugin::::default(), )); let Some(render_app) = app.get_sub_app_mut(RenderApp) else { return; }; render_app - .init_resource::>() + .init_resource::>() .add_systems(Render, prepare_cas_pipelines.in_set(RenderSet::Prepare)); { render_app - .add_render_graph_node::(Core3d, Node3d::ContrastAdaptiveSharpening) + .add_render_graph_node::(Core3d, Node3d::ContrastAdaptiveSharpening) .add_render_graph_edge( Core3d, Node3d::Tonemapping, @@ -142,7 +142,7 @@ impl Plugin for CASPlugin { } { render_app - .add_render_graph_node::(Core2d, Node2d::ContrastAdaptiveSharpening) + .add_render_graph_node::(Core2d, Node2d::ContrastAdaptiveSharpening) .add_render_graph_edge( Core2d, Node2d::Tonemapping, @@ -163,17 +163,17 @@ impl Plugin for CASPlugin { let Some(render_app) = app.get_sub_app_mut(RenderApp) else { return; }; - render_app.init_resource::(); + render_app.init_resource::(); } } #[derive(Resource)] -pub struct CASPipeline { +pub struct CasPipeline { texture_bind_group: BindGroupLayout, sampler: Sampler, } -impl FromWorld for CASPipeline { +impl FromWorld for CasPipeline { fn from_world(render_world: &mut World) -> Self { let render_device = render_world.resource::(); let texture_bind_group = render_device.create_bind_group_layout( @@ -184,14 +184,14 @@ impl FromWorld for CASPipeline { texture_2d(TextureSampleType::Float { filterable: true }), sampler(SamplerBindingType::Filtering), // CAS Settings - uniform_buffer::(true), + uniform_buffer::(true), ), ), ); let sampler = render_device.create_sampler(&SamplerDescriptor::default()); - CASPipeline { + CasPipeline { texture_bind_group, sampler, } @@ -199,13 +199,13 @@ impl FromWorld for CASPipeline { } #[derive(PartialEq, Eq, Hash, Clone, Copy)] -pub struct CASPipelineKey { +pub struct CasPipelineKey { texture_format: TextureFormat, denoise: bool, } -impl SpecializedRenderPipeline for CASPipeline { - type Key = CASPipelineKey; +impl SpecializedRenderPipeline for CasPipeline { + type Key = CasPipelineKey; fn specialize(&self, key: Self::Key) -> RenderPipelineDescriptor { let mut shader_defs = vec![]; @@ -237,15 +237,15 @@ impl SpecializedRenderPipeline for CASPipeline { fn prepare_cas_pipelines( mut commands: Commands, pipeline_cache: Res, - mut pipelines: ResMut>, - sharpening_pipeline: Res, - views: Query<(Entity, &ExtractedView, &DenoiseCAS), With>, + mut pipelines: ResMut>, + sharpening_pipeline: Res, + views: Query<(Entity, &ExtractedView, &DenoiseCas), With>, ) { for (entity, view, cas_settings) in &views { let pipeline_id = pipelines.specialize( &pipeline_cache, &sharpening_pipeline, - CASPipelineKey { + CasPipelineKey { denoise: cas_settings.0, texture_format: if view.hdr { ViewTarget::TEXTURE_FORMAT_HDR @@ -255,9 +255,9 @@ fn prepare_cas_pipelines( }, ); - commands.entity(entity).insert(ViewCASPipeline(pipeline_id)); + commands.entity(entity).insert(ViewCasPipeline(pipeline_id)); } } #[derive(Component)] -pub struct ViewCASPipeline(CachedRenderPipelineId); +pub struct ViewCasPipeline(CachedRenderPipelineId); diff --git a/crates/bevy_core_pipeline/src/contrast_adaptive_sharpening/node.rs b/crates/bevy_core_pipeline/src/contrast_adaptive_sharpening/node.rs index 5c512747e5..663d481e88 100644 --- a/crates/bevy_core_pipeline/src/contrast_adaptive_sharpening/node.rs +++ b/crates/bevy_core_pipeline/src/contrast_adaptive_sharpening/node.rs @@ -1,6 +1,6 @@ use std::sync::Mutex; -use crate::contrast_adaptive_sharpening::ViewCASPipeline; +use crate::contrast_adaptive_sharpening::ViewCasPipeline; use bevy_ecs::prelude::*; use bevy_render::{ extract_component::{ComponentUniforms, DynamicUniformIndex}, @@ -13,21 +13,21 @@ use bevy_render::{ view::{ExtractedView, ViewTarget}, }; -use super::{CASPipeline, CASUniform}; +use super::{CasPipeline, CasUniform}; -pub struct CASNode { +pub struct CasNode { query: QueryState< ( &'static ViewTarget, - &'static ViewCASPipeline, - &'static DynamicUniformIndex, + &'static ViewCasPipeline, + &'static DynamicUniformIndex, ), With, >, cached_bind_group: Mutex>, } -impl FromWorld for CASNode { +impl FromWorld for CasNode { fn from_world(world: &mut World) -> Self { Self { query: QueryState::new(world), @@ -36,7 +36,7 @@ impl FromWorld for CASNode { } } -impl Node for CASNode { +impl Node for CasNode { fn update(&mut self, world: &mut World) { self.query.update_archetypes(world); } @@ -49,8 +49,8 @@ impl Node for CASNode { ) -> Result<(), NodeRunError> { let view_entity = graph.view_entity(); let pipeline_cache = world.resource::(); - let sharpening_pipeline = world.resource::(); - let uniforms = world.resource::>(); + let sharpening_pipeline = world.resource::(); + let uniforms = world.resource::>(); let Ok((target, pipeline, uniform_index)) = self.query.get_manual(world, view_entity) else { diff --git a/crates/bevy_core_pipeline/src/lib.rs b/crates/bevy_core_pipeline/src/lib.rs index 9118afc8d4..568f2cf3f1 100644 --- a/crates/bevy_core_pipeline/src/lib.rs +++ b/crates/bevy_core_pipeline/src/lib.rs @@ -52,7 +52,7 @@ pub mod prelude { use crate::{ blit::BlitPlugin, bloom::BloomPlugin, - contrast_adaptive_sharpening::CASPlugin, + contrast_adaptive_sharpening::CasPlugin, core_2d::Core2dPlugin, core_3d::Core3dPlugin, deferred::copy_lighting_id::CopyDeferredLightingIdPlugin, @@ -97,7 +97,7 @@ impl Plugin for CorePipelinePlugin { UpscalingPlugin, BloomPlugin, FxaaPlugin, - CASPlugin, + CasPlugin, MotionBlurPlugin, DepthOfFieldPlugin, SmaaPlugin,