bevy_pbr/parallax.rs
1use bevy_reflect::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)]
15pub enum ParallaxMappingMethod {
16 /// A simple linear interpolation, using a single texture sample.
17 ///
18 /// This method is named "Parallax Occlusion Mapping".
19 ///
20 /// Unlike [`ParallaxMappingMethod::Relief`], only requires a single lookup,
21 /// but may skip small details and result in writhing material artifacts.
22 #[default]
23 Occlusion,
24 /// Discovers the best depth value based on binary search.
25 ///
26 /// Each iteration incurs a texture sample.
27 /// The result has fewer visual artifacts than [`ParallaxMappingMethod::Occlusion`].
28 ///
29 /// This method is named "Relief Mapping".
30 Relief {
31 /// How many additional steps to use at most to find the depth value.
32 max_steps: u32,
33 },
34}
35impl ParallaxMappingMethod {
36 /// [`ParallaxMappingMethod::Relief`] with a 5 steps, a reasonable default.
37 pub const DEFAULT_RELIEF_MAPPING: Self = ParallaxMappingMethod::Relief { max_steps: 5 };
38
39 pub(crate) fn max_steps(&self) -> u32 {
40 match self {
41 ParallaxMappingMethod::Occlusion => 0,
42 ParallaxMappingMethod::Relief { max_steps } => *max_steps,
43 }
44 }
45}