Struct bevy_mod_paramap::ParallaxMaterial
source · pub struct ParallaxMaterial {Show 20 fields
pub base_color: Color,
pub base_color_texture: Option<Handle<Image>>,
pub emissive: Color,
pub emissive_texture: Option<Handle<Image>>,
pub perceptual_roughness: f32,
pub metallic: f32,
pub metallic_roughness_texture: Option<Handle<Image>>,
pub reflectance: f32,
pub normal_map_texture: Handle<Image>,
pub flip_normal_map_y: bool,
pub occlusion_texture: Option<Handle<Image>>,
pub double_sided: bool,
pub cull_mode: Option<Face>,
pub unlit: bool,
pub alpha_mode: AlphaMode,
pub depth_bias: f32,
pub height_map: Handle<Image>,
pub height_depth: f32,
pub algorithm: ParallaxAlgo,
pub max_height_layers: f32,
}
Expand description
A shameless clone of bevy’s default PBR material with an additional field:
height_map
.
height_map
is a greyscale image representing the height of the object at a given
pixel. Works like the original [StandardMaterial
] otherwise.
WARNING: this material assumes the mesh has tangents set. If your mesh doesn’t have tangents, bad unspecified things will happen.
Fields
base_color: Color
Doubles as diffuse albedo for non-metallic, specular for metallic and a mix for everything
in between. If used together with a base_color_texture, this is factored into the final
base color as base_color * base_color_texture_value
base_color_texture: Option<Handle<Image>>
The “albedo” of the material, when Some
, this will be the texture applied to the mesh.
emissive: Color
Color the material “emits” to the camera.
This is typically used for monitor screens or LED lights. Anything that can be visible even in darkness.
The emissive color is added to what would otherwise be the material’s visible color. This means that for a light emissive value, in darkness, you will mostly see the emissive component.
The default emissive color is black, which doesn’t add anything to the material color.
Note that an emissive material won’t light up surrounding areas like a light source, it just adds a value to the color seen on screen.
emissive_texture: Option<Handle<Image>>
Same as emissive, but based off a texture
perceptual_roughness: f32
Linear perceptual roughness, clamped to [0.089, 1.0] in the shader
Defaults to minimum of 0.089
If used together with a roughness/metallic texture, this is factored into the final base
color as roughness * roughness_texture_value
metallic: f32
From [0.0, 1.0], dielectric to pure metallic
If used together with a roughness/metallic texture, this is factored into the final base
color as metallic * metallic_texture_value
metallic_roughness_texture: Option<Handle<Image>>
A texture representing both metallic
and preceptual_roughness
.
The blue channel is the metallic
and green is roughness
(we don’t
talk about the red channel)
reflectance: f32
Specular intensity for non-metals on a linear scale of [0.0, 1.0] defaults to 0.5 which is mapped to 4% reflectance in the shader
normal_map_texture: Handle<Image>
Used to fake the lighting of bumps and dents on a material.
A typical usage would be faking cobblestones on a flat plane mesh in 3D.
Notes
Normal mapping with StandardMaterial
and the core bevy PBR shaders requires:
- A normal map texture
- Vertex UVs
- Vertex tangents
- Vertex normals
Tangents do not have to be stored in your model,
they can be generated using the Mesh::generate_tangents
method.
If your material has a normal map, but still renders as a flat surface,
make sure your meshes have their tangents set.
flip_normal_map_y: bool
Normal map textures authored for DirectX have their y-component flipped. Set this to flip it to right-handed conventions.
occlusion_texture: Option<Handle<Image>>
Specifies the level of exposure to ambient light.
This is usually generated and stored automatically (“baked”) by 3D-modelling software.
Typically, steep concave parts of a model (such as the armpit of a shirt) are darker, because they have little exposed to light. An occlusion map specifies those parts of the model that light doesn’t reach well.
The material will be less lit in places where this texture is dark. This is similar to ambient occlusion, but built into the model.
double_sided: bool
Support two-sided lighting by automatically flipping the normals for “back” faces
within the PBR lighting shader.
Defaults to false.
This does not automatically configure backface culling, which can be done via
cull_mode
.
cull_mode: Option<Face>
Whether to cull the “front”, “back” or neither side of a mesh
defaults to Face::Back
unlit: bool
Whether to shade this material.
Normals, occlusion textures, roughness, metallic, reflectance and
emissive are ignored if this is set to true
.
alpha_mode: AlphaMode
How to interpret the alpha channel of the base_color_texture
.
By default, it’s Opaque
, therefore completely ignored.
Note that currently bevy handles poorly semi-transparent textures. You
are likely to encounter the following bugs:
- When two
AlphaMode::Blend
material occupy the same pixel, only one material’s color will show. - If a different mesh is both “in front” and “behind” a non-opaque material, bevy won’t know which material to display in front, which might result in flickering.
depth_bias: f32
Re-arange depth of material, useful to avoid z-fighting.
height_map: Handle<Image>
The height map used for parallax mapping.
Black is the tallest, white deepest.
To improve performance, set your height_map
’s [Image::sampler_descriptor
]
filter mode to FilterMode::Nearest
, as this paper indicates, it improves
perfs a bit.
height_depth: f32
How deep the offset introduced by the height map should be.
Default is 0.1, anything over that value may look very awkward. Lower value look less “deep.”
algorithm: ParallaxAlgo
Whether to use a more accurate and more expensive algorithm.
We recommend that all objects use the same ParallaxAlgo
, to avoid
duplicating and running two shaders.
max_height_layers: f32
In how many layers to split the height maps for Steep Parallax Mapping.
If your height_depth
is >0.1
and you are seeing jaggy edges,
increase this value. However, this incures a performance cost.
Default is 16.0.
This must never be less than 2.0
.
Trait Implementations
sourceimpl AsBindGroup for ParallaxMaterial
impl AsBindGroup for ParallaxMaterial
type Data = ParallaxMaterialKey
type Data = ParallaxMaterialKey
sourcefn as_bind_group(
&self,
layout: &BindGroupLayout,
render_device: &RenderDevice,
images: &RenderAssets<Image>,
fallback_image: &FallbackImage
) -> Result<PreparedBindGroup<Self>, AsBindGroupError>
fn as_bind_group(
&self,
layout: &BindGroupLayout,
render_device: &RenderDevice,
images: &RenderAssets<Image>,
fallback_image: &FallbackImage
) -> Result<PreparedBindGroup<Self>, AsBindGroupError>
self
matching the layout defined in [AsBindGroup::bind_group_layout
].sourcefn bind_group_layout(render_device: &RenderDevice) -> BindGroupLayout
fn bind_group_layout(render_device: &RenderDevice) -> BindGroupLayout
AsBindGroup::as_bind_group
]sourceimpl AsBindGroupShaderType<ParallaxMaterialUniform> for ParallaxMaterial
impl AsBindGroupShaderType<ParallaxMaterialUniform> for ParallaxMaterial
sourcefn as_bind_group_shader_type(
&self,
images: &RenderAssets<Image>
) -> ParallaxMaterialUniform
fn as_bind_group_shader_type(
&self,
images: &RenderAssets<Image>
) -> ParallaxMaterialUniform
T
[ShaderType
] for self
. When used in [AsBindGroup
]
derives, it is safe to assume that all images in self
exist. Read moresourceimpl Clone for ParallaxMaterial
impl Clone for ParallaxMaterial
sourcefn clone(&self) -> ParallaxMaterial
fn clone(&self) -> ParallaxMaterial
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresourceimpl Debug for ParallaxMaterial
impl Debug for ParallaxMaterial
sourceimpl Default for ParallaxMaterial
impl Default for ParallaxMaterial
sourceimpl From<&ParallaxMaterial> for ParallaxMaterialKey
impl From<&ParallaxMaterial> for ParallaxMaterialKey
sourcefn from(material: &ParallaxMaterial) -> Self
fn from(material: &ParallaxMaterial) -> Self
sourceimpl From<&ParallaxMaterial> for StandardMaterial
impl From<&ParallaxMaterial> for StandardMaterial
sourcefn from(mat: &ParallaxMaterial) -> Self
fn from(mat: &ParallaxMaterial) -> Self
sourceimpl Material for ParallaxMaterial
impl Material for ParallaxMaterial
sourcefn specialize(
_pipeline: &MaterialPipeline<Self>,
descriptor: &mut RenderPipelineDescriptor,
_layout: &MeshVertexBufferLayout,
key: MaterialPipelineKey<Self>
) -> Result<(), SpecializedMeshPipelineError>
fn specialize(
_pipeline: &MaterialPipeline<Self>,
descriptor: &mut RenderPipelineDescriptor,
_layout: &MeshVertexBufferLayout,
key: MaterialPipelineKey<Self>
) -> Result<(), SpecializedMeshPipelineError>
RenderPipelineDescriptor
] for a specific entity using the entity’s
[MaterialPipelineKey
] and [MeshVertexBufferLayout
] as input. Read moresourcefn fragment_shader() -> ShaderRef
fn fragment_shader() -> ShaderRef
ShaderRef::Default
] is returned, the default mesh fragment shader
will be used. Read moresourcefn alpha_mode(&self) -> AlphaMode
fn alpha_mode(&self) -> AlphaMode
AlphaMode
]. Defaults to [AlphaMode::Opaque
].sourcefn depth_bias(&self) -> f32
fn depth_bias(&self) -> f32
fn vertex_shader() -> ShaderRef
fn vertex_shader() -> ShaderRef
ShaderRef::Default
] is returned, the default mesh vertex shader
will be used. Read moresourceimpl TypeUuid for ParallaxMaterial
impl TypeUuid for ParallaxMaterial
Auto Trait Implementations
impl RefUnwindSafe for ParallaxMaterial
impl Send for ParallaxMaterial
impl Sync for ParallaxMaterial
impl Unpin for ParallaxMaterial
impl UnwindSafe for ParallaxMaterial
Blanket Implementations
impl<T, U> AsBindGroupShaderType<U> for Twhere
U: ShaderType,
&'a T: for<'a> Into<U>,
impl<T, U> AsBindGroupShaderType<U> for Twhere
U: ShaderType,
&'a T: for<'a> Into<U>,
fn as_bind_group_shader_type(&self, _images: &RenderAssets<Image>) -> U
fn as_bind_group_shader_type(&self, _images: &RenderAssets<Image>) -> U
T
[ShaderType
] for self
. When used in [AsBindGroup
]
derives, it is safe to assume that all images in self
exist. Read moresourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
. Read morefn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
. Read morefn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s. Read morefn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s. Read moreimpl<T> FromWorld for Twhere
T: Default,
impl<T> FromWorld for Twhere
T: Default,
fn from_world(_world: &mut World) -> T
fn from_world(_world: &mut World) -> T
Self
using data from the given [World]