Using Cas instead of CAS #14341 (#14357)

# Objective

- Replacing CAS with Cas in CASPlugin
- Closes #14341

## Solution

- Simple replace

---------

Co-authored-by: François Mockers <francois.mockers@vleue.com>
Co-authored-by: Jan Hohenheim <jan@hohenheim.ch>
Co-authored-by: François Mockers <mockersf@gmail.com>
This commit is contained in:
Sunil Thunga 2024-07-20 23:42:24 +05:30 committed by GitHub
parent c0b35d07f3
commit 2158f3d91f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 37 additions and 37 deletions

View file

@ -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<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),
},
@ -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,
@ -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,
@ -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,
@ -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(
@ -184,14 +184,14 @@ 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,
}
@ -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<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
@ -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);

View file

@ -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<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),
@ -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::<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 {

View file

@ -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,