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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
use bevy::{
core_pipeline::prepass::{DeferredPrepass, DepthPrepass, NormalPrepass},
prelude::*,
render::{extract_component::ExtractComponent, render_resource::ShaderType},
};
/// 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,
/// Color of outlines.
color: LinearRgba,
/// 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,
/// A threshold for depth differences (in units), values below this threshold will not become outlines.
/// Higher values will result in more outlines which may look better on smooth surfaces.
depth_threshold: f32,
/// Luma threshold to invert outline color. A value of `1.0` means this feature is disabled.
adaptive_threshold: f32,
/// Near plane depth of camera, used for linearization of depth buffer values
pub(crate) camera_near: f32,
}
impl OutlinePostProcessSettings {
/// Create a new instance with the given settings
pub fn new(
weight: f32,
color: LinearRgba,
normal_threshold: f32,
depth_threshold: f32,
adaptive_threshold: f32,
) -> Self {
Self {
weight,
color,
normal_threshold,
depth_threshold,
adaptive_threshold,
camera_near: 0.0,
}
}
}
impl Default for OutlinePostProcessSettings {
fn default() -> Self {
Self {
weight: 1.0,
color: LinearRgba::BLACK,
normal_threshold: 0.01,
depth_threshold: 0.05,
adaptive_threshold: 1.0,
camera_near: 0.0,
}
}
}
|