diff --git a/src/lib.rs b/src/lib.rs index df375e9..926df41 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,6 +6,7 @@ use glam::{Mat4, UVec2, Vec3, vec3}; use crate::{ camera::OrbitalCamera, + ray::Ray, render::lines::{LookParams, Mesh, Pipeline, Vertex}, trace::{Scene, Source, Sphere}, }; @@ -189,36 +190,45 @@ impl Core { }; let mut prng = rand_pcg::Pcg64::new(42, 0); - let rays: Vec = (0..10000) - .flat_map(|_| { - let ray = source.make_ray(&mut prng); - if let Some(ray) = scene.trace_ray(ray) { - [ - Vertex { - pos: ray.base - 0.02 * ray.dir, - color: vec3(1., 1., 1.), - }, - Vertex { - pos: ray.base, - color: vec3(0., 1., 0.), - }, - ] - } else { - [ - Vertex { - pos: ray.base, - color: vec3(1., 1., 1.), - }, - Vertex { - pos: ray.base + 0.1 * ray.dir, - color: vec3(1., 0., 0.), - }, - ] - } - }) - .collect(); + let source_rays: Vec = (0..1024).map(|_| source.make_ray(&mut prng)).collect(); + let mut source_ray_display: Vec = Vec::with_capacity(source_rays.len()); + let mut hits: Vec = Vec::with_capacity(source_rays.len()); + for ray in source_rays { + if let Some(hit) = scene.trace_ray(ray) { + hits.push(hit); + source_ray_display.extend([ + Vertex { + pos: ray.base, + color: vec3(1., 1., 1.), + }, + Vertex { + pos: ray.base + 0.1 * ray.dir, + color: vec3(0., 1., 0.), + }, + Vertex { + pos: hit.base - 0.02 * hit.dir, + color: vec3(0., 0., 1.), + }, + Vertex { + pos: hit.base, + color: vec3(1., 1., 1.), + }, + ]); + } else { + source_ray_display.extend([ + Vertex { + pos: ray.base, + color: vec3(1., 1., 1.), + }, + Vertex { + pos: ray.base + 0.1 * ray.dir, + color: vec3(1., 0., 0.), + }, + ]); + } + } self.pipeline - .render(&mut pass, [&Mesh::new(&self.device, &rays)]); + .render(&mut pass, [&Mesh::new(&self.device, &source_ray_display)]); drop(pass); self.queue.submit(std::iter::once(encoder.finish()));