pub trait Material {
// Required methods
fn fragment_shader_source(&self, lights: &[&dyn Light]) -> String;
fn id(&self) -> u16;
fn fragment_attributes(&self) -> FragmentAttributes;
fn use_uniforms(
&self,
program: &Program,
camera: &Camera,
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.
Required Methods§
sourcefn fragment_shader_source(&self, lights: &[&dyn Light]) -> String
fn fragment_shader_source(&self, lights: &[&dyn Light]) -> String
Returns the fragment shader source for this material.
sourcefn id(&self) -> u16
fn id(&self) -> u16
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 that is smaller than 0b1u16 << 15
.
sourcefn fragment_attributes(&self) -> FragmentAttributes
fn fragment_attributes(&self) -> FragmentAttributes
Returns a FragmentAttributes struct that describes which fragment attributes, ie. the input from the vertex shader, are required for rendering with this material.
sourcefn use_uniforms(
&self,
program: &Program,
camera: &Camera,
lights: &[&dyn Light]
)
fn use_uniforms( &self, program: &Program, camera: &Camera, lights: &[&dyn Light] )
Sends the uniform data needed for this material to the fragment shader.
sourcefn render_states(&self) -> RenderStates
fn render_states(&self) -> RenderStates
Returns the render states needed to render with this material.
sourcefn material_type(&self) -> MaterialType
fn material_type(&self) -> MaterialType
Returns the type of material.