11use bevy_reflect:: { FromReflect , Reflect } ;
22
3- /// The parallax mapping method to use to compute a displacement based on the
3+ /// The parallax mapping method to use to compute depth based on the
44/// material's [`depth_map`].
55///
66/// See the `parallax_mapping.wgsl` shader code for implementation details
@@ -12,9 +12,25 @@ pub enum ParallaxMappingMethod {
1212 /// A simple linear interpolation, using a single texture sample.
1313 #[ default]
1414 ParallaxOcclusionMapping ,
15- /// A discovery of 5 iterations of the best displacement
16- /// value. Each iteration incurs a texture sample.
15+ /// Discovers the best depth value based on binary search.
1716 ///
17+ /// Each iteration incurs a texture sample.
1818 /// The result has fewer visual artifacts than `ParallaxOcclusionMapping`.
19- ReliefMapping { n_steps : u32 } ,
19+ ReliefMapping {
20+ /// How many additional steps to use at most to find the depth value.
21+ max_steps : u32 ,
22+ } ,
23+ }
24+ impl ParallaxMappingMethod {
25+ /// [`ReliefMapping`] with a 5 steps, a reasonable default.
26+ ///
27+ /// [`ReliefMapping`]: Self::ReliefMapping
28+ pub const DEFAULT_RELIEF_MAPPING : Self = ParallaxMappingMethod :: ReliefMapping { max_steps : 5 } ;
29+
30+ pub ( crate ) fn max_steps ( & self ) -> u32 {
31+ match self {
32+ ParallaxMappingMethod :: ParallaxOcclusionMapping => 0 ,
33+ ParallaxMappingMethod :: ReliefMapping { max_steps } => * max_steps,
34+ }
35+ }
2036}
0 commit comments