diff --git a/src/anim.rs b/src/anim.rs index 94f8840..56dbd58 100644 --- a/src/anim.rs +++ b/src/anim.rs @@ -59,9 +59,7 @@ impl SphereParams { center, radius, emit_color, - pad1: 0.0, reflect_color, - pad2: 0.0, } } } diff --git a/src/trace.rs b/src/trace.rs index a7ab316..be0d84f 100644 --- a/src/trace.rs +++ b/src/trace.rs @@ -12,15 +12,13 @@ pub struct Params { pub sphere_count: u32, } -#[derive(Debug, Clone, Copy, Pod, Zeroable)] +#[derive(Debug, Clone, Copy)] #[repr(C)] pub struct Sphere { pub center: Vec3, pub radius: f32, pub emit_color: Vec3, - pub pad1: f32, pub reflect_color: Vec3, - pub pad2: f32, } #[derive(Debug, Clone, Copy, Pod, Zeroable)] @@ -31,6 +29,17 @@ pub struct Vertex { pub screen: Vec2, } +#[derive(Debug, Clone, Copy, Pod, Zeroable)] +#[repr(C)] +struct SphereData { + center: Vec3, + radius: f32, + emit_color: Vec3, + pad1: f32, + reflect_color: Vec3, + pad2: f32, +} + pub struct Tracer { view_buf: wgpu::Buffer, params_buf: wgpu::Buffer, @@ -138,9 +147,20 @@ impl Tracer { impl TracerData { pub fn new(device: &wgpu::Device, tracer: &Tracer, spheres: &[Sphere]) -> Self { + let spheres: Vec<_> = spheres + .iter() + .map(|s| SphereData { + center: s.center, + radius: s.radius, + emit_color: s.emit_color, + pad1: 0.0, + reflect_color: s.reflect_color, + pad2: 0.0, + }) + .collect(); let spheres_buf = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: None, - contents: cast_slice(spheres), + contents: cast_slice(&spheres), usage: wgpu::BufferUsages::STORAGE, }); let bindings = device.create_bind_group(&wgpu::BindGroupDescriptor {