
# Objective Now that #13432 has been merged, it's important we update our reflected types to properly opt into this feature. If we do not, then this could cause issues for users downstream who want to make use of reflection-based cloning. ## Solution This PR is broken into 4 commits: 1. Add `#[reflect(Clone)]` on all types marked `#[reflect(opaque)]` that are also `Clone`. This is mandatory as these types would otherwise cause the cloning operation to fail for any type that contains it at any depth. 2. Update the reflection example to suggest adding `#[reflect(Clone)]` on opaque types. 3. Add `#[reflect(clone)]` attributes on all fields marked `#[reflect(ignore)]` that are also `Clone`. This prevents the ignored field from causing the cloning operation to fail. Note that some of the types that contain these fields are also `Clone`, and thus can be marked `#[reflect(Clone)]`. This makes the `#[reflect(clone)]` attribute redundant. However, I think it's safer to keep it marked in the case that the `Clone` impl/derive is ever removed. I'm open to removing them, though, if people disagree. 4. Finally, I added `#[reflect(Clone)]` on all types that are also `Clone`. While not strictly necessary, it enables us to reduce the generated output since we can just call `Clone::clone` directly instead of calling `PartialReflect::reflect_clone` on each variant/field. It also means we benefit from any optimizations or customizations made in the `Clone` impl, including directly dereferencing `Copy` values and increasing reference counters. Along with that change I also took the liberty of adding any missing registrations that I saw could be applied to the type as well, such as `Default`, `PartialEq`, and `Hash`. There were hundreds of these to edit, though, so it's possible I missed quite a few. That last commit is **_massive_**. There were nearly 700 types to update. So it's recommended to review the first three before moving onto that last one. Additionally, I can break the last commit off into its own PR or into smaller PRs, but I figured this would be the easiest way of doing it (and in a timely manner since I unfortunately don't have as much time as I used to for code contributions). ## Testing You can test locally with a `cargo check`: ``` cargo check --workspace --all-features ```
47 lines
1.8 KiB
Rust
47 lines
1.8 KiB
Rust
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
|
|
|
|
/// The [parallax mapping] method to use to compute depth based on the
|
|
/// material's [`depth_map`].
|
|
///
|
|
/// Parallax Mapping uses a depth map texture to give the illusion of depth
|
|
/// variation on a mesh surface that is geometrically flat.
|
|
///
|
|
/// See the `parallax_mapping.wgsl` shader code for implementation details
|
|
/// and explanation of the methods used.
|
|
///
|
|
/// [`depth_map`]: crate::StandardMaterial::depth_map
|
|
/// [parallax mapping]: https://en.wikipedia.org/wiki/Parallax_mapping
|
|
#[derive(Debug, Copy, Clone, PartialEq, Eq, Default, Reflect)]
|
|
#[reflect(Default, Clone, PartialEq)]
|
|
pub enum ParallaxMappingMethod {
|
|
/// A simple linear interpolation, using a single texture sample.
|
|
///
|
|
/// This method is named "Parallax Occlusion Mapping".
|
|
///
|
|
/// Unlike [`ParallaxMappingMethod::Relief`], only requires a single lookup,
|
|
/// but may skip small details and result in writhing material artifacts.
|
|
#[default]
|
|
Occlusion,
|
|
/// Discovers the best depth value based on binary search.
|
|
///
|
|
/// Each iteration incurs a texture sample.
|
|
/// The result has fewer visual artifacts than [`ParallaxMappingMethod::Occlusion`].
|
|
///
|
|
/// This method is named "Relief Mapping".
|
|
Relief {
|
|
/// How many additional steps to use at most to find the depth value.
|
|
max_steps: u32,
|
|
},
|
|
}
|
|
impl ParallaxMappingMethod {
|
|
/// [`ParallaxMappingMethod::Relief`] with a 5 steps, a reasonable default.
|
|
pub const DEFAULT_RELIEF_MAPPING: Self = ParallaxMappingMethod::Relief { max_steps: 5 };
|
|
|
|
pub(crate) fn max_steps(&self) -> u32 {
|
|
match self {
|
|
ParallaxMappingMethod::Occlusion => 0,
|
|
ParallaxMappingMethod::Relief { max_steps } => *max_steps,
|
|
}
|
|
}
|
|
}
|