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§
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) -> EffectMaterialId
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.
Sourcefn use_uniforms(
&self,
program: &Program,
viewer: &dyn Viewer,
lights: &[&dyn Light],
)
fn use_uniforms( &self, program: &Program, viewer: &dyn Viewer, 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.