wde_renderer/utils/
post_process_mesh.rs

1use bevy::prelude::*;
2
3use crate::{prelude::*, sync::ExtractResource};
4
5/// Resource storing the handle to the full-screen quad mesh used for post-processing passes.
6/// This mesh is a simple quad covering the entire screen, with UVs for sampling the rendered texture.
7#[derive(Resource, Default)]
8pub struct PostProcessingMesh(pub Option<Handle<Mesh>>);
9impl PostProcessingMesh {
10    pub fn init(assets_server: Res<AssetServer>, mut mesh: ResMut<PostProcessingMesh>) {
11        let deferred_mesh: Handle<Mesh> = assets_server.add(Mesh {
12            label: "post-process-mesh".to_string(),
13            vertices: vec![
14                Vertex {
15                    position: [-1.0, 1.0, 0.0],
16                    uv: [0.0, 1.0],
17                    ..Default::default()
18                },
19                Vertex {
20                    position: [-1.0, -1.0, 0.0],
21                    uv: [0.0, 0.0],
22                    ..Default::default()
23                },
24                Vertex {
25                    position: [1.0, -1.0, 0.0],
26                    uv: [1.0, 0.0],
27                    ..Default::default()
28                },
29                Vertex {
30                    position: [1.0, 1.0, 0.0],
31                    uv: [1.0, 1.0],
32                    ..Default::default()
33                },
34            ],
35            indices: vec![0, 1, 2, 0, 2, 3],
36            bbox: MeshBbox {
37                min: Vec3::new(-1.0, -1.0, 0.0),
38                max: Vec3::new(1.0, 1.0, 0.0)
39            },
40            use_ssbo: false
41        });
42        mesh.0 = Some(deferred_mesh);
43    }
44}
45impl ExtractResource for PostProcessingMesh {
46    type Source = Self;
47
48    fn extract(source: &Self::Source) -> Self {
49        Self(source.0.clone())
50    }
51}