use crate::core::*;
use crate::renderer::*;
#[derive(Default, Clone)]
pub struct DepthMaterial {
pub min_distance: Option<f32>,
pub max_distance: Option<f32>,
pub render_states: RenderStates,
}
impl FromCpuMaterial for DepthMaterial {
fn from_cpu_material(_context: &Context, _cpu_material: &CpuMaterial) -> Self {
Self::default()
}
}
impl Material for DepthMaterial {
fn id(&self) -> u16 {
0b1u16 << 15 | 0b10u16
}
fn fragment_shader_source(&self, _lights: &[&dyn Light]) -> String {
include_str!("shaders/depth_material.frag").to_string()
}
fn fragment_attributes(&self) -> FragmentAttributes {
FragmentAttributes {
position: true,
..FragmentAttributes::NONE
}
}
fn use_uniforms(&self, program: &Program, camera: &Camera, _lights: &[&dyn Light]) {
program.use_uniform(
"minDistance",
self.min_distance.unwrap_or_else(|| camera.z_near()),
);
program.use_uniform(
"maxDistance",
self.max_distance.unwrap_or_else(|| camera.z_far()),
);
program.use_uniform("eye", camera.position());
}
fn render_states(&self) -> RenderStates {
self.render_states
}
fn material_type(&self) -> MaterialType {
MaterialType::Opaque
}
}