Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bevyengine
GitHub Repository: bevyengine/bevy
Path: blob/main/crates/bevy_pbr/src/parallax.rs
6598 views
1
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
2
3
/// The [parallax mapping] method to use to compute depth based on the
4
/// material's [`depth_map`].
5
///
6
/// Parallax Mapping uses a depth map texture to give the illusion of depth
7
/// variation on a mesh surface that is geometrically flat.
8
///
9
/// See the `parallax_mapping.wgsl` shader code for implementation details
10
/// and explanation of the methods used.
11
///
12
/// [`depth_map`]: crate::StandardMaterial::depth_map
13
/// [parallax mapping]: https://en.wikipedia.org/wiki/Parallax_mapping
14
#[derive(Debug, Copy, Clone, PartialEq, Eq, Default, Reflect)]
15
#[reflect(Default, Clone, PartialEq)]
16
pub enum ParallaxMappingMethod {
17
/// A simple linear interpolation, using a single texture sample.
18
///
19
/// This method is named "Parallax Occlusion Mapping".
20
///
21
/// Unlike [`ParallaxMappingMethod::Relief`], only requires a single lookup,
22
/// but may skip small details and result in writhing material artifacts.
23
#[default]
24
Occlusion,
25
/// Discovers the best depth value based on binary search.
26
///
27
/// Each iteration incurs a texture sample.
28
/// The result has fewer visual artifacts than [`ParallaxMappingMethod::Occlusion`].
29
///
30
/// This method is named "Relief Mapping".
31
Relief {
32
/// How many additional steps to use at most to find the depth value.
33
max_steps: u32,
34
},
35
}
36
37
impl ParallaxMappingMethod {
38
/// [`ParallaxMappingMethod::Relief`] with a 5 steps, a reasonable default.
39
pub const DEFAULT_RELIEF_MAPPING: Self = ParallaxMappingMethod::Relief { max_steps: 5 };
40
41
pub(crate) fn max_steps(&self) -> u32 {
42
match self {
43
ParallaxMappingMethod::Occlusion => 0,
44
ParallaxMappingMethod::Relief { max_steps } => *max_steps,
45
}
46
}
47
}
48
49