Skip to content

Commit

Permalink
seperate const generic vector types and hardcoded, we should profile …
Browse files Browse the repository at this point in the history
…them later
  • Loading branch information
float3 committed Apr 11, 2024
1 parent 24c736e commit 249d5a0
Show file tree
Hide file tree
Showing 31 changed files with 632 additions and 273 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ version = "0.1.0"
edition = "2021"

[features]
default = ["oidn"]
default = ["oidn", "vector_constgenerics"]
small_rng = ["rand/small_rng"]
oidn = ["dep:oidn", "dep:flate2", "dep:tar", "dep:zip"]
vector_constgenerics = []

[dependencies]
cfg-if = "1.0.0"
Expand Down
17 changes: 1 addition & 16 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,12 @@ mod oidn {
env::var("OIDN_VER").expect("OIDN_VER environment variable not set. Please set this to the OIDN version you want to install.")
}

pub fn get_current_oidn_version() -> String {
let oidn_dir = get_oidn_dir();
let version_file = Path::new(&oidn_dir)
.parent()
.expect("OIDN directory has no parent")
.join("version");

let mut current_version = String::new();
if version_file.exists() {
current_version =
std::fs::read_to_string(&version_file).expect("Failed to read version file");
}
current_version
}

pub(crate) async fn setup_oidn_environment() {
let oidn_dir = get_oidn_dir();
let oidn_dir = Path::new(&oidn_dir);

if oidn_dir.exists() {
std::fs::remove_dir_all(oidn_dir).expect("Failed to delete OIDN directory");
return;
}

extract_oidn(oidn_dir)
Expand Down
Binary file modified renders/checkered_floor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified renders/cornell_box.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified renders/mirror_ball.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified renders/red_ball.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified renders/scene.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion scenes/mirror_ball.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ material = "checkered"
[[lights]]
type = "point"
position = [0.0, 5.0, 0.0]
color = [5.0, 5.0, 5.0]
color = [10.0, 10.0, 10.0]

[camera]
position = [0.0, 0.5, 3.0]
Expand Down
30 changes: 15 additions & 15 deletions src/camera/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,31 @@ use rand::Rng;

use crate::{
ray::Ray,
scene::{FloatSize, RNGType},
utils::{matrix::Matrix, vector::Vec3},
scene::{Flooat, RNGType},
utils::{matrix::Float3x3, vector::Float3},
};

#[derive(Debug)]
pub struct Camera {
pub position: Vec3<FloatSize>,
pub rotation: Vec3<FloatSize>,
pub position: Float3,
pub rotation: Float3,
}

impl Camera {
pub fn get_ray(
&self,
x: FloatSize,
y: FloatSize,
width: FloatSize,
height: FloatSize,
x: Flooat,
y: Flooat,
width: Flooat,
height: Flooat,
rand_state: &mut RNGType,
) -> Ray {
let x = x + rand_state.gen_range(0.0..1.0) as FloatSize;
let y = y + rand_state.gen_range(0.0..1.0) as FloatSize;
let x = x + rand_state.gen_range(0.0..1.0) as Flooat;
let y = y + rand_state.gen_range(0.0..1.0) as Flooat;

let x0 = (x / width) * 2.0 - 1.0;
let y0 = (y / height) * 2.0 - 1.0;
let mut direction = Vec3::new([x0 * width / height, -y0, -1.0]);
let mut direction = Float3::new([x0 * width / height, -y0, -1.0]);

let rotation_matrix = self.get_rotation_matrix();

Expand All @@ -38,22 +38,22 @@ impl Camera {
}
}

fn get_rotation_matrix(&self) -> Matrix<FloatSize, 3, 3> {
fn get_rotation_matrix(&self) -> Float3x3 {
let yaw = self.rotation.x().to_radians();
let pitch = self.rotation.y().to_radians();
let roll = self.rotation.z().to_radians();

let rotation_z = Matrix::new([
let rotation_z = Float3x3::new([
[yaw.cos(), -yaw.sin(), 0.0],
[yaw.sin(), yaw.cos(), 0.0],
[0.0, 0.0, 1.0],
]);
let rotation_y = Matrix::new([
let rotation_y = Float3x3::new([
[pitch.cos(), 0.0, pitch.sin()],
[0.0, 1.0, 0.0],
[-pitch.sin(), 0.0, pitch.cos()],
]);
let rotation_x = Matrix::new([
let rotation_x = Float3x3::new([
[1.0, 0.0, 0.0],
[0.0, roll.cos(), -roll.sin()],
[0.0, roll.sin(), roll.cos()],
Expand Down
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![feature(generic_const_exprs)]
pub mod camera;
pub mod light;
pub mod material;
Expand Down
10 changes: 5 additions & 5 deletions src/light/arealight.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
use crate::{scene::FloatSize, utils::vector::Vec3};
use crate::{scene::Flooat, utils::vector::Float3};

use super::Light;

#[derive(Debug, Clone)]
pub struct Arealight {}

impl Light for Arealight {
fn illuminate(&self) -> Vec3<FloatSize> {
fn illuminate(&self) -> Float3 {
todo!()
}

fn position(&self) -> Vec3<FloatSize> {
fn position(&self) -> Float3 {
todo!()
}

fn intensity(&self) -> FloatSize {
fn intensity(&self) -> Flooat {
todo!()
}

fn color(&self) -> Vec3<FloatSize> {
fn color(&self) -> Float3 {
todo!()
}
}
10 changes: 5 additions & 5 deletions src/light/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::str::FromStr;

use crate::{scene::FloatSize, utils::vector::Vec3};
use crate::{scene::Flooat, utils::vector::Float3};

pub mod arealight;
pub mod pointlight;
Expand All @@ -25,9 +25,9 @@ impl FromStr for LightType {
}

pub trait Light: Sync + std::fmt::Debug {
fn position(&self) -> Vec3<FloatSize>;
fn illuminate(&self) -> Vec3<FloatSize>;
fn intensity(&self) -> FloatSize;
fn color(&self) -> Vec3<FloatSize>;
fn position(&self) -> Float3;
fn illuminate(&self) -> Float3;
fn intensity(&self) -> Flooat;
fn color(&self) -> Float3;
// fn clone_box(&self) -> Box<dyn Light>;
}
16 changes: 8 additions & 8 deletions src/light/pointlight.rs
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
use crate::{scene::FloatSize, utils::vector::Vec3};
use crate::{scene::Flooat, utils::vector::Float3};

use super::Light;
#[derive(Debug, Clone, Copy)]
pub struct PointLight {
position: Vec3<FloatSize>,
color: Vec3<FloatSize>,
position: Float3,
color: Float3,
}

impl PointLight {
pub fn new(position: Vec3<FloatSize>, color: Vec3<FloatSize>) -> Self {
pub fn new(position: Float3, color: Float3) -> Self {
PointLight { position, color }
}
}

impl Light for PointLight {
fn illuminate(&self) -> Vec3<FloatSize> {
fn illuminate(&self) -> Float3 {
self.color
}

fn position(&self) -> Vec3<FloatSize> {
fn position(&self) -> Float3 {
self.position
}

fn intensity(&self) -> FloatSize {
fn intensity(&self) -> Flooat {
self.color.length()
}

fn color(&self) -> Vec3<FloatSize> {
fn color(&self) -> Float3 {
self.color
}
}
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use pathtracer::{
pathtracer::PathTracer,
scene::{FloatSize, Scene},
scene::{Flooat, Scene},
utils::vector::Vector,
};

Expand Down Expand Up @@ -68,7 +68,7 @@ fn trace_scene_file(scene_file: &str, output_file: &str, pathtracer: &PathTracer
let modbuffer = &buffer
.iter()
.flat_map(|color| {
let color = color.scale(255.0 as FloatSize);
let color = color.scale(255.0 as Flooat);
vec![(color.0[0]) as u8, (color.0[1]) as u8, (color.0[2]) as u8]
})
.collect::<Vec<u8>>();
Expand Down
Loading

0 comments on commit 249d5a0

Please sign in to comment.