Skip to main content

RenderableMaterialTrait

Trait RenderableMaterialTrait 

Source
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:

  1. Implement MaterialTrait for basic type support
  2. Implement this trait for rendering capabilities
  3. Define your uniform struct with #[repr(C)] and bytemuck
  4. Create a corresponding shader template

See PhysicalMaterial for a reference implementation.

Required Methods§

Source

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

Returns the shader template name.

Source

fn version(&self) -> u64

Returns the material version (used for cache invalidation).

Source

fn shader_defines(&self) -> ShaderDefines

Returns shader macro definitions based on current material state.

Source

fn settings(&self) -> MaterialSettings

Returns material rendering settings.

Source

fn visit_textures(&self, visitor: &mut dyn FnMut(&TextureSource))

Visits all textures used by this material.

Source

fn define_bindings<'a>(&'a self, builder: &mut ResourceBuilder<'a>)

Defines GPU resource bindings for this material.

Source

fn uniform_buffer(&self) -> BufferRef

Returns a reference to the uniform buffer.

Source

fn with_uniform_bytes(&self, f: &mut dyn FnMut(&[u8]))

Provides uniform data bytes to the callback.

Provided Methods§

Source

fn extra_defines(&self, _defines: &mut ShaderDefines)

Implementors§