wip: parallelization

This commit is contained in:
djaidjai committed 2026-05-03 14:58:56 +02:00
1 parent eb90c36ae8
commit 10f9c0984d
23 files changed
+294 -211

No files matched your search

+18 -3
View File
@@ -5,8 +5,8 @@ use serde::Deserialize;
use crate::{
objects::{
cube::Cube, materials::traits::Material, quad::Quad, sphere::Sphere, traits::Hittable,
triangle::Triangle,
circle::Circle, cube::Cube, materials::traits::Material, quad::Quad, sphere::Sphere,
traits::Hittable, triangle::Triangle,
},
scenes::material_def::MaterialDef,
vec3::Vec3,
@@ -19,11 +19,11 @@ pub(crate) enum HittableDef {
Triangle(RawTriangle),
Quad(RawQuad),
Cube(RawCube),
Circle(RawCircle),
}
impl HittableDef {
pub(crate) fn into_arc(self, materials: &Vec<Arc<dyn Material>>) -> Option<Arc<dyn Hittable>> {
// THOUGHT: i think this can be done better; in the map/filter call in scnene.deserialize?
match self {
HittableDef::Sphere(s) => {
let material = s.material.into_arc(materials);
@@ -55,6 +55,13 @@ impl HittableDef {
None => None,
}
}
HittableDef::Circle(c) => {
let material = c.material.into_arc(materials);
match material {
Some(m) => Some(Arc::new(Circle::new(c.radius, c.center, c.normal, m))),
None => None,
}
}
}
}
}
@@ -96,6 +103,14 @@ pub(crate) struct RawCube {
pub material: RawMaterial,
}
#[derive(Deserialize)]
pub(crate) struct RawCircle {
radius: f32,
center: Vec3,
normal: Vec3,
material: RawMaterial,
}
#[derive(Deserialize)]
#[serde(untagged)]
pub(crate) enum RawMaterial {
-12
View File
@@ -4,15 +4,9 @@ use crate::{camera::Camera, vec3::Vec3};
#[derive(Deserialize)]
pub struct RawCamera {
// output
image_width: u32,
image_height: u32,
// raytracing
#[serde(default)]
anti_alias_rate: u32,
#[serde(default)]
max_depth: u32,
// camera
#[serde(default)]
@@ -32,10 +26,7 @@ pub struct RawCamera {
impl Default for RawCamera {
fn default() -> Self {
Self {
image_width: 400,
image_height: 300,
anti_alias_rate: 1,
max_depth: 10,
fov: 70.,
look_from: Vec3::new(0., 0., 0.),
look_at: Vec3::new(0., 0., -1.),
@@ -49,10 +40,7 @@ impl Default for RawCamera {
impl From<RawCamera> for Camera {
fn from(raw: RawCamera) -> Self {
Camera::new_full(
raw.image_width,
raw.image_height,
raw.anti_alias_rate,
raw.max_depth,
raw.fov,
raw.look_from,
raw.look_at,
+31 -5
View File
@@ -10,14 +10,33 @@ use crate::{
#[derive(Debug)]
pub struct Scene {
pub camera: Camera,
pub _materials: Vec<Arc<dyn Material>>,
pub camera: Camera, // FIXME: should not be public
pub objects: Vec<Arc<dyn Hittable>>,
// image
pub filename: String,
pub image_width: u32,
pub image_height: u32,
// raytracing // TODO: think about organisation of these vars, also in Camera
pub max_depth: u32,
}
impl Scene {
pub fn render(&mut self) {
self.camera.render(&self.objects);
pub fn new(
camera: Camera,
objects: Vec<Arc<dyn Hittable>>,
filename: String,
image_width: u32,
image_height: u32,
max_depth: u32,
) -> Self {
Self {
camera,
objects,
filename,
image_width,
image_height,
max_depth,
}
}
}
@@ -26,6 +45,10 @@ struct SceneDef {
pub camera: RawCamera,
pub materials: Vec<MaterialDef>,
pub objects: Vec<HittableDef>,
pub filename: String,
pub image_width: u32,
pub image_height: u32,
pub max_depth: u32,
}
impl<'de> Deserialize<'de> for Scene {
@@ -46,8 +69,11 @@ impl<'de> Deserialize<'de> for Scene {
.collect();
Ok(Self {
camera: Camera::from(conc.camera),
_materials: mats,
objects: objs,
filename: conc.filename,
image_width: conc.image_width,
image_height: conc.image_height,
max_depth: conc.max_depth,
})
}
}
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.