use mutable vectors, to collect into several at once
This commit is contained in:
parent
413839ccb8
commit
8bed95f872
68
src/lib.rs
68
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<Vertex> = (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<Ray> = (0..1024).map(|_| source.make_ray(&mut prng)).collect();
|
||||
let mut source_ray_display: Vec<Vertex> = Vec::with_capacity(source_rays.len());
|
||||
let mut hits: Vec<Ray> = 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()));
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user