ParallaxMaterial

Struct ParallaxMaterial 

Source
pub struct ParallaxMaterial {
Show 21 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, pub fog_enabled: bool,
}
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.

§fog_enabled: bool

Whether to enable fog for this material

Trait Implementations§

Source§

impl AsBindGroup for ParallaxMaterial

Source§

type Data = ParallaxMaterialKey

Data that will be stored alongside the “prepared” bind group.
Source§

fn as_bind_group( &self, layout: &BindGroupLayout, render_device: &RenderDevice, images: &RenderAssets<Image>, fallback_image: &FallbackImage, ) -> Result<PreparedBindGroup<Self::Data>, AsBindGroupError>

Creates a bind group for self matching the layout defined in AsBindGroup::bind_group_layout.
Source§

fn bind_group_layout(render_device: &RenderDevice) -> BindGroupLayout

Creates the bind group layout matching all bind groups returned by AsBindGroup::as_bind_group
Source§

impl AsBindGroupShaderType<ParallaxMaterialUniform> for ParallaxMaterial

Source§

fn as_bind_group_shader_type( &self, images: &RenderAssets<Image>, ) -> ParallaxMaterialUniform

Return the T ShaderType for self. When used in AsBindGroup derives, it is safe to assume that all images in self exist.
Source§

impl Clone for ParallaxMaterial

Source§

fn clone(&self) -> ParallaxMaterial

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ParallaxMaterial

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ParallaxMaterial

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl From<&ParallaxMaterial> for ParallaxMaterialKey

Source§

fn from(material: &ParallaxMaterial) -> Self

Converts to this type from the input type.
Source§

impl From<&ParallaxMaterial> for StandardMaterial

Source§

fn from(mat: &ParallaxMaterial) -> Self

Converts to this type from the input type.
Source§

impl FromReflect for ParallaxMaterial

Source§

fn from_reflect(reflect: &dyn Reflect) -> Option<Self>

Constructs a concrete instance of Self from a reflected value.
Source§

fn take_from_reflect( reflect: Box<dyn Reflect>, ) -> Result<Self, Box<dyn Reflect>>

Attempts to downcast the given value to Self using, constructing the value using from_reflect if that fails. Read more
Source§

impl GetTypeRegistration for ParallaxMaterial

Source§

impl Material for ParallaxMaterial

Source§

fn specialize( _pipeline: &MaterialPipeline<Self>, descriptor: &mut RenderPipelineDescriptor, _layout: &MeshVertexBufferLayout, key: MaterialPipelineKey<Self>, ) -> Result<(), SpecializedMeshPipelineError>

Customizes the default RenderPipelineDescriptor for a specific entity using the entity’s MaterialPipelineKey and MeshVertexBufferLayout as input.
Source§

fn fragment_shader() -> ShaderRef

Returns this material’s fragment shader. If ShaderRef::Default is returned, the default mesh fragment shader will be used.
Source§

fn alpha_mode(&self) -> AlphaMode

Returns this material’s AlphaMode. Defaults to AlphaMode::Opaque.
Source§

fn depth_bias(&self) -> f32

Add a bias to the view depth of the mesh which can be used to force a specific render order for meshes with similar depth, to avoid z-fighting. The bias is in depth-texture units so large values may be needed to overcome small depth differences.
Source§

fn vertex_shader() -> ShaderRef

Returns this material’s vertex shader. If ShaderRef::Default is returned, the default mesh vertex shader will be used.
Source§

fn prepass_vertex_shader() -> ShaderRef

Returns this material’s prepass vertex shader. If ShaderRef::Default is returned, the default prepass vertex shader will be used.
Source§

fn prepass_fragment_shader() -> ShaderRef

Returns this material’s prepass fragment shader. If ShaderRef::Default is returned, the default prepass fragment shader will be used.
Source§

impl Reflect for ParallaxMaterial

Source§

fn type_name(&self) -> &str

Returns the type name of the underlying type.
Source§

fn get_type_info(&self) -> &'static TypeInfo

Returns the TypeInfo of the underlying type. Read more
Source§

fn into_any(self: Box<Self>) -> Box<dyn Any>

Returns the value as a Box<dyn Any>.
Source§

fn as_any(&self) -> &dyn Any

Returns the value as a &dyn Any.
Source§

fn as_any_mut(&mut self) -> &mut dyn Any

Returns the value as a &mut dyn Any.
Source§

fn into_reflect(self: Box<Self>) -> Box<dyn Reflect>

Casts this type to a boxed reflected value.
Source§

fn as_reflect(&self) -> &dyn Reflect

Casts this type to a reflected value.
Source§

fn as_reflect_mut(&mut self) -> &mut dyn Reflect

Casts this type to a mutable reflected value.
Source§

fn clone_value(&self) -> Box<dyn Reflect>

Clones the value as a Reflect trait object. Read more
Source§

fn set(&mut self, value: Box<dyn Reflect>) -> Result<(), Box<dyn Reflect>>

Performs a type-checked assignment of a reflected value to this value. Read more
Source§

fn apply(&mut self, value: &dyn Reflect)

Applies a reflected value to this value. Read more
Source§

fn reflect_ref(&self) -> ReflectRef<'_>

Returns an enumeration of “kinds” of type. Read more
Source§

fn reflect_mut(&mut self) -> ReflectMut<'_>

Returns a mutable enumeration of “kinds” of type. Read more
Source§

fn reflect_owned(self: Box<Self>) -> ReflectOwned

Returns an owned enumeration of “kinds” of type. Read more
Source§

fn reflect_partial_eq(&self, value: &dyn Reflect) -> Option<bool>

Returns a “partial equality” comparison result. Read more
Source§

fn debug(&self, f: &mut Formatter<'_>) -> Result

Debug formatter for the value. Read more
Source§

fn reflect_hash(&self) -> Option<u64>

Returns a hash of the value (which includes the type). Read more
Source§

fn serializable(&self) -> Option<Serializable<'_>>

Returns a serializable version of the value. Read more
Source§

impl Struct for ParallaxMaterial

Source§

fn field(&self, name: &str) -> Option<&dyn Reflect>

Returns a reference to the value of the field named name as a &dyn Reflect.
Source§

fn field_mut(&mut self, name: &str) -> Option<&mut dyn Reflect>

Returns a mutable reference to the value of the field named name as a &mut dyn Reflect.
Source§

fn field_at(&self, index: usize) -> Option<&dyn Reflect>

Returns a reference to the value of the field with index index as a &dyn Reflect.
Source§

fn field_at_mut(&mut self, index: usize) -> Option<&mut dyn Reflect>

Returns a mutable reference to the value of the field with index index as a &mut dyn Reflect.
Source§

fn name_at(&self, index: usize) -> Option<&str>

Returns the name of the field with index index.
Source§

fn field_len(&self) -> usize

Returns the number of fields in the struct.
Source§

fn iter_fields(&self) -> FieldIter<'_>

Returns an iterator over the values of the reflectable fields for this struct.
Source§

fn clone_dynamic(&self) -> DynamicStruct

Clones the struct into a DynamicStruct.
Source§

impl TypeUuid for ParallaxMaterial

Source§

impl Typed for ParallaxMaterial

Source§

fn type_info() -> &'static TypeInfo

Returns the compile-time info for the underlying type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T, U> AsBindGroupShaderType<U> for T
where U: ShaderType, &'a T: for<'a> Into<U>,

Source§

fn as_bind_group_shader_type(&self, _images: &RenderAssets<Image>) -> U

Return the T ShaderType for self. When used in AsBindGroup derives, it is safe to assume that all images in self exist.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromWorld for T
where T: Default,

Source§

fn from_world(_world: &mut World) -> T

Creates Self using data from the given World
Source§

impl<S> GetField for S
where S: Struct,

Source§

fn get_field<T>(&self, name: &str) -> Option<&T>
where T: Reflect,

Returns a reference to the value of the field named name, downcast to T.
Source§

fn get_field_mut<T>(&mut self, name: &str) -> Option<&mut T>
where T: Reflect,

Returns a mutable reference to the value of the field named name, downcast to T.
Source§

impl<T> GetPath for T
where T: Reflect,

Source§

fn reflect_path<'r, 'p>( &'r self, path: &'p str, ) -> Result<&'r (dyn Reflect + 'static), ReflectPathError<'p>>

Returns a reference to the value specified by path. Read more
Source§

fn reflect_path_mut<'r, 'p>( &'r mut self, path: &'p str, ) -> Result<&'r mut (dyn Reflect + 'static), ReflectPathError<'p>>

Returns a mutable reference to the value specified by path. Read more
Source§

fn path<'r, 'p, T>( &'r self, path: &'p str, ) -> Result<&'r T, ReflectPathError<'p>>
where T: Reflect,

Returns a statically typed reference to the value specified by path. Read more
Source§

fn path_mut<'r, 'p, T>( &'r mut self, path: &'p str, ) -> Result<&'r mut T, ReflectPathError<'p>>
where T: Reflect,

Returns a statically typed mutable reference to the value specified by path. Read more
Source§

impl<T, W> HasTypeWitness<W> for T
where W: MakeTypeWitness<Arg = T>, T: ?Sized,

Source§

const WITNESS: W = W::MAKE

A constant of the type witness
Source§

impl<T> Identity for T
where T: ?Sized,

Source§

const TYPE_EQ: TypeEq<T, <T as Identity>::Type> = TypeEq::NEW

Proof that Self is the same type as Self::Type, provides methods for casting between Self and Self::Type.
Source§

type Type = T

The same type as Self, used to emulate type equality bounds (T == U) with associated type equality constraints (T: Identity<Type = U>).
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> TypeData for T
where T: 'static + Send + Sync + Clone,

Source§

impl<T> TypeUuidDynamic for T
where T: TypeUuid,

Source§

fn type_uuid(&self) -> Uuid

Returns the UUID associated with this value’s type.

Source§

fn type_name(&self) -> &'static str

Returns the type name of this value’s type.

Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> Asset for T

Source§

impl<T> AssetDynamic for T
where T: Send + Sync + 'static + TypeUuidDynamic,

Source§

impl<T> Event for T
where T: Send + Sync + 'static,