Trait bevy::pbr::SpecializedMaterial
[−]pub trait SpecializedMaterial: Asset + RenderAsset {
type Key: PartialEq<Self::Key> + Eq + Hash + Clone + Send + Sync;
fn key(material: &Self::PreparedAsset) -> Self::Key;
fn specialize(
pipeline: &MaterialPipeline<Self>,
descriptor: &mut RenderPipelineDescriptor,
key: Self::Key,
layout: &Hashed<InnerMeshVertexBufferLayout, FixedState>
) -> Result<(), SpecializedMeshPipelineError>;
fn bind_group(material: &Self::PreparedAsset) -> &BindGroup;
fn bind_group_layout(render_device: &RenderDevice) -> BindGroupLayout;
fn vertex_shader(asset_server: &AssetServer) -> Option<Handle<Shader>> { ... }
fn fragment_shader(asset_server: &AssetServer) -> Option<Handle<Shader>> { ... }
fn alpha_mode(material: &Self::PreparedAsset) -> AlphaMode { ... }
fn dynamic_uniform_indices(material: &Self::PreparedAsset) -> &[u32] { ... }
}
Expand description
Materials are used alongside MaterialPlugin
and MaterialMeshBundle
to spawn entities that are rendered with a specific SpecializedMaterial
type. They serve as an easy to use high level
way to render Mesh
entities with custom shader logic. SpecializedMaterials
use their SpecializedMaterial::Key
to customize their RenderPipelineDescriptor
based on specific material values. The slightly simpler Material
trait
should be used for materials that do not need specialization. Material
types automatically implement SpecializedMaterial
.
Required Associated Types
Required Methods
fn key(material: &Self::PreparedAsset) -> Self::Key
fn key(material: &Self::PreparedAsset) -> Self::Key
Extract the SpecializedMaterial::Key
for the “prepared” version of this material. This key will be
passed in to the SpecializedMaterial::specialize
function when compiling the RenderPipeline
for a given entity’s material.
fn specialize(
pipeline: &MaterialPipeline<Self>,
descriptor: &mut RenderPipelineDescriptor,
key: Self::Key,
layout: &Hashed<InnerMeshVertexBufferLayout, FixedState>
) -> Result<(), SpecializedMeshPipelineError>
fn specialize(
pipeline: &MaterialPipeline<Self>,
descriptor: &mut RenderPipelineDescriptor,
key: Self::Key,
layout: &Hashed<InnerMeshVertexBufferLayout, FixedState>
) -> Result<(), SpecializedMeshPipelineError>
Specializes the given descriptor
according to the given key
.
fn bind_group(material: &Self::PreparedAsset) -> &BindGroup
fn bind_group(material: &Self::PreparedAsset) -> &BindGroup
Returns this material’s BindGroup
. This should match the layout returned by SpecializedMaterial::bind_group_layout
.
fn bind_group_layout(render_device: &RenderDevice) -> BindGroupLayout
fn bind_group_layout(render_device: &RenderDevice) -> BindGroupLayout
Returns this material’s BindGroupLayout
. This should match the BindGroup
returned by SpecializedMaterial::bind_group
.
Provided Methods
fn vertex_shader(asset_server: &AssetServer) -> Option<Handle<Shader>>
fn vertex_shader(asset_server: &AssetServer) -> Option<Handle<Shader>>
fn fragment_shader(asset_server: &AssetServer) -> Option<Handle<Shader>>
fn fragment_shader(asset_server: &AssetServer) -> Option<Handle<Shader>>
fn alpha_mode(material: &Self::PreparedAsset) -> AlphaMode
fn alpha_mode(material: &Self::PreparedAsset) -> AlphaMode
Returns this material’s AlphaMode
. Defaults to AlphaMode::Opaque
.
fn dynamic_uniform_indices(material: &Self::PreparedAsset) -> &[u32]
fn dynamic_uniform_indices(material: &Self::PreparedAsset) -> &[u32]
The dynamic uniform indices to set for the given material
’s BindGroup
.
Defaults to an empty array / no dynamic uniform indices.