aboutsummaryrefslogtreecommitdiff
path: root/src/lib.rs
blob: 12dd5bbc89baad84420b975b50935b29991afd49 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use bevy::{prelude::*, render::{RenderApp, extract_component::{UniformComponentPlugin, ExtractComponentPlugin}, render_graph::{RenderGraphApp, ViewNodeRunner}}, asset::embedded_asset, core_pipeline::core_3d::graph::{Core3d, Node3d}};

pub use nodes::OutlineRenderLabel;

pub struct OutlinePostProcessPlugin;

pub mod components;
mod resources;
mod nodes;

impl Plugin for OutlinePostProcessPlugin {
    fn build(&self, app: &mut App) {
        embedded_asset!(app, "../assets/shaders/outline_post_process.wgsl");

        app.add_plugins((
            UniformComponentPlugin::<components::OutlinePostProcessSettings>::default(),
            ExtractComponentPlugin::<components::OutlinePostProcessSettings>::default(),
        ));
    
        let Ok(render_app) = app.get_sub_app_mut(RenderApp) else {
            return;
        };

        render_app.add_render_graph_node::<ViewNodeRunner<nodes::OutlineRenderNode>>(
            Core3d,
            nodes::OutlineRenderLabel,
        ).add_render_graph_edges(
            Core3d, 
            (
                Node3d::Tonemapping,
                nodes::OutlineRenderLabel,
                Node3d::EndMainPassPostProcessing,
            ),
        );
    }
    
    fn finish(&self, app: &mut App) {
        let Ok(render_app) = app.get_sub_app_mut(RenderApp) else {
            return;
        };

        render_app.init_resource::<resources::OutlinePostProcessPipeline>();
    }
}