-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Add parallax mapping to bevy PBR #5928
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
e975dd3
Add parallax mapping to bevy_pbr
nicopap 733f8c7
Parametrize MAX_STEPS, fix iteration count
nicopap 4f70217
Clarify tangent space calculation
nicopap 43fe5c4
Better doc on ParallaxMappingMethod
nicopap ba340db
Naming & clarify code in pbr shader
nicopap fe4e53d
Improvements to parallax mapping code for comprehensibility and corre…
superdump 4653c5c
Parallax depth -> parallax depth scale
superdump f80a3ab
Improve doc wording
nicopap 7f32b0e
formatting
nicopap d1281ae
Fix documentatation
nicopap e0f78b6
Add max_step controls + clamp to 0 depth
nicopap 57bd85b
Use pngs for parallax_mapping example
nicopap 30ab17d
Fix Dx12 backend panic
nicopap File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
use bevy_reflect::{FromReflect, 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, FromReflect)] | ||
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, | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.