pub trait RenderableMaterialTrait: MaterialTrait {
// Required methods
fn shader_name(&self) -> &'static str;
fn version(&self) -> u64;
fn shader_defines(&self) -> ShaderDefines;
fn settings(&self) -> MaterialSettings;
fn visit_textures(&self, visitor: &mut dyn FnMut(&TextureSource));
fn define_bindings<'a>(&'a self, builder: &mut ResourceBuilder<'a>);
fn uniform_buffer(&self) -> BufferRef;
fn with_uniform_bytes(&self, f: &mut dyn FnMut(&[u8]));
// Provided method
fn extra_defines(&self, _defines: &mut ShaderDefines) { ... }
}Expand description
Advanced rendering interface for materials.
This trait is for internal use by the rendering system and for implementing custom material types. Regular users don’t need to import or use this trait directly.
§Implementing Custom Materials
To create a custom material type:
- Implement
MaterialTraitfor basic type support - Implement this trait for rendering capabilities
- Define your uniform struct with
#[repr(C)]andbytemuck - Create a corresponding shader template
See PhysicalMaterial for a reference implementation.
Required Methods§
Sourcefn shader_name(&self) -> &'static str
fn shader_name(&self) -> &'static str
Returns the shader template name.
Sourcefn shader_defines(&self) -> ShaderDefines
fn shader_defines(&self) -> ShaderDefines
Returns shader macro definitions based on current material state.
Sourcefn settings(&self) -> MaterialSettings
fn settings(&self) -> MaterialSettings
Returns material rendering settings.
Sourcefn visit_textures(&self, visitor: &mut dyn FnMut(&TextureSource))
fn visit_textures(&self, visitor: &mut dyn FnMut(&TextureSource))
Visits all textures used by this material.
Sourcefn define_bindings<'a>(&'a self, builder: &mut ResourceBuilder<'a>)
fn define_bindings<'a>(&'a self, builder: &mut ResourceBuilder<'a>)
Defines GPU resource bindings for this material.
Sourcefn uniform_buffer(&self) -> BufferRef
fn uniform_buffer(&self) -> BufferRef
Returns a reference to the uniform buffer.
Sourcefn with_uniform_bytes(&self, f: &mut dyn FnMut(&[u8]))
fn with_uniform_bytes(&self, f: &mut dyn FnMut(&[u8]))
Provides uniform data bytes to the callback.