|
|
|
@ -282,38 +282,38 @@ pub trait DrawModel<'a> {
|
|
|
|
|
&mut self,
|
|
|
|
|
mesh: &'a Mesh,
|
|
|
|
|
material: &'a Material,
|
|
|
|
|
camera: &'a wgpu::BindGroup,
|
|
|
|
|
light: &'a wgpu::BindGroup,
|
|
|
|
|
camera_bind_group: &'a wgpu::BindGroup,
|
|
|
|
|
light_bind_group: &'a wgpu::BindGroup,
|
|
|
|
|
);
|
|
|
|
|
fn draw_mesh_instanced(
|
|
|
|
|
&mut self,
|
|
|
|
|
mesh: &'a Mesh,
|
|
|
|
|
material: &'a Material,
|
|
|
|
|
instances: Range<u32>,
|
|
|
|
|
camera: &'a wgpu::BindGroup,
|
|
|
|
|
light: &'a wgpu::BindGroup,
|
|
|
|
|
camera_bind_group: &'a wgpu::BindGroup,
|
|
|
|
|
light_bind_group: &'a wgpu::BindGroup,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
fn draw_model(
|
|
|
|
|
&mut self,
|
|
|
|
|
model: &'a Model,
|
|
|
|
|
camera: &'a wgpu::BindGroup,
|
|
|
|
|
light: &'a wgpu::BindGroup,
|
|
|
|
|
camera_bind_group: &'a wgpu::BindGroup,
|
|
|
|
|
light_bind_group: &'a wgpu::BindGroup,
|
|
|
|
|
);
|
|
|
|
|
fn draw_model_instanced(
|
|
|
|
|
&mut self,
|
|
|
|
|
model: &'a Model,
|
|
|
|
|
instances: Range<u32>,
|
|
|
|
|
camera: &'a wgpu::BindGroup,
|
|
|
|
|
light: &'a wgpu::BindGroup,
|
|
|
|
|
camera_bind_group: &'a wgpu::BindGroup,
|
|
|
|
|
light_bind_group: &'a wgpu::BindGroup,
|
|
|
|
|
);
|
|
|
|
|
fn draw_model_instanced_with_material(
|
|
|
|
|
&mut self,
|
|
|
|
|
model: &'a Model,
|
|
|
|
|
material: &'a Material,
|
|
|
|
|
instances: Range<u32>,
|
|
|
|
|
camera: &'a wgpu::BindGroup,
|
|
|
|
|
light: &'a wgpu::BindGroup,
|
|
|
|
|
camera_bind_group: &'a wgpu::BindGroup,
|
|
|
|
|
light_bind_group: &'a wgpu::BindGroup,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -325,10 +325,10 @@ where
|
|
|
|
|
&mut self,
|
|
|
|
|
mesh: &'b Mesh,
|
|
|
|
|
material: &'b Material,
|
|
|
|
|
camera: &'b wgpu::BindGroup,
|
|
|
|
|
light: &'b wgpu::BindGroup,
|
|
|
|
|
camera_bind_group: &'b wgpu::BindGroup,
|
|
|
|
|
light_bind_group: &'b wgpu::BindGroup,
|
|
|
|
|
) {
|
|
|
|
|
self.draw_mesh_instanced(mesh, material, 0..1, camera, light);
|
|
|
|
|
self.draw_mesh_instanced(mesh, material, 0..1, camera_bind_group, light_bind_group);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn draw_mesh_instanced(
|
|
|
|
@ -336,36 +336,36 @@ where
|
|
|
|
|
mesh: &'b Mesh,
|
|
|
|
|
material: &'b Material,
|
|
|
|
|
instances: Range<u32>,
|
|
|
|
|
camera: &'b wgpu::BindGroup,
|
|
|
|
|
light: &'b wgpu::BindGroup,
|
|
|
|
|
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, &[]);
|
|
|
|
|
self.set_bind_group(2, light, &[]);
|
|
|
|
|
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: &'b wgpu::BindGroup,
|
|
|
|
|
light: &'b wgpu::BindGroup,
|
|
|
|
|
camera_bind_group: &'b wgpu::BindGroup,
|
|
|
|
|
light_bind_group: &'b wgpu::BindGroup,
|
|
|
|
|
) {
|
|
|
|
|
self.draw_model_instanced(model, 0..1, camera, light);
|
|
|
|
|
self.draw_model_instanced(model, 0..1, camera_bind_group, light_bind_group);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn draw_model_instanced(
|
|
|
|
|
&mut self,
|
|
|
|
|
model: &'b Model,
|
|
|
|
|
instances: Range<u32>,
|
|
|
|
|
camera: &'b wgpu::BindGroup,
|
|
|
|
|
light: &'b wgpu::BindGroup,
|
|
|
|
|
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, light);
|
|
|
|
|
self.draw_mesh_instanced(mesh, material, instances.clone(), camera_bind_group, light_bind_group);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -374,11 +374,11 @@ where
|
|
|
|
|
model: &'b Model,
|
|
|
|
|
material: &'b Material,
|
|
|
|
|
instances: Range<u32>,
|
|
|
|
|
camera: &'b wgpu::BindGroup,
|
|
|
|
|
light: &'b wgpu::BindGroup,
|
|
|
|
|
camera_bind_group: &'b wgpu::BindGroup,
|
|
|
|
|
light_bind_group: &'b wgpu::BindGroup,
|
|
|
|
|
) {
|
|
|
|
|
for mesh in &model.meshes {
|
|
|
|
|
self.draw_mesh_instanced(mesh, material, instances.clone(), camera, light);
|
|
|
|
|
self.draw_mesh_instanced(mesh, material, instances.clone(), camera_bind_group, light_bind_group);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -387,29 +387,29 @@ pub trait DrawLight<'a> {
|
|
|
|
|
fn draw_light_mesh(
|
|
|
|
|
&mut self,
|
|
|
|
|
mesh: &'a Mesh,
|
|
|
|
|
camera: &'a wgpu::BindGroup,
|
|
|
|
|
light: &'a wgpu::BindGroup,
|
|
|
|
|
camera_bind_group: &'a wgpu::BindGroup,
|
|
|
|
|
light_bind_group: &'a wgpu::BindGroup,
|
|
|
|
|
);
|
|
|
|
|
fn draw_light_mesh_instanced(
|
|
|
|
|
&mut self,
|
|
|
|
|
mesh: &'a Mesh,
|
|
|
|
|
instances: Range<u32>,
|
|
|
|
|
camera: &'a wgpu::BindGroup,
|
|
|
|
|
light: &'a wgpu::BindGroup,
|
|
|
|
|
camera_bind_group: &'a wgpu::BindGroup,
|
|
|
|
|
light_bind_group: &'a wgpu::BindGroup,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
fn draw_light_model(
|
|
|
|
|
&mut self,
|
|
|
|
|
model: &'a Model,
|
|
|
|
|
camera: &'a wgpu::BindGroup,
|
|
|
|
|
light: &'a wgpu::BindGroup,
|
|
|
|
|
camera_bind_group: &'a wgpu::BindGroup,
|
|
|
|
|
light_bind_group: &'a wgpu::BindGroup,
|
|
|
|
|
);
|
|
|
|
|
fn draw_light_model_instanced(
|
|
|
|
|
&mut self,
|
|
|
|
|
model: &'a Model,
|
|
|
|
|
instances: Range<u32>,
|
|
|
|
|
camera: &'a wgpu::BindGroup,
|
|
|
|
|
light: &'a wgpu::BindGroup,
|
|
|
|
|
camera_bind_group: &'a wgpu::BindGroup,
|
|
|
|
|
light_bind_group: &'a wgpu::BindGroup,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -420,43 +420,43 @@ where
|
|
|
|
|
fn draw_light_mesh(
|
|
|
|
|
&mut self,
|
|
|
|
|
mesh: &'b Mesh,
|
|
|
|
|
camera: &'b wgpu::BindGroup,
|
|
|
|
|
light: &'b wgpu::BindGroup,
|
|
|
|
|
camera_bind_group: &'b wgpu::BindGroup,
|
|
|
|
|
light_bind_group: &'b wgpu::BindGroup,
|
|
|
|
|
) {
|
|
|
|
|
self.draw_light_mesh_instanced(mesh, 0..1, camera, light);
|
|
|
|
|
self.draw_light_mesh_instanced(mesh, 0..1, camera_bind_group, light_bind_group);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn draw_light_mesh_instanced(
|
|
|
|
|
&mut self,
|
|
|
|
|
mesh: &'b Mesh,
|
|
|
|
|
instances: Range<u32>,
|
|
|
|
|
camera: &'b wgpu::BindGroup,
|
|
|
|
|
light: &'b wgpu::BindGroup,
|
|
|
|
|
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, camera, &[]);
|
|
|
|
|
self.set_bind_group(1, light, &[]);
|
|
|
|
|
self.set_bind_group(0, camera_bind_group, &[]);
|
|
|
|
|
self.set_bind_group(1, light_bind_group, &[]);
|
|
|
|
|
self.draw_indexed(0..mesh.num_elements, 0, instances);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn draw_light_model(
|
|
|
|
|
&mut self,
|
|
|
|
|
model: &'b Model,
|
|
|
|
|
camera: &'b wgpu::BindGroup,
|
|
|
|
|
light: &'b wgpu::BindGroup,
|
|
|
|
|
camera_bind_group: &'b wgpu::BindGroup,
|
|
|
|
|
light_bind_group: &'b wgpu::BindGroup,
|
|
|
|
|
) {
|
|
|
|
|
self.draw_light_model_instanced(model, 0..1, camera, light);
|
|
|
|
|
self.draw_light_model_instanced(model, 0..1, camera_bind_group, light_bind_group);
|
|
|
|
|
}
|
|
|
|
|
fn draw_light_model_instanced(
|
|
|
|
|
&mut self,
|
|
|
|
|
model: &'b Model,
|
|
|
|
|
instances: Range<u32>,
|
|
|
|
|
camera: &'b wgpu::BindGroup,
|
|
|
|
|
light: &'b wgpu::BindGroup,
|
|
|
|
|
camera_bind_group: &'b wgpu::BindGroup,
|
|
|
|
|
light_bind_group: &'b wgpu::BindGroup,
|
|
|
|
|
) {
|
|
|
|
|
for mesh in &model.meshes {
|
|
|
|
|
self.draw_light_mesh_instanced(mesh, instances.clone(), camera, light);
|
|
|
|
|
self.draw_light_mesh_instanced(mesh, instances.clone(), camera_bind_group, light_bind_group);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|