This commit is contained in:
numzero 2024-12-30 03:32:35 +03:00
parent 676fb20ad4
commit 12159dd0b5

View File

@ -41,6 +41,19 @@ struct SphereData {
glossiness: f32,
}
impl From<&Sphere> for SphereData {
fn from(s: &Sphere) -> Self {
SphereData {
center: s.center,
radius: s.radius,
emit_color: s.emit_color,
pad1: 0.0,
reflect_color: s.reflect_color,
glossiness: s.glossiness,
}
}
}
pub struct Tracer {
view_buf: wgpu::Buffer,
pipeline: wgpu::RenderPipeline,
@ -192,17 +205,7 @@ 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,
glossiness: s.glossiness,
})
.collect();
let spheres: Vec<_> = spheres.iter().map(SphereData::from).collect();
let spheres_buf = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
label: None,
contents: cast_slice(&spheres),