From 33a35c50c20e863123642c8c9ea31dfc006945f6 Mon Sep 17 00:00:00 2001 From: Julian T Date: Mon, 25 Jan 2021 14:43:46 +0100 Subject: Started work on implementing vectors bounding and film --- src/camera/film.rs | 51 ++++++++++++++++++++++++++++++++++++++++++++++++ src/camera/filter/mod.rs | 22 +++++++++++++++++++++ src/camera/mod.rs | 2 ++ 3 files changed, 75 insertions(+) create mode 100644 src/camera/film.rs create mode 100644 src/camera/filter/mod.rs create mode 100644 src/camera/mod.rs (limited to 'src/camera') diff --git a/src/camera/film.rs b/src/camera/film.rs new file mode 100644 index 0000000..c4a65ce --- /dev/null +++ b/src/camera/film.rs @@ -0,0 +1,51 @@ +use crate::vector::{Vector2, Vector2f}; +use crate::Float; +use crate::bounding::Bound2i; +use super::filter::Filter; + +#[derive(Clone)] +pub struct Pixel { + pub rgb: [Float; 3], +} + +pub struct Film<'a> { + pub resolution: Vector2, + + pixels: Vec, + filter: &'a dyn Filter, + filter_radius: Vector2f, +} + +pub struct FilmTile { + +} + +impl Pixel { + fn new() -> Pixel { + Pixel { rgb: [0.0, 0.0, 0.0] } + } +} + +impl Film<'_> { + fn new(resolution: Vector2, filter: & dyn Filter) -> Film { + let area = resolution.x * resolution.y; + Film { + resolution, + pixels: vec![Pixel::new(); area], + filter, + filter_radius: filter.radius() + } + } + + fn get_tile(bound: &Bound2i) { + // Used to calculate descrete coordinates into continues + let halfpixel = Vector2f::from_xy(0.5, 0.5); + } + + fn splat(&mut self, point: &Vector2, pixel: &Pixel) { + let index = point.x + point.y * self.resolution.x; + + self.pixels[index] = pixel.clone(); + } +} + diff --git a/src/camera/filter/mod.rs b/src/camera/filter/mod.rs new file mode 100644 index 0000000..93c6fc5 --- /dev/null +++ b/src/camera/filter/mod.rs @@ -0,0 +1,22 @@ +use crate::vector::Vector2f; +use crate::Float; + +pub trait Filter { + fn eval(&self, point: &Vector2f) -> Float; + fn radius(&self) -> Vector2f; +} + +pub struct BoxFilter { + radius: Vector2f, +} + +// The same a no filter, and can give aliasing in final image +impl Filter for BoxFilter { + fn eval(&self, _: &Vector2f) -> Float { + 1.0 + } + + fn radius(&self) -> Vector2f { + self.radius + } +} diff --git a/src/camera/mod.rs b/src/camera/mod.rs new file mode 100644 index 0000000..bba95f7 --- /dev/null +++ b/src/camera/mod.rs @@ -0,0 +1,2 @@ +mod film; +mod filter; -- cgit v1.2.3