Skip to content

Commit

Permalink
Using Cas instead of CAS bevyengine#14341 (bevyengine#14357)
Browse files Browse the repository at this point in the history
# Objective

- Replacing CAS with Cas in CASPlugin
- Closes bevyengine#14341

## Solution

- Simple replace

---------

Co-authored-by: François Mockers <[email protected]>
Co-authored-by: Jan Hohenheim <[email protected]>
Co-authored-by: François Mockers <[email protected]>
  • Loading branch information
4 people authored Jul 20, 2024
1 parent c0b35d0 commit 2158f3d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 37 deletions.
52 changes: 26 additions & 26 deletions crates/bevy_core_pipeline/src/contrast_adaptive_sharpening/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down Expand Up @@ -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<Camera>;
type Out = (DenoiseCAS, CASUniform);
type Out = (DenoiseCas, CasUniform);

fn extract_component(item: QueryItem<Self::QueryData>) -> Option<Self::Out> {
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),
},
Expand All @@ -99,9 +99,9 @@ const CONTRAST_ADAPTIVE_SHARPENING_SHADER_HANDLE: Handle<Shader> =
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,
Expand All @@ -113,19 +113,19 @@ impl Plugin for CASPlugin {
app.register_type::<ContrastAdaptiveSharpeningSettings>();
app.add_plugins((
ExtractComponentPlugin::<ContrastAdaptiveSharpeningSettings>::default(),
UniformComponentPlugin::<CASUniform>::default(),
UniformComponentPlugin::<CasUniform>::default(),
));

let Some(render_app) = app.get_sub_app_mut(RenderApp) else {
return;
};
render_app
.init_resource::<SpecializedRenderPipelines<CASPipeline>>()
.init_resource::<SpecializedRenderPipelines<CasPipeline>>()
.add_systems(Render, prepare_cas_pipelines.in_set(RenderSet::Prepare));

{
render_app
.add_render_graph_node::<CASNode>(Core3d, Node3d::ContrastAdaptiveSharpening)
.add_render_graph_node::<CasNode>(Core3d, Node3d::ContrastAdaptiveSharpening)
.add_render_graph_edge(
Core3d,
Node3d::Tonemapping,
Expand All @@ -142,7 +142,7 @@ impl Plugin for CASPlugin {
}
{
render_app
.add_render_graph_node::<CASNode>(Core2d, Node2d::ContrastAdaptiveSharpening)
.add_render_graph_node::<CasNode>(Core2d, Node2d::ContrastAdaptiveSharpening)
.add_render_graph_edge(
Core2d,
Node2d::Tonemapping,
Expand All @@ -163,17 +163,17 @@ impl Plugin for CASPlugin {
let Some(render_app) = app.get_sub_app_mut(RenderApp) else {
return;
};
render_app.init_resource::<CASPipeline>();
render_app.init_resource::<CasPipeline>();
}
}

#[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::<RenderDevice>();
let texture_bind_group = render_device.create_bind_group_layout(
Expand All @@ -184,28 +184,28 @@ impl FromWorld for CASPipeline {
texture_2d(TextureSampleType::Float { filterable: true }),
sampler(SamplerBindingType::Filtering),
// CAS Settings
uniform_buffer::<CASUniform>(true),
uniform_buffer::<CasUniform>(true),
),
),
);

let sampler = render_device.create_sampler(&SamplerDescriptor::default());

CASPipeline {
CasPipeline {
texture_bind_group,
sampler,
}
}
}

#[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![];
Expand Down Expand Up @@ -237,15 +237,15 @@ impl SpecializedRenderPipeline for CASPipeline {
fn prepare_cas_pipelines(
mut commands: Commands,
pipeline_cache: Res<PipelineCache>,
mut pipelines: ResMut<SpecializedRenderPipelines<CASPipeline>>,
sharpening_pipeline: Res<CASPipeline>,
views: Query<(Entity, &ExtractedView, &DenoiseCAS), With<CASUniform>>,
mut pipelines: ResMut<SpecializedRenderPipelines<CasPipeline>>,
sharpening_pipeline: Res<CasPipeline>,
views: Query<(Entity, &ExtractedView, &DenoiseCas), With<CasUniform>>,
) {
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
Expand All @@ -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);
Original file line number Diff line number Diff line change
@@ -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},
Expand All @@ -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<CASUniform>,
&'static ViewCasPipeline,
&'static DynamicUniformIndex<CasUniform>,
),
With<ExtractedView>,
>,
cached_bind_group: Mutex<Option<(BufferId, TextureViewId, BindGroup)>>,
}

impl FromWorld for CASNode {
impl FromWorld for CasNode {
fn from_world(world: &mut World) -> Self {
Self {
query: QueryState::new(world),
Expand All @@ -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);
}
Expand All @@ -49,8 +49,8 @@ impl Node for CASNode {
) -> Result<(), NodeRunError> {
let view_entity = graph.view_entity();
let pipeline_cache = world.resource::<PipelineCache>();
let sharpening_pipeline = world.resource::<CASPipeline>();
let uniforms = world.resource::<ComponentUniforms<CASUniform>>();
let sharpening_pipeline = world.resource::<CasPipeline>();
let uniforms = world.resource::<ComponentUniforms<CasUniform>>();

let Ok((target, pipeline, uniform_index)) = self.query.get_manual(world, view_entity)
else {
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_core_pipeline/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -97,7 +97,7 @@ impl Plugin for CorePipelinePlugin {
UpscalingPlugin,
BloomPlugin,
FxaaPlugin,
CASPlugin,
CasPlugin,
MotionBlurPlugin,
DepthOfFieldPlugin,
SmaaPlugin,
Expand Down

0 comments on commit 2158f3d

Please sign in to comment.