Struct bevy::prelude::StandardMaterial
pub struct StandardMaterial {Show 16 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: Option<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,
}
Expand description
A material with “standard” properties used in PBR lighting Standard property values with pictures here https://google.github.io/filament/Material%20Properties.pdf.
Fields§
§base_color: Color
The color of the surface of the material before lighting.
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
Defaults to Color::WHITE
.
base_color_texture: Option<Handle<Image>>
The texture component of the material’s color before lighting.
The actual pre-lighting color is base_color * this_texture
.
See base_color
for details.
You should set base_color
to Color::WHITE
(the default)
if you want the texture to show as-is.
Setting base_color
to something else than white will tint
the texture. For example, setting base_color
to pure red will
tint the texture red.
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>>
The emissive map, multiplies pixels with emissive
to get the final “emitting” color of a surface.
This color is multiplied by emissive
to get the final emitted color.
Meaning that you should set emissive
to Color::WHITE
if you want to use the full range of color of the emissive texture.
perceptual_roughness: f32
Linear perceptual roughness, clamped to [0.089, 1.0]
in the shader.
Defaults to minimum of 0.089
.
Low values result in a “glossy” material with specular highlights,
while values close to 1
result in rough materials.
If used together with a roughness/metallic texture, this is factored into the final base
color as roughness * roughness_texture_value
.
metallic: f32
How “metallic” the material appears, within [0.0, 1.0]
,
going from dielectric to pure metallic.
Defaults to 0.01
.
The closer to 1
the value, the more the material will
reflect light like a metal such as steel or gold.
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>>
Metallic and roughness maps, stored as a single texture.
The blue channel contains metallic values, and the green channel contains the roughness values. Other channels are unused.
Those values are multiplied by the scalar ones of the material,
see metallic
and perceptual_roughness
for details.
Note that with the default values of metallic
and perceptual_roughness
,
setting this texture has no effect. If you want to exclusively use the
metallic_roughness_texture
values for your material, make sure to set metallic
and perceptual_roughness
to 1.0
.
reflectance: f32
Specular intensity for non-metals on a linear scale of [0.0, 1.0]
.
Use the value as a way to control the intensity of the specular highlight of the material, i.e. how reflective is the material, rather than the physical property “reflectance.”
Set to 0.0
, no specular highlight is visible, the highlight is strongest
when reflectance
is set to 1.0
.
Defaults to 0.5
which is mapped to 4% reflectance in the shader.
normal_map_texture: Option<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.
If set to None
, the two sides of the mesh are visible.
Defaults to Some(Face::Back)
.
In bevy, the order of declaration of a triangle’s vertices
in Mesh
defines the triangle’s front face.
When a triangle is in a viewport, if its vertices appear counter-clockwise from the viewport’s perspective, then the viewport is seeing the triangle’s front face. Conversly, if the vertices appear clockwise, you are seeing the back face.
In short, in bevy, front faces winds counter-clockwise.
Your 3D editing software should manage all of that.
unlit: bool
Whether to apply only the base color to this material.
Normals, occlusion textures, roughness, metallic, reflectance, emissive,
shadows, alpha mode and ambient light are ignored if this is set to true
.
alpha_mode: AlphaMode
How to apply the alpha channel of the base_color_texture
.
See AlphaMode
for details. Defaults to AlphaMode::Opaque
.
depth_bias: f32
Re-arrange render ordering.
A material with a positive depth bias will render closer to the camera while negative values cause the material to render behind other objects. This is independent of the viewport.
depth_bias
only affects render ordering. This means that for opaque materials,
depth_bias
will only have any effect if two materials are overlapping,
which only serves as a z-fighting resolver.
depth_bias
can however reorder AlphaMode::Blend
materials.
This is useful if your transparent materials are not rendering
in the expected order.
Trait Implementations§
§impl AsBindGroup for StandardMaterial
impl AsBindGroup for StandardMaterial
§type Data = StandardMaterialKey
type Data = StandardMaterialKey
§fn as_bind_group(
&self,
layout: &BindGroupLayout,
render_device: &RenderDevice,
images: &RenderAssets<Image>,
fallback_image: &FallbackImage
) -> Result<PreparedBindGroup<StandardMaterial>, AsBindGroupError>
fn as_bind_group(
&self,
layout: &BindGroupLayout,
render_device: &RenderDevice,
images: &RenderAssets<Image>,
fallback_image: &FallbackImage
) -> Result<PreparedBindGroup<StandardMaterial>, AsBindGroupError>
self
matching the layout defined in AsBindGroup::bind_group_layout
.§fn bind_group_layout(render_device: &RenderDevice) -> BindGroupLayout
fn bind_group_layout(render_device: &RenderDevice) -> BindGroupLayout
AsBindGroup::as_bind_group
§impl AsBindGroupShaderType<StandardMaterialUniform> for StandardMaterial
impl AsBindGroupShaderType<StandardMaterialUniform> for StandardMaterial
§fn as_bind_group_shader_type(
&self,
images: &RenderAssets<Image>
) -> StandardMaterialUniform
fn as_bind_group_shader_type(
&self,
images: &RenderAssets<Image>
) -> StandardMaterialUniform
T
ShaderType
for self
. When used in AsBindGroup
derives, it is safe to assume that all images in self
exist. Read more§impl Clone for StandardMaterial
impl Clone for StandardMaterial
§fn clone(&self) -> StandardMaterial
fn clone(&self) -> StandardMaterial
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more§impl Debug for StandardMaterial
impl Debug for StandardMaterial
§impl Default for StandardMaterial
impl Default for StandardMaterial
§fn default() -> StandardMaterial
fn default() -> StandardMaterial
§impl From<&StandardMaterial> for StandardMaterialKey
impl From<&StandardMaterial> for StandardMaterialKey
§fn from(material: &StandardMaterial) -> StandardMaterialKey
fn from(material: &StandardMaterial) -> StandardMaterialKey
§impl From<Color> for StandardMaterial
impl From<Color> for StandardMaterial
§fn from(color: Color) -> StandardMaterial
fn from(color: Color) -> StandardMaterial
§impl From<Handle<Image>> for StandardMaterial
impl From<Handle<Image>> for StandardMaterial
§fn from(texture: Handle<Image>) -> StandardMaterial
fn from(texture: Handle<Image>) -> StandardMaterial
§impl FromReflect for StandardMaterialwhere
Color: FromReflect,
Option<Handle<Image>>: FromReflect,
f32: FromReflect,
bool: FromReflect,
AlphaMode: FromReflect,
impl FromReflect for StandardMaterialwhere
Color: FromReflect,
Option<Handle<Image>>: FromReflect,
f32: FromReflect,
bool: FromReflect,
AlphaMode: FromReflect,
§fn from_reflect(reflect: &(dyn Reflect + 'static)) -> Option<StandardMaterial>
fn from_reflect(reflect: &(dyn Reflect + 'static)) -> Option<StandardMaterial>
Self
from a reflected value.§impl GetTypeRegistration for StandardMaterial
impl GetTypeRegistration for StandardMaterial
§impl Material for StandardMaterial
impl Material for StandardMaterial
§fn specialize(
_pipeline: &MaterialPipeline<StandardMaterial>,
descriptor: &mut RenderPipelineDescriptor,
_layout: &Hashed<InnerMeshVertexBufferLayout, FixedState>,
key: MaterialPipelineKey<StandardMaterial>
) -> Result<(), SpecializedMeshPipelineError>
fn specialize(
_pipeline: &MaterialPipeline<StandardMaterial>,
descriptor: &mut RenderPipelineDescriptor,
_layout: &Hashed<InnerMeshVertexBufferLayout, FixedState>,
key: MaterialPipelineKey<StandardMaterial>
) -> Result<(), SpecializedMeshPipelineError>
RenderPipelineDescriptor
for a specific entity using the entity’s
MaterialPipelineKey
and MeshVertexBufferLayout
as input. Read more§fn fragment_shader() -> ShaderRef
fn fragment_shader() -> ShaderRef
ShaderRef::Default
is returned, the default mesh fragment shader
will be used. Read more§fn alpha_mode(&self) -> AlphaMode
fn alpha_mode(&self) -> AlphaMode
AlphaMode
. Defaults to AlphaMode::Opaque
.§fn 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 more§impl Reflect for StandardMaterial
impl Reflect for StandardMaterial
§fn get_type_info(&self) -> &'static TypeInfo
fn get_type_info(&self) -> &'static TypeInfo
§fn into_any(
self: Box<StandardMaterial, Global>
) -> Box<dyn Any + 'static, Global>
fn into_any(
self: Box<StandardMaterial, Global>
) -> Box<dyn Any + 'static, Global>
Box<dyn Any>
.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut dyn Any
.§fn into_reflect(
self: Box<StandardMaterial, Global>
) -> Box<dyn Reflect + 'static, Global>
fn into_reflect(
self: Box<StandardMaterial, Global>
) -> Box<dyn Reflect + 'static, Global>
§fn as_reflect(&self) -> &(dyn Reflect + 'static)
fn as_reflect(&self) -> &(dyn Reflect + 'static)
§fn as_reflect_mut(&mut self) -> &mut (dyn Reflect + 'static)
fn as_reflect_mut(&mut self) -> &mut (dyn Reflect + 'static)
§fn clone_value(&self) -> Box<dyn Reflect + 'static, Global>
fn clone_value(&self) -> Box<dyn Reflect + 'static, Global>
Reflect
trait object. Read more§fn set(
&mut self,
value: Box<dyn Reflect + 'static, Global>
) -> Result<(), Box<dyn Reflect + 'static, Global>>
fn set(
&mut self,
value: Box<dyn Reflect + 'static, Global>
) -> Result<(), Box<dyn Reflect + 'static, Global>>
§fn apply(&mut self, value: &(dyn Reflect + 'static))
fn apply(&mut self, value: &(dyn Reflect + 'static))
§fn reflect_ref(&self) -> ReflectRef<'_>
fn reflect_ref(&self) -> ReflectRef<'_>
§fn reflect_mut(&mut self) -> ReflectMut<'_>
fn reflect_mut(&mut self) -> ReflectMut<'_>
§fn reflect_owned(self: Box<StandardMaterial, Global>) -> ReflectOwned
fn reflect_owned(self: Box<StandardMaterial, Global>) -> ReflectOwned
§fn reflect_partial_eq(&self, value: &(dyn Reflect + 'static)) -> Option<bool>
fn reflect_partial_eq(&self, value: &(dyn Reflect + 'static)) -> Option<bool>
§fn debug(&self, f: &mut Formatter<'_>) -> Result<(), Error>
fn debug(&self, f: &mut Formatter<'_>) -> Result<(), Error>
§fn reflect_hash(&self) -> Option<u64>
fn reflect_hash(&self) -> Option<u64>
§fn serializable(&self) -> Option<Serializable<'_>>
fn serializable(&self) -> Option<Serializable<'_>>
§impl Struct for StandardMaterial
impl Struct for StandardMaterial
§fn field_at_mut(&mut self, index: usize) -> Option<&mut (dyn Reflect + 'static)>
fn field_at_mut(&mut self, index: usize) -> Option<&mut (dyn Reflect + 'static)>
index
as a &mut dyn Reflect
. Read more§fn iter_fields(&self) -> FieldIter<'_> ⓘ
fn iter_fields(&self) -> FieldIter<'_> ⓘ
§fn clone_dynamic(&self) -> DynamicStruct
fn clone_dynamic(&self) -> DynamicStruct
DynamicStruct
.§impl TypeUuid for StandardMaterial
impl TypeUuid for StandardMaterial
Auto Trait Implementations§
impl RefUnwindSafe for StandardMaterial
impl Send for StandardMaterial
impl Sync for StandardMaterial
impl Unpin for StandardMaterial
impl UnwindSafe for StandardMaterial
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 more§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 more§fn 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 more§fn 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 more§fn 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 more§impl<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§impl<S> GetField for Swhere
S: Struct,
impl<S> GetField for Swhere
S: Struct,
§impl<T> GetPath for Twhere
T: Reflect,
impl<T> GetPath for Twhere
T: Reflect,
§fn path<'r, 'p>(
&'r self,
path: &'p str
) -> Result<&'r (dyn Reflect + 'static), ReflectPathError<'p>>
fn path<'r, 'p>(
&'r self,
path: &'p str
) -> Result<&'r (dyn Reflect + 'static), ReflectPathError<'p>>
path
. Read more§fn path_mut<'r, 'p>(
&'r mut self,
path: &'p str
) -> Result<&'r mut (dyn Reflect + 'static), ReflectPathError<'p>>
fn path_mut<'r, 'p>(
&'r mut self,
path: &'p str
) -> Result<&'r mut (dyn Reflect + 'static), ReflectPathError<'p>>
path
. Read more§fn get_path<T, 'r, 'p>(
&'r self,
path: &'p str
) -> Result<&'r T, ReflectPathError<'p>>where
T: Reflect,
fn get_path<T, 'r, 'p>(
&'r self,
path: &'p str
) -> Result<&'r T, ReflectPathError<'p>>where
T: Reflect,
path
.§fn get_path_mut<T, 'r, 'p>(
&'r mut self,
path: &'p str
) -> Result<&'r mut T, ReflectPathError<'p>>where
T: Reflect,
fn get_path_mut<T, 'r, 'p>(
&'r mut self,
path: &'p str
) -> Result<&'r mut T, ReflectPathError<'p>>where
T: Reflect,
path
. Read more