aboutsummaryrefslogtreecommitdiff
path: root/src/components.rs
blob: 22de86c9a18438aff2962ecc6a4b793db26eeb63 (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::{extract_component::ExtractComponent, render_resource::ShaderType},
    core_pipeline::prepass::{NormalPrepass, DepthPrepass, DeferredPrepass},
};

/// Component which, when inserted into an entity with a camera and normal prepass, enables an outline effect for that
/// camera.
#[derive(Component, ShaderType, ExtractComponent, PartialEq, Clone)]
#[require(NormalPrepass, DepthPrepass, DeferredPrepass, Msaa(|| Msaa::Off))]
pub struct OutlinePostProcessSettings {
    /// Weight of outlines in pixels.
    weight: f32,
    /// A threshold for normal differences, values below this threshold will not become outlines.
    /// Higher values will result in more outlines which may look better on smooth surfaces.
    normal_threshold: f32,
    /// Whether to use adaptive outlines. White outlines will be drawn around darker objects, while black ones will be drawn around lighter ones.
    adaptive: u32,
    /// Threshold of illumination for outlines to apply. Requires deferred prepass.
    light_threshold: f32,
}

impl OutlinePostProcessSettings {
    /// Create a new instance with the given settings
    pub fn new(weight: f32, normal_threshold: f32, adaptive: bool, light_threshold: f32) -> Self {
        Self {
            weight,
            normal_threshold,
            adaptive: adaptive as u32,
            light_threshold,
        }
    }
}

impl Default for OutlinePostProcessSettings {
    fn default() -> Self {
        Self {
            weight: 1.0,
            normal_threshold: 0.0,
            adaptive: 0,
            light_threshold: 0.0,
        }
    }
}