bevy_pbr/parallax.rs
1use 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)]
16pub 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}
36impl ParallaxMappingMethod {
37 /// [`ParallaxMappingMethod::Relief`] with a 5 steps, a reasonable default.
38 pub const DEFAULT_RELIEF_MAPPING: Self = ParallaxMappingMethod::Relief { max_steps: 5 };
39
40 pub(crate) fn max_steps(&self) -> u32 {
41 match self {
42 ParallaxMappingMethod::Occlusion => 0,
43 ParallaxMappingMethod::Relief { max_steps } => *max_steps,
44 }
45 }
46}