Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bevyengine
GitHub Repository: bevyengine/bevy
Path: blob/main/crates/bevy_anti_alias/src/fxaa/node.rs
9299 views
1
use crate::fxaa::{CameraFxaaPipeline, Fxaa, FxaaPipeline};
2
use bevy_ecs::prelude::*;
3
use bevy_render::{
4
diagnostic::RecordDiagnostics,
5
render_resource::{
6
BindGroup, BindGroupEntries, Operations, PipelineCache, RenderPassColorAttachment,
7
RenderPassDescriptor, TextureViewId,
8
},
9
renderer::{RenderContext, ViewQuery},
10
view::ViewTarget,
11
};
12
13
pub(crate) fn fxaa(
14
view: ViewQuery<(&ViewTarget, &CameraFxaaPipeline, &Fxaa)>,
15
fxaa_pipeline: Res<FxaaPipeline>,
16
pipeline_cache: Res<PipelineCache>,
17
mut ctx: RenderContext,
18
mut cached_bind_group: Local<Option<(TextureViewId, BindGroup)>>,
19
) {
20
let (target, pipeline, fxaa) = view.into_inner();
21
22
if !fxaa.enabled {
23
return;
24
}
25
26
let Some(pipeline) = pipeline_cache.get_render_pipeline(pipeline.pipeline_id) else {
27
return;
28
};
29
30
let post_process = target.post_process_write();
31
let source = post_process.source;
32
let destination = post_process.destination;
33
let bind_group = match &mut *cached_bind_group {
34
Some((id, bind_group)) if source.id() == *id => bind_group,
35
cached => {
36
let bind_group = ctx.render_device().create_bind_group(
37
None,
38
&pipeline_cache.get_bind_group_layout(&fxaa_pipeline.texture_bind_group),
39
&BindGroupEntries::sequential((source, &fxaa_pipeline.sampler)),
40
);
41
42
let (_, bind_group) = cached.insert((source.id(), bind_group));
43
bind_group
44
}
45
};
46
47
let pass_descriptor = RenderPassDescriptor {
48
label: Some("fxaa"),
49
color_attachments: &[Some(RenderPassColorAttachment {
50
view: destination,
51
depth_slice: None,
52
resolve_target: None,
53
ops: Operations::default(),
54
})],
55
depth_stencil_attachment: None,
56
timestamp_writes: None,
57
occlusion_query_set: None,
58
multiview_mask: None,
59
};
60
61
let diagnostics = ctx.diagnostic_recorder();
62
let diagnostics = diagnostics.as_deref();
63
let time_span = diagnostics.time_span(ctx.command_encoder(), "fxaa");
64
65
{
66
let mut render_pass = ctx.command_encoder().begin_render_pass(&pass_descriptor);
67
let pass_span = diagnostics.pass_span(&mut render_pass, "fxaa");
68
69
render_pass.set_pipeline(pipeline);
70
render_pass.set_bind_group(0, bind_group, &[]);
71
render_pass.draw(0..3, 0..1);
72
73
pass_span.end(&mut render_pass);
74
}
75
76
time_span.end(ctx.command_encoder());
77
}
78
79