# 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:
parent
c0b35d07f3
commit
2158f3d91f
@ -23,7 +23,7 @@ use bevy_render::{
|
|||||||
|
|
||||||
mod node;
|
mod node;
|
||||||
|
|
||||||
pub use node::CASNode;
|
pub use node::CasNode;
|
||||||
|
|
||||||
/// Applies a contrast adaptive sharpening (CAS) filter to the camera.
|
/// Applies a contrast adaptive sharpening (CAS) filter to the camera.
|
||||||
///
|
///
|
||||||
@ -66,28 +66,28 @@ impl Default for ContrastAdaptiveSharpeningSettings {
|
|||||||
|
|
||||||
#[derive(Component, Default, Reflect, Clone)]
|
#[derive(Component, Default, Reflect, Clone)]
|
||||||
#[reflect(Component)]
|
#[reflect(Component)]
|
||||||
pub struct DenoiseCAS(bool);
|
pub struct DenoiseCas(bool);
|
||||||
|
|
||||||
/// The uniform struct extracted from [`ContrastAdaptiveSharpeningSettings`] attached to a [`Camera`].
|
/// The uniform struct extracted from [`ContrastAdaptiveSharpeningSettings`] attached to a [`Camera`].
|
||||||
/// Will be available for use in the CAS shader.
|
/// Will be available for use in the CAS shader.
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
#[derive(Component, ShaderType, Clone)]
|
#[derive(Component, ShaderType, Clone)]
|
||||||
pub struct CASUniform {
|
pub struct CasUniform {
|
||||||
sharpness: f32,
|
sharpness: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ExtractComponent for ContrastAdaptiveSharpeningSettings {
|
impl ExtractComponent for ContrastAdaptiveSharpeningSettings {
|
||||||
type QueryData = &'static Self;
|
type QueryData = &'static Self;
|
||||||
type QueryFilter = With<Camera>;
|
type QueryFilter = With<Camera>;
|
||||||
type Out = (DenoiseCAS, CASUniform);
|
type Out = (DenoiseCas, CasUniform);
|
||||||
|
|
||||||
fn extract_component(item: QueryItem<Self::QueryData>) -> Option<Self::Out> {
|
fn extract_component(item: QueryItem<Self::QueryData>) -> Option<Self::Out> {
|
||||||
if !item.enabled || item.sharpening_strength == 0.0 {
|
if !item.enabled || item.sharpening_strength == 0.0 {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
Some((
|
Some((
|
||||||
DenoiseCAS(item.denoise),
|
DenoiseCas(item.denoise),
|
||||||
CASUniform {
|
CasUniform {
|
||||||
// above 1.0 causes extreme artifacts and fireflies
|
// above 1.0 causes extreme artifacts and fireflies
|
||||||
sharpness: item.sharpening_strength.clamp(0.0, 1.0),
|
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);
|
Handle::weak_from_u128(6925381244141981602);
|
||||||
|
|
||||||
/// Adds Support for Contrast Adaptive Sharpening (CAS).
|
/// 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) {
|
fn build(&self, app: &mut App) {
|
||||||
load_internal_asset!(
|
load_internal_asset!(
|
||||||
app,
|
app,
|
||||||
@ -113,19 +113,19 @@ impl Plugin for CASPlugin {
|
|||||||
app.register_type::<ContrastAdaptiveSharpeningSettings>();
|
app.register_type::<ContrastAdaptiveSharpeningSettings>();
|
||||||
app.add_plugins((
|
app.add_plugins((
|
||||||
ExtractComponentPlugin::<ContrastAdaptiveSharpeningSettings>::default(),
|
ExtractComponentPlugin::<ContrastAdaptiveSharpeningSettings>::default(),
|
||||||
UniformComponentPlugin::<CASUniform>::default(),
|
UniformComponentPlugin::<CasUniform>::default(),
|
||||||
));
|
));
|
||||||
|
|
||||||
let Some(render_app) = app.get_sub_app_mut(RenderApp) else {
|
let Some(render_app) = app.get_sub_app_mut(RenderApp) else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
render_app
|
render_app
|
||||||
.init_resource::<SpecializedRenderPipelines<CASPipeline>>()
|
.init_resource::<SpecializedRenderPipelines<CasPipeline>>()
|
||||||
.add_systems(Render, prepare_cas_pipelines.in_set(RenderSet::Prepare));
|
.add_systems(Render, prepare_cas_pipelines.in_set(RenderSet::Prepare));
|
||||||
|
|
||||||
{
|
{
|
||||||
render_app
|
render_app
|
||||||
.add_render_graph_node::<CASNode>(Core3d, Node3d::ContrastAdaptiveSharpening)
|
.add_render_graph_node::<CasNode>(Core3d, Node3d::ContrastAdaptiveSharpening)
|
||||||
.add_render_graph_edge(
|
.add_render_graph_edge(
|
||||||
Core3d,
|
Core3d,
|
||||||
Node3d::Tonemapping,
|
Node3d::Tonemapping,
|
||||||
@ -142,7 +142,7 @@ impl Plugin for CASPlugin {
|
|||||||
}
|
}
|
||||||
{
|
{
|
||||||
render_app
|
render_app
|
||||||
.add_render_graph_node::<CASNode>(Core2d, Node2d::ContrastAdaptiveSharpening)
|
.add_render_graph_node::<CasNode>(Core2d, Node2d::ContrastAdaptiveSharpening)
|
||||||
.add_render_graph_edge(
|
.add_render_graph_edge(
|
||||||
Core2d,
|
Core2d,
|
||||||
Node2d::Tonemapping,
|
Node2d::Tonemapping,
|
||||||
@ -163,17 +163,17 @@ impl Plugin for CASPlugin {
|
|||||||
let Some(render_app) = app.get_sub_app_mut(RenderApp) else {
|
let Some(render_app) = app.get_sub_app_mut(RenderApp) else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
render_app.init_resource::<CASPipeline>();
|
render_app.init_resource::<CasPipeline>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Resource)]
|
#[derive(Resource)]
|
||||||
pub struct CASPipeline {
|
pub struct CasPipeline {
|
||||||
texture_bind_group: BindGroupLayout,
|
texture_bind_group: BindGroupLayout,
|
||||||
sampler: Sampler,
|
sampler: Sampler,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromWorld for CASPipeline {
|
impl FromWorld for CasPipeline {
|
||||||
fn from_world(render_world: &mut World) -> Self {
|
fn from_world(render_world: &mut World) -> Self {
|
||||||
let render_device = render_world.resource::<RenderDevice>();
|
let render_device = render_world.resource::<RenderDevice>();
|
||||||
let texture_bind_group = render_device.create_bind_group_layout(
|
let texture_bind_group = render_device.create_bind_group_layout(
|
||||||
@ -184,14 +184,14 @@ impl FromWorld for CASPipeline {
|
|||||||
texture_2d(TextureSampleType::Float { filterable: true }),
|
texture_2d(TextureSampleType::Float { filterable: true }),
|
||||||
sampler(SamplerBindingType::Filtering),
|
sampler(SamplerBindingType::Filtering),
|
||||||
// CAS Settings
|
// CAS Settings
|
||||||
uniform_buffer::<CASUniform>(true),
|
uniform_buffer::<CasUniform>(true),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
let sampler = render_device.create_sampler(&SamplerDescriptor::default());
|
let sampler = render_device.create_sampler(&SamplerDescriptor::default());
|
||||||
|
|
||||||
CASPipeline {
|
CasPipeline {
|
||||||
texture_bind_group,
|
texture_bind_group,
|
||||||
sampler,
|
sampler,
|
||||||
}
|
}
|
||||||
@ -199,13 +199,13 @@ impl FromWorld for CASPipeline {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Hash, Clone, Copy)]
|
#[derive(PartialEq, Eq, Hash, Clone, Copy)]
|
||||||
pub struct CASPipelineKey {
|
pub struct CasPipelineKey {
|
||||||
texture_format: TextureFormat,
|
texture_format: TextureFormat,
|
||||||
denoise: bool,
|
denoise: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SpecializedRenderPipeline for CASPipeline {
|
impl SpecializedRenderPipeline for CasPipeline {
|
||||||
type Key = CASPipelineKey;
|
type Key = CasPipelineKey;
|
||||||
|
|
||||||
fn specialize(&self, key: Self::Key) -> RenderPipelineDescriptor {
|
fn specialize(&self, key: Self::Key) -> RenderPipelineDescriptor {
|
||||||
let mut shader_defs = vec![];
|
let mut shader_defs = vec![];
|
||||||
@ -237,15 +237,15 @@ impl SpecializedRenderPipeline for CASPipeline {
|
|||||||
fn prepare_cas_pipelines(
|
fn prepare_cas_pipelines(
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
pipeline_cache: Res<PipelineCache>,
|
pipeline_cache: Res<PipelineCache>,
|
||||||
mut pipelines: ResMut<SpecializedRenderPipelines<CASPipeline>>,
|
mut pipelines: ResMut<SpecializedRenderPipelines<CasPipeline>>,
|
||||||
sharpening_pipeline: Res<CASPipeline>,
|
sharpening_pipeline: Res<CasPipeline>,
|
||||||
views: Query<(Entity, &ExtractedView, &DenoiseCAS), With<CASUniform>>,
|
views: Query<(Entity, &ExtractedView, &DenoiseCas), With<CasUniform>>,
|
||||||
) {
|
) {
|
||||||
for (entity, view, cas_settings) in &views {
|
for (entity, view, cas_settings) in &views {
|
||||||
let pipeline_id = pipelines.specialize(
|
let pipeline_id = pipelines.specialize(
|
||||||
&pipeline_cache,
|
&pipeline_cache,
|
||||||
&sharpening_pipeline,
|
&sharpening_pipeline,
|
||||||
CASPipelineKey {
|
CasPipelineKey {
|
||||||
denoise: cas_settings.0,
|
denoise: cas_settings.0,
|
||||||
texture_format: if view.hdr {
|
texture_format: if view.hdr {
|
||||||
ViewTarget::TEXTURE_FORMAT_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)]
|
#[derive(Component)]
|
||||||
pub struct ViewCASPipeline(CachedRenderPipelineId);
|
pub struct ViewCasPipeline(CachedRenderPipelineId);
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
|
|
||||||
use crate::contrast_adaptive_sharpening::ViewCASPipeline;
|
use crate::contrast_adaptive_sharpening::ViewCasPipeline;
|
||||||
use bevy_ecs::prelude::*;
|
use bevy_ecs::prelude::*;
|
||||||
use bevy_render::{
|
use bevy_render::{
|
||||||
extract_component::{ComponentUniforms, DynamicUniformIndex},
|
extract_component::{ComponentUniforms, DynamicUniformIndex},
|
||||||
@ -13,21 +13,21 @@ use bevy_render::{
|
|||||||
view::{ExtractedView, ViewTarget},
|
view::{ExtractedView, ViewTarget},
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{CASPipeline, CASUniform};
|
use super::{CasPipeline, CasUniform};
|
||||||
|
|
||||||
pub struct CASNode {
|
pub struct CasNode {
|
||||||
query: QueryState<
|
query: QueryState<
|
||||||
(
|
(
|
||||||
&'static ViewTarget,
|
&'static ViewTarget,
|
||||||
&'static ViewCASPipeline,
|
&'static ViewCasPipeline,
|
||||||
&'static DynamicUniformIndex<CASUniform>,
|
&'static DynamicUniformIndex<CasUniform>,
|
||||||
),
|
),
|
||||||
With<ExtractedView>,
|
With<ExtractedView>,
|
||||||
>,
|
>,
|
||||||
cached_bind_group: Mutex<Option<(BufferId, TextureViewId, BindGroup)>>,
|
cached_bind_group: Mutex<Option<(BufferId, TextureViewId, BindGroup)>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromWorld for CASNode {
|
impl FromWorld for CasNode {
|
||||||
fn from_world(world: &mut World) -> Self {
|
fn from_world(world: &mut World) -> Self {
|
||||||
Self {
|
Self {
|
||||||
query: QueryState::new(world),
|
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) {
|
fn update(&mut self, world: &mut World) {
|
||||||
self.query.update_archetypes(world);
|
self.query.update_archetypes(world);
|
||||||
}
|
}
|
||||||
@ -49,8 +49,8 @@ impl Node for CASNode {
|
|||||||
) -> Result<(), NodeRunError> {
|
) -> Result<(), NodeRunError> {
|
||||||
let view_entity = graph.view_entity();
|
let view_entity = graph.view_entity();
|
||||||
let pipeline_cache = world.resource::<PipelineCache>();
|
let pipeline_cache = world.resource::<PipelineCache>();
|
||||||
let sharpening_pipeline = world.resource::<CASPipeline>();
|
let sharpening_pipeline = world.resource::<CasPipeline>();
|
||||||
let uniforms = world.resource::<ComponentUniforms<CASUniform>>();
|
let uniforms = world.resource::<ComponentUniforms<CasUniform>>();
|
||||||
|
|
||||||
let Ok((target, pipeline, uniform_index)) = self.query.get_manual(world, view_entity)
|
let Ok((target, pipeline, uniform_index)) = self.query.get_manual(world, view_entity)
|
||||||
else {
|
else {
|
||||||
|
|||||||
@ -52,7 +52,7 @@ pub mod prelude {
|
|||||||
use crate::{
|
use crate::{
|
||||||
blit::BlitPlugin,
|
blit::BlitPlugin,
|
||||||
bloom::BloomPlugin,
|
bloom::BloomPlugin,
|
||||||
contrast_adaptive_sharpening::CASPlugin,
|
contrast_adaptive_sharpening::CasPlugin,
|
||||||
core_2d::Core2dPlugin,
|
core_2d::Core2dPlugin,
|
||||||
core_3d::Core3dPlugin,
|
core_3d::Core3dPlugin,
|
||||||
deferred::copy_lighting_id::CopyDeferredLightingIdPlugin,
|
deferred::copy_lighting_id::CopyDeferredLightingIdPlugin,
|
||||||
@ -97,7 +97,7 @@ impl Plugin for CorePipelinePlugin {
|
|||||||
UpscalingPlugin,
|
UpscalingPlugin,
|
||||||
BloomPlugin,
|
BloomPlugin,
|
||||||
FxaaPlugin,
|
FxaaPlugin,
|
||||||
CASPlugin,
|
CasPlugin,
|
||||||
MotionBlurPlugin,
|
MotionBlurPlugin,
|
||||||
DepthOfFieldPlugin,
|
DepthOfFieldPlugin,
|
||||||
SmaaPlugin,
|
SmaaPlugin,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user