per-vertex lighting!

This commit is contained in:
numzero 2025-11-24 18:31:23 +03:00
parent 41579bbb5d
commit 59bc5b640f

View File

@ -249,26 +249,6 @@ impl Core {
sphere(vec3(0.1, 0.3, 0.1)), sphere(vec3(0.1, 0.3, 0.1)),
], ],
}; };
if args.show_shapes {
let mut meshes = Vec::new();
for obj in &scene.objects {
let mesh = shape::sphere((obj.radius * 15.) as usize + 7);
let obj_mesh = render::faces::Mesh::new(
&self.device,
&mesh
.vertices
.iter()
.map(|v| render::faces::Vertex {
pos: obj.position + obj.radius * v,
color: 0.5 * (v + 1.),
})
.collect::<Vec<_>>(),
bytemuck::cast_slice(&mesh.indices),
);
meshes.push(obj_mesh);
}
self.mesh_pipe.render(&mut pass, &meshes);
}
let mut prng = rand_pcg::Pcg64::new(42, 0); let mut prng = rand_pcg::Pcg64::new(42, 0);
let source_rays: Vec<Ray> = (0..10240).map(|_| source.make_ray(&mut prng)).collect(); let source_rays: Vec<Ray> = (0..10240).map(|_| source.make_ray(&mut prng)).collect();
@ -401,6 +381,33 @@ impl Core {
]); ]);
} }
} }
if args.show_shapes {
let mut meshes = Vec::new();
for obj in &scene.objects {
let mesh = shape::sphere((obj.radius * 45.) as usize + 7);
let obj_mesh = render::faces::Mesh::new(
&self.device,
&mesh
.vertices
.iter()
.map(|&v| {
let pos = obj.position + obj.radius * v;
let normal = v;
let dir = (pos - camera.position()).normalize();
let light = light_at(Hit {
incident: Ray::new(pos, dir),
normal,
});
let color = colormap(light);
render::faces::Vertex { pos, color }
})
.collect::<Vec<_>>(),
bytemuck::cast_slice(&mesh.indices),
);
meshes.push(obj_mesh);
}
self.mesh_pipe.render(&mut pass, &meshes);
}
if !source_ray_display.is_empty() { if !source_ray_display.is_empty() {
self.pipeline self.pipeline
.render(&mut pass, [&Mesh::new(&self.device, &source_ray_display)]); .render(&mut pass, [&Mesh::new(&self.device, &source_ray_display)]);