lighting, blinn-phong
This commit is contained in:
parent
b741202111
commit
89789d5f4a
7 changed files with 420 additions and 103 deletions
|
@ -66,6 +66,7 @@ pub trait DrawModel<'a> {
|
|||
mesh: &'a Mesh,
|
||||
material: &'a Material,
|
||||
camera_bind_group: &'a wgpu::BindGroup,
|
||||
light_bind_group: &'a wgpu::BindGroup,
|
||||
);
|
||||
fn draw_mesh_instanced(
|
||||
&mut self,
|
||||
|
@ -73,13 +74,21 @@ pub trait DrawModel<'a> {
|
|||
material: &'a Material,
|
||||
instances: Range<u32>,
|
||||
camera_bind_group: &'a wgpu::BindGroup,
|
||||
light_bind_group: &'a wgpu::BindGroup,
|
||||
);
|
||||
|
||||
fn draw_model(
|
||||
&mut self,
|
||||
model: &'a Model,
|
||||
camera_bind_group: &'a wgpu::BindGroup,
|
||||
light_bind_group: &'a wgpu::BindGroup,
|
||||
);
|
||||
fn draw_model(&mut self, model: &'a Model, camera_bind_group: &'a wgpu::BindGroup);
|
||||
fn draw_model_instanced(
|
||||
&mut self,
|
||||
model: &'a Model,
|
||||
instances: Range<u32>,
|
||||
camera_bind_group: &'a wgpu::BindGroup,
|
||||
light_bind_group: &'a wgpu::BindGroup,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -92,8 +101,9 @@ where
|
|||
mesh: &'b Mesh,
|
||||
material: &'b Material,
|
||||
camera_bind_group: &'b wgpu::BindGroup,
|
||||
light_bind_group: &'b wgpu::BindGroup,
|
||||
) {
|
||||
self.draw_mesh_instanced(mesh, material, 0..1, camera_bind_group);
|
||||
self.draw_mesh_instanced(mesh, material, 0..1, camera_bind_group, light_bind_group);
|
||||
}
|
||||
|
||||
fn draw_mesh_instanced(
|
||||
|
@ -102,16 +112,23 @@ where
|
|||
material: &'b Material,
|
||||
instances: Range<u32>,
|
||||
camera_bind_group: &'b wgpu::BindGroup,
|
||||
light_bind_group: &'b wgpu::BindGroup,
|
||||
) {
|
||||
self.set_vertex_buffer(0, mesh.vertex_buffer.slice(..));
|
||||
self.set_index_buffer(mesh.index_buffer.slice(..), wgpu::IndexFormat::Uint32);
|
||||
self.set_bind_group(0, &material.bind_group, &[]);
|
||||
self.set_bind_group(1, camera_bind_group, &[]);
|
||||
self.set_bind_group(2, light_bind_group, &[]);
|
||||
self.draw_indexed(0..mesh.num_elements, 0, instances);
|
||||
}
|
||||
|
||||
fn draw_model(&mut self, model: &'b Model, camera_bind_group: &'b wgpu::BindGroup) {
|
||||
self.draw_model_instanced(model, 0..1, camera_bind_group);
|
||||
fn draw_model(
|
||||
&mut self,
|
||||
model: &'b Model,
|
||||
camera_bind_group: &'b wgpu::BindGroup,
|
||||
light_bind_group: &'b wgpu::BindGroup,
|
||||
) {
|
||||
self.draw_model_instanced(model, 0..1, camera_bind_group, light_bind_group);
|
||||
}
|
||||
|
||||
fn draw_model_instanced(
|
||||
|
@ -119,10 +136,17 @@ where
|
|||
model: &'b Model,
|
||||
instances: Range<u32>,
|
||||
camera_bind_group: &'b wgpu::BindGroup,
|
||||
light_bind_group: &'b wgpu::BindGroup,
|
||||
) {
|
||||
for mesh in &model.meshes {
|
||||
let material = &model.materials[mesh.material];
|
||||
self.draw_mesh_instanced(mesh, material, instances.clone(), camera_bind_group);
|
||||
self.draw_mesh_instanced(
|
||||
mesh,
|
||||
material,
|
||||
instances.clone(),
|
||||
camera_bind_group,
|
||||
light_bind_group,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue