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::{
|
use crate::{
|
||||||
camera::OrbitalCamera,
|
camera::OrbitalCamera,
|
||||||
|
ray::Ray,
|
||||||
render::lines::{LookParams, Mesh, Pipeline, Vertex},
|
render::lines::{LookParams, Mesh, Pipeline, Vertex},
|
||||||
trace::{Scene, Source, Sphere},
|
trace::{Scene, Source, Sphere},
|
||||||
};
|
};
|
||||||
|
|
@ -189,36 +190,45 @@ impl Core {
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut prng = rand_pcg::Pcg64::new(42, 0);
|
let mut prng = rand_pcg::Pcg64::new(42, 0);
|
||||||
let rays: Vec<Vertex> = (0..10000)
|
let source_rays: Vec<Ray> = (0..1024).map(|_| source.make_ray(&mut prng)).collect();
|
||||||
.flat_map(|_| {
|
let mut source_ray_display: Vec<Vertex> = Vec::with_capacity(source_rays.len());
|
||||||
let ray = source.make_ray(&mut prng);
|
let mut hits: Vec<Ray> = Vec::with_capacity(source_rays.len());
|
||||||
if let Some(ray) = scene.trace_ray(ray) {
|
for ray in source_rays {
|
||||||
[
|
if let Some(hit) = scene.trace_ray(ray) {
|
||||||
Vertex {
|
hits.push(hit);
|
||||||
pos: ray.base - 0.02 * ray.dir,
|
source_ray_display.extend([
|
||||||
color: vec3(1., 1., 1.),
|
Vertex {
|
||||||
},
|
pos: ray.base,
|
||||||
Vertex {
|
color: vec3(1., 1., 1.),
|
||||||
pos: ray.base,
|
},
|
||||||
color: vec3(0., 1., 0.),
|
Vertex {
|
||||||
},
|
pos: ray.base + 0.1 * ray.dir,
|
||||||
]
|
color: vec3(0., 1., 0.),
|
||||||
} else {
|
},
|
||||||
[
|
Vertex {
|
||||||
Vertex {
|
pos: hit.base - 0.02 * hit.dir,
|
||||||
pos: ray.base,
|
color: vec3(0., 0., 1.),
|
||||||
color: vec3(1., 1., 1.),
|
},
|
||||||
},
|
Vertex {
|
||||||
Vertex {
|
pos: hit.base,
|
||||||
pos: ray.base + 0.1 * ray.dir,
|
color: vec3(1., 1., 1.),
|
||||||
color: vec3(1., 0., 0.),
|
},
|
||||||
},
|
]);
|
||||||
]
|
} else {
|
||||||
}
|
source_ray_display.extend([
|
||||||
})
|
Vertex {
|
||||||
.collect();
|
pos: ray.base,
|
||||||
|
color: vec3(1., 1., 1.),
|
||||||
|
},
|
||||||
|
Vertex {
|
||||||
|
pos: ray.base + 0.1 * ray.dir,
|
||||||
|
color: vec3(1., 0., 0.),
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
self.pipeline
|
self.pipeline
|
||||||
.render(&mut pass, [&Mesh::new(&self.device, &rays)]);
|
.render(&mut pass, [&Mesh::new(&self.device, &source_ray_display)]);
|
||||||
|
|
||||||
drop(pass);
|
drop(pass);
|
||||||
self.queue.submit(std::iter::once(encoder.finish()));
|
self.queue.submit(std::iter::once(encoder.finish()));
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user