use crate::context::WgpuContext;
use crate::renderer::light::Light;
use crate::renderer::viewer::Viewer;
use glam::Mat4;
pub trait Material {
fn pipeline(&self) -> &wgpu::RenderPipeline;
fn camera_bind_group(&self) -> &wgpu::BindGroup;
fn model_bind_group(&self) -> &wgpu::BindGroup;
fn update_uniforms(
&self,
ctx: &WgpuContext,
viewer: &dyn Viewer,
model_matrix: Mat4,
lights: &[&dyn Light],
);
}
#[repr(C)]
#[derive(Copy, Clone, Debug, bytemuck::Pod, bytemuck::Zeroable)]
pub struct ModelUniform {
pub model: [[f32; 4]; 4],
pub normal_matrix: [[f32; 4]; 4],
}
impl ModelUniform {
pub fn from_matrix(model: Mat4) -> Self {
let normal_matrix = model.inverse().transpose();
Self {
model: model.to_cols_array_2d(),
normal_matrix: normal_matrix.to_cols_array_2d(),
}
}
}