@@ -16,15 +16,15 @@ use bevy_render::{
16
16
17
17
mod node;
18
18
19
- pub use node:: ContrastAdaptiveSharpeningNode ;
19
+ pub use node:: CASNode ;
20
20
21
21
/// Applies a contrast adaptive sharpening (CAS) filter to the camera.
22
22
///
23
23
/// CAS is usually used in combination with shader based anti-aliasing methods
24
24
/// such as FXAA or TAA to regain some of the lost detail from the blurring that they introduce.
25
25
///
26
26
/// CAS is designed to adjust the amount of sharpening applied to different areas of an image
27
- /// based on the local contrast.This can help avoid over-sharpening areas with high contrast
27
+ /// based on the local contrast. This can help avoid over-sharpening areas with high contrast
28
28
/// and under-sharpening areas with low contrast.
29
29
///
30
30
/// To use this, add the [`ContrastAdaptiveSharpeningSettings`] component to a 2D or 3D camera.
@@ -82,9 +82,9 @@ const CONTRAST_ADAPTIVE_SHARPENING_SHADER_HANDLE: HandleUntyped =
82
82
HandleUntyped :: weak_from_u64 ( Shader :: TYPE_UUID , 6925381244141981602 ) ;
83
83
84
84
/// Adds Support for Contrast Adaptive Sharpening (CAS).
85
- pub struct ContrastAdaptiveSharpeningPlugin ;
85
+ pub struct CASPlugin ;
86
86
87
- impl Plugin for ContrastAdaptiveSharpeningPlugin {
87
+ impl Plugin for CASPlugin {
88
88
fn build ( & self , app : & mut App ) {
89
89
load_internal_asset ! (
90
90
app,
@@ -102,14 +102,11 @@ impl Plugin for ContrastAdaptiveSharpeningPlugin {
102
102
Err ( _) => return ,
103
103
} ;
104
104
render_app
105
- . init_resource :: < ContrastAdaptiveSharpeningPipeline > ( )
106
- . init_resource :: < SpecializedRenderPipelines < ContrastAdaptiveSharpeningPipeline > > ( )
107
- . add_system_to_stage (
108
- RenderStage :: Prepare ,
109
- prepare_contrast_adaptive_sharpening_pipelines,
110
- ) ;
105
+ . init_resource :: < CASPipeline > ( )
106
+ . init_resource :: < SpecializedRenderPipelines < CASPipeline > > ( )
107
+ . add_system_to_stage ( RenderStage :: Prepare , prepare_cas_pipelines) ;
111
108
{
112
- let cas_node = ContrastAdaptiveSharpeningNode :: new ( & mut render_app. world ) ;
109
+ let cas_node = CASNode :: new ( & mut render_app. world ) ;
113
110
let mut binding = render_app. world . resource_mut :: < RenderGraph > ( ) ;
114
111
let graph = binding. get_sub_graph_mut ( core_3d:: graph:: NAME ) . unwrap ( ) ;
115
112
@@ -119,7 +116,7 @@ impl Plugin for ContrastAdaptiveSharpeningPlugin {
119
116
graph. input_node ( ) . id ,
120
117
core_3d:: graph:: input:: VIEW_ENTITY ,
121
118
core_3d:: graph:: node:: CONTRAST_ADAPTIVE_SHARPENING ,
122
- ContrastAdaptiveSharpeningNode :: IN_VIEW ,
119
+ CASNode :: IN_VIEW ,
123
120
) ;
124
121
125
122
graph. add_node_edge (
@@ -132,7 +129,7 @@ impl Plugin for ContrastAdaptiveSharpeningPlugin {
132
129
) ;
133
130
}
134
131
{
135
- let cas_node = ContrastAdaptiveSharpeningNode :: new ( & mut render_app. world ) ;
132
+ let cas_node = CASNode :: new ( & mut render_app. world ) ;
136
133
let mut binding = render_app. world . resource_mut :: < RenderGraph > ( ) ;
137
134
let graph = binding. get_sub_graph_mut ( core_2d:: graph:: NAME ) . unwrap ( ) ;
138
135
@@ -142,7 +139,7 @@ impl Plugin for ContrastAdaptiveSharpeningPlugin {
142
139
graph. input_node ( ) . id ,
143
140
core_2d:: graph:: input:: VIEW_ENTITY ,
144
141
core_2d:: graph:: node:: CONTRAST_ADAPTIVE_SHARPENING ,
145
- ContrastAdaptiveSharpeningNode :: IN_VIEW ,
142
+ CASNode :: IN_VIEW ,
146
143
) ;
147
144
148
145
graph. add_node_edge (
@@ -158,12 +155,12 @@ impl Plugin for ContrastAdaptiveSharpeningPlugin {
158
155
}
159
156
160
157
#[ derive( Resource ) ]
161
- pub struct ContrastAdaptiveSharpeningPipeline {
158
+ pub struct CASPipeline {
162
159
texture_bind_group : BindGroupLayout ,
163
160
sampler : Sampler ,
164
161
}
165
162
166
- impl FromWorld for ContrastAdaptiveSharpeningPipeline {
163
+ impl FromWorld for CASPipeline {
167
164
fn from_world ( render_world : & mut World ) -> Self {
168
165
let render_device = render_world. resource :: < RenderDevice > ( ) ;
169
166
let texture_bind_group =
@@ -191,7 +188,7 @@ impl FromWorld for ContrastAdaptiveSharpeningPipeline {
191
188
binding : 2 ,
192
189
ty : BindingType :: Buffer {
193
190
ty : BufferBindingType :: Uniform ,
194
- has_dynamic_offset : false ,
191
+ has_dynamic_offset : true ,
195
192
min_binding_size : Some ( CASUniform :: min_size ( ) ) ,
196
193
} ,
197
194
visibility : ShaderStages :: FRAGMENT ,
@@ -202,20 +199,20 @@ impl FromWorld for ContrastAdaptiveSharpeningPipeline {
202
199
203
200
let sampler = render_device. create_sampler ( & SamplerDescriptor :: default ( ) ) ;
204
201
205
- ContrastAdaptiveSharpeningPipeline {
202
+ CASPipeline {
206
203
texture_bind_group,
207
204
sampler,
208
205
}
209
206
}
210
207
}
211
208
212
209
#[ derive( PartialEq , Eq , Hash , Clone , Copy ) ]
213
- pub struct SharpeningPipelineKey {
210
+ pub struct CASPipelineKey {
214
211
texture_format : TextureFormat ,
215
212
}
216
213
217
- impl SpecializedRenderPipeline for ContrastAdaptiveSharpeningPipeline {
218
- type Key = SharpeningPipelineKey ;
214
+ impl SpecializedRenderPipeline for CASPipeline {
215
+ type Key = CASPipelineKey ;
219
216
220
217
fn specialize ( & self , key : Self :: Key ) -> RenderPipelineDescriptor {
221
218
RenderPipelineDescriptor {
@@ -239,11 +236,11 @@ impl SpecializedRenderPipeline for ContrastAdaptiveSharpeningPipeline {
239
236
}
240
237
}
241
238
242
- pub fn prepare_contrast_adaptive_sharpening_pipelines (
239
+ pub fn prepare_cas_pipelines (
243
240
mut commands : Commands ,
244
241
pipeline_cache : Res < PipelineCache > ,
245
- mut pipelines : ResMut < SpecializedRenderPipelines < ContrastAdaptiveSharpeningPipeline > > ,
246
- sharpening_pipeline : Res < ContrastAdaptiveSharpeningPipeline > ,
242
+ mut pipelines : ResMut < SpecializedRenderPipelines < CASPipeline > > ,
243
+ sharpening_pipeline : Res < CASPipeline > ,
247
244
views : Query < ( Entity , & ExtractedView , & CASUniform ) > ,
248
245
) {
249
246
for ( entity, view, sharpening) in & views {
@@ -253,7 +250,7 @@ pub fn prepare_contrast_adaptive_sharpening_pipelines(
253
250
let pipeline_id = pipelines. specialize (
254
251
& pipeline_cache,
255
252
& sharpening_pipeline,
256
- SharpeningPipelineKey {
253
+ CASPipelineKey {
257
254
texture_format : if view. hdr {
258
255
ViewTarget :: TEXTURE_FORMAT_HDR
259
256
} else {
@@ -262,11 +259,9 @@ pub fn prepare_contrast_adaptive_sharpening_pipelines(
262
259
} ,
263
260
) ;
264
261
265
- commands
266
- . entity ( entity)
267
- . insert ( ViewContrastAdaptiveSharpeningPipeline ( pipeline_id) ) ;
262
+ commands. entity ( entity) . insert ( ViewCASPipeline ( pipeline_id) ) ;
268
263
}
269
264
}
270
265
271
266
#[ derive( Component ) ]
272
- pub struct ViewContrastAdaptiveSharpeningPipeline ( CachedRenderPipelineId ) ;
267
+ pub struct ViewCASPipeline ( CachedRenderPipelineId ) ;
0 commit comments