|
|
|
@ -118,7 +118,7 @@ impl model::Vertex for InstanceRaw {
|
|
|
|
|
|
|
|
|
|
#[repr(C)]
|
|
|
|
|
#[derive(Debug, Copy, Clone, bytemuck::Pod, bytemuck::Zeroable)]
|
|
|
|
|
struct Light {
|
|
|
|
|
struct LightUniform {
|
|
|
|
|
position: [f32; 3],
|
|
|
|
|
// Due to uniforms requiring 16 byte (4 float) spacing, we need to use a padding field here
|
|
|
|
|
_padding: u32,
|
|
|
|
@ -144,7 +144,7 @@ struct State {
|
|
|
|
|
instance_buffer: wgpu::Buffer,
|
|
|
|
|
depth_texture: texture::Texture,
|
|
|
|
|
size: winit::dpi::PhysicalSize<u32>,
|
|
|
|
|
light: Light,
|
|
|
|
|
light_uniform: LightUniform,
|
|
|
|
|
light_buffer: wgpu::Buffer,
|
|
|
|
|
light_bind_group: wgpu::BindGroup,
|
|
|
|
|
light_render_pipeline: wgpu::RenderPipeline,
|
|
|
|
@ -374,7 +374,7 @@ impl State {
|
|
|
|
|
.unwrap();
|
|
|
|
|
println!("Elapsed (Original): {:?}", std::time::Instant::now() - now);
|
|
|
|
|
|
|
|
|
|
let light = Light {
|
|
|
|
|
let light_uniform = LightUniform {
|
|
|
|
|
position: [2.0, 2.0, 2.0],
|
|
|
|
|
_padding: 0,
|
|
|
|
|
color: [1.0, 1.0, 1.0],
|
|
|
|
@ -382,7 +382,7 @@ impl State {
|
|
|
|
|
|
|
|
|
|
let light_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
|
|
|
|
label: Some("Light VB"),
|
|
|
|
|
contents: bytemuck::cast_slice(&[light]),
|
|
|
|
|
contents: bytemuck::cast_slice(&[light_uniform]),
|
|
|
|
|
usage: wgpu::BufferUsage::UNIFORM | wgpu::BufferUsage::COPY_DST,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@ -509,7 +509,7 @@ impl State {
|
|
|
|
|
instance_buffer,
|
|
|
|
|
depth_texture,
|
|
|
|
|
size,
|
|
|
|
|
light,
|
|
|
|
|
light_uniform,
|
|
|
|
|
light_buffer,
|
|
|
|
|
light_bind_group,
|
|
|
|
|
light_render_pipeline,
|
|
|
|
@ -577,13 +577,16 @@ impl State {
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Update the light
|
|
|
|
|
let old_position: cgmath::Vector3<_> = self.light.position.into();
|
|
|
|
|
self.light.position =
|
|
|
|
|
let old_position: cgmath::Vector3<_> = self.light_uniform.position.into();
|
|
|
|
|
self.light_uniform.position =
|
|
|
|
|
(cgmath::Quaternion::from_axis_angle((0.0, 1.0, 0.0).into(), cgmath::Deg(1.0))
|
|
|
|
|
* old_position)
|
|
|
|
|
.into();
|
|
|
|
|
self.queue
|
|
|
|
|
.write_buffer(&self.light_buffer, 0, bytemuck::cast_slice(&[self.light]));
|
|
|
|
|
self.queue.write_buffer(
|
|
|
|
|
&self.light_buffer,
|
|
|
|
|
0,
|
|
|
|
|
bytemuck::cast_slice(&[self.light_uniform]),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn render(&mut self) -> Result<(), wgpu::SwapChainError> {
|
|
|
|
|