Trait Material

Source
pub trait Material {
    // Required methods
    fn fragment_shader_source(&self, lights: &[&dyn Light]) -> String;
    fn id(&self) -> EffectMaterialId;
    fn use_uniforms(
        &self,
        program: &Program,
        viewer: &dyn Viewer,
        lights: &[&dyn Light],
    );
    fn render_states(&self) -> RenderStates;
    fn material_type(&self) -> MaterialType;
}
Expand description

Represents a material that, together with a geometry, can be rendered using Geometry::render_with_material. Alternatively, a geometry and a material can be combined in a Gm, thereby creating an Object which can be used in a render call, for example RenderTarget::render.

An implementation of the Geometry trait should provide a set of attributes which can be used in the fragment shader. The following attributes might be available:

  • position: in vec3 pos; (in world space)
  • normal: in vec3 nor;
  • tangent: in vec3 tang;
  • bitangent: in vec3 bitang;
  • uv coordinates: in vec2 uvs; (flipped in v compared to standard uv coordinates)
  • color: in vec4 col;

Required Methods§

Source

fn fragment_shader_source(&self, lights: &[&dyn Light]) -> String

Returns the fragment shader source for this material.

Source

fn id(&self) -> EffectMaterialId

Returns a unique ID for each variation of the shader source returned from Material::fragment_shader_source.

Note: The last bit is reserved to internally implemented materials, so if implementing the Material trait outside of this crate, always return an id in the public use range as defined by EffectMaterialId.

Source

fn use_uniforms( &self, program: &Program, viewer: &dyn Viewer, lights: &[&dyn Light], )

Sends the uniform data needed for this material to the fragment shader.

Source

fn render_states(&self) -> RenderStates

Returns the render states needed to render with this material.

Source

fn material_type(&self) -> MaterialType

Returns the type of material.

Implementations on Foreign Types§

Source§

impl<T: Material + ?Sized> Material for &T

Source§

fn fragment_shader_source(&self, lights: &[&dyn Light]) -> String

Source§

fn use_uniforms( &self, program: &Program, viewer: &dyn Viewer, lights: &[&dyn Light], )

Source§

fn render_states(&self) -> RenderStates

Source§

fn material_type(&self) -> MaterialType

Source§

fn id(&self) -> EffectMaterialId

Source§

impl<T: Material + ?Sized> Material for &mut T

Source§

fn fragment_shader_source(&self, lights: &[&dyn Light]) -> String

Source§

fn use_uniforms( &self, program: &Program, viewer: &dyn Viewer, lights: &[&dyn Light], )

Source§

fn render_states(&self) -> RenderStates

Source§

fn material_type(&self) -> MaterialType

Source§

fn id(&self) -> EffectMaterialId

Source§

impl<T: Material> Material for Box<T>

Source§

fn fragment_shader_source(&self, lights: &[&dyn Light]) -> String

Source§

fn use_uniforms( &self, program: &Program, viewer: &dyn Viewer, lights: &[&dyn Light], )

Source§

fn render_states(&self) -> RenderStates

Source§

fn material_type(&self) -> MaterialType

Source§

fn id(&self) -> EffectMaterialId

Source§

impl<T: Material> Material for Rc<T>

Source§

fn fragment_shader_source(&self, lights: &[&dyn Light]) -> String

Source§

fn use_uniforms( &self, program: &Program, viewer: &dyn Viewer, lights: &[&dyn Light], )

Source§

fn render_states(&self) -> RenderStates

Source§

fn material_type(&self) -> MaterialType

Source§

fn id(&self) -> EffectMaterialId

Source§

impl<T: Material> Material for Arc<T>

Source§

fn fragment_shader_source(&self, lights: &[&dyn Light]) -> String

Source§

fn use_uniforms( &self, program: &Program, viewer: &dyn Viewer, lights: &[&dyn Light], )

Source§

fn render_states(&self) -> RenderStates

Source§

fn material_type(&self) -> MaterialType

Source§

fn id(&self) -> EffectMaterialId

Source§

impl<T: Material> Material for RefCell<T>

Source§

fn fragment_shader_source(&self, lights: &[&dyn Light]) -> String

Source§

fn use_uniforms( &self, program: &Program, viewer: &dyn Viewer, lights: &[&dyn Light], )

Source§

fn render_states(&self) -> RenderStates

Source§

fn material_type(&self) -> MaterialType

Source§

fn id(&self) -> EffectMaterialId

Source§

impl<T: Material> Material for RwLock<T>

Source§

fn fragment_shader_source(&self, lights: &[&dyn Light]) -> String

Source§

fn use_uniforms( &self, program: &Program, viewer: &dyn Viewer, lights: &[&dyn Light], )

Source§

fn render_states(&self) -> RenderStates

Source§

fn material_type(&self) -> MaterialType

Source§

fn id(&self) -> EffectMaterialId

Implementors§