diff --git a/pathtracer/src/material/mod.rs b/pathtracer/src/material/mod.rs index 699eac3..63ce29a 100644 --- a/pathtracer/src/material/mod.rs +++ b/pathtracer/src/material/mod.rs @@ -13,6 +13,7 @@ use serde::Deserialize; pub enum MaterialEnum { #[serde(rename = "uniform")] UniformMaterial, + TriangleMaterial, } /// Represent the physical light properties of an object in the scene; @@ -22,5 +23,8 @@ pub trait Material: std::fmt::Debug { fn properties(&self, point: Point2D) -> LightProperties; } +mod triangle; +pub use triangle::*; + mod uniform; pub use uniform::*; diff --git a/pathtracer/src/material/triangle.rs b/pathtracer/src/material/triangle.rs new file mode 100644 index 0000000..a9d8adf --- /dev/null +++ b/pathtracer/src/material/triangle.rs @@ -0,0 +1,31 @@ +use super::Material; +use crate::core::{LightProperties, LinearColor, ReflTransEnum}; +use crate::Point2D; +use serde::Deserialize; + +/// Represent a material which interpolates between three points. +#[derive(Debug, PartialEq, Deserialize)] +pub struct TriangleMaterial { + /// The diffuse components. + diffuse: [LinearColor; 3], + /// The specular components. + specular: [LinearColor; 3], + /// The transparency or reflectivity properties, this is not interpolated. + #[serde(flatten)] + pub refl_trans: Option, +} + +impl Material for TriangleMaterial { + fn properties(&self, point: Point2D) -> LightProperties { + let (u, v) = (point.x, point.y); + let diffuse = self.diffuse[0].clone() * (1. - u - v) + + self.diffuse[1].clone() * u + + self.diffuse[2].clone() * v; + let specular = self.specular[0].clone() * (1. - u - v) + + self.specular[1].clone() * u + + self.specular[2].clone() * v; + LightProperties::new(diffuse, specular, self.refl_trans.clone()) + } +} + +// FIXME: tests diff --git a/pathtracer/src/render/mesh.rs b/pathtracer/src/render/mesh.rs new file mode 100644 index 0000000..1c79b05 --- /dev/null +++ b/pathtracer/src/render/mesh.rs @@ -0,0 +1,8 @@ +use super::Object; + +/// Represent a mesh of objects. +pub struct Mesh { + /// The shapes composing the mesh + #[allow(unused)] // FIXME: remove when used + shapes: Vec, +} diff --git a/pathtracer/src/render/mod.rs b/pathtracer/src/render/mod.rs index 46bdffa..6d969e6 100644 --- a/pathtracer/src/render/mod.rs +++ b/pathtracer/src/render/mod.rs @@ -3,6 +3,9 @@ pub mod light_aggregate; pub use light_aggregate::*; +mod mesh; +pub use mesh::*; + pub mod object; pub use object::*; diff --git a/pathtracer/src/shape/mesh.rs b/pathtracer/src/shape/mesh.rs new file mode 100644 index 0000000..6e1e789 --- /dev/null +++ b/pathtracer/src/shape/mesh.rs @@ -0,0 +1,9 @@ +use super::{InterpolatedTriangle, Shape, Triangle}; +use crate::material::{Material, TriangleMaterial, UniformMaterial}; +use crate::texture::{Texture, TriangleTexture, UniformTexture}; +use crate::Point; +use beevee::{ + aabb::{Bounded, AABB}, + bvh::Intersected, + ray::Ray, +}; diff --git a/pathtracer/src/texture/mod.rs b/pathtracer/src/texture/mod.rs index ca99154..c432fde 100644 --- a/pathtracer/src/texture/mod.rs +++ b/pathtracer/src/texture/mod.rs @@ -13,6 +13,7 @@ use serde::Deserialize; pub enum TextureEnum { #[serde(rename = "uniform")] UniformTexture, + TriangleTexture, } /// Represent an object's texture. @@ -22,5 +23,8 @@ pub trait Texture: std::fmt::Debug { fn texel_color(&self, point: Point2D) -> LinearColor; } +mod triangle; +pub use triangle::*; + mod uniform; pub use uniform::*; diff --git a/pathtracer/src/texture/triangle.rs b/pathtracer/src/texture/triangle.rs new file mode 100644 index 0000000..947bc80 --- /dev/null +++ b/pathtracer/src/texture/triangle.rs @@ -0,0 +1,23 @@ +use super::{uniform::UniformTexture, Texture}; +use crate::core::LinearColor; +use crate::Point2D; +use serde::Deserialize; + +/// Represent a texture which interpolates between three points. +#[derive(Debug, PartialEq, Deserialize)] +pub struct TriangleTexture { + /// The texture at each point + textures: [UniformTexture; 3], +} + +impl Texture for TriangleTexture { + fn texel_color(&self, point: Point2D) -> LinearColor { + let (u, v) = (point.x, point.y); + let sum = self.textures[0].texel_color(point) * (1. - u - v) + + self.textures[1].texel_color(point) * u + + self.textures[2].texel_color(point) * v; + sum / 3. + } +} + +// FIXME: tests