Skip to content

Commit

Permalink
rename flooat to float0
Browse files Browse the repository at this point in the history
  • Loading branch information
float3 committed May 11, 2024
1 parent 653a1dc commit c3d1c92
Show file tree
Hide file tree
Showing 18 changed files with 94 additions and 94 deletions.
14 changes: 7 additions & 7 deletions src/camera/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use rand::Rng;

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

Expand All @@ -15,14 +15,14 @@ pub struct Camera {
impl Camera {
pub fn get_ray(
&self,
x: Flooat,
y: Flooat,
width: Flooat,
height: Flooat,
x: Float0,
y: Float0,
width: Float0,
height: Float0,
rand_state: &mut RNGType,
) -> Ray {
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 x = x + rand_state.gen_range(0.0..1.0) as Float0;
let y = y + rand_state.gen_range(0.0..1.0) as Float0;

let x0 = (x / width) * 2.0 - 1.0;
let y0 = (y / height) * 2.0 - 1.0;
Expand Down
4 changes: 2 additions & 2 deletions src/light/arealight.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{scene::Flooat, utils::vector::Float3};
use crate::{scene::Float0, utils::vector::Float3};

use super::Light;

Expand All @@ -14,7 +14,7 @@ impl Light for Arealight {
todo!()
}

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

Expand Down
4 changes: 2 additions & 2 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::Flooat, utils::vector::Float3};
use crate::{scene::Float0, utils::vector::Float3};

pub mod arealight;
pub mod pointlight;
Expand All @@ -27,7 +27,7 @@ impl FromStr for LightType {
pub trait Light: Sync + std::fmt::Debug {
fn position(&self) -> Float3;
fn illuminate(&self) -> Float3;
fn intensity(&self) -> Flooat;
fn intensity(&self) -> Float0;
fn color(&self) -> Float3;
// fn clone_box(&self) -> Box<dyn Light>;
}
4 changes: 2 additions & 2 deletions src/light/pointlight.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{scene::Flooat, utils::vector::Float3};
use crate::{scene::Float0, utils::vector::Float3};

use super::Light;
#[derive(Debug, Clone, Copy)]
Expand All @@ -22,7 +22,7 @@ impl Light for PointLight {
self.position
}

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

Expand Down
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::{Flooat, Scene},
scene::{Float0, 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 Flooat);
let color = color.scale(255.0 as Float0);
vec![(color.0[0]) as u8, (color.0[1]) as u8, (color.0[2]) as u8]
})
.collect::<Vec<u8>>();
Expand Down
58 changes: 29 additions & 29 deletions src/material/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
object::HitRecord,
ray::Ray,
scene::{Flooat, RNGType, PI},
scene::{Float0, RNGType, PI},
utils::{
matrix::Float3x3,
vector::{Float2, Float3},
Expand All @@ -13,7 +13,7 @@ use rand::prelude::*;
#[derive(Debug)]
pub struct Material {
pub albedo: Float3,
pub reflectivity: Flooat,
pub reflectivity: Float0,
pub checkered: bool,
}

Expand All @@ -31,12 +31,12 @@ fn generate_coordinate_system(normal: &Float3) -> (Float3, Float3) {
}

#[allow(dead_code)]
fn random_unit_vector(rand_state: &mut RNGType) -> (Float3, Flooat) {
fn pdf() -> Flooat {
1.0 / (4.0 * PI as Flooat)
fn random_unit_vector(rand_state: &mut RNGType) -> (Float3, Float0) {
fn pdf() -> Float0 {
1.0 / (4.0 * PI as Float0)
}
let theta: Flooat = rand_state.gen_range(0.0..(PI as Flooat));
let phi: Flooat = rand_state.gen_range(0.0..(2.0 * PI as Flooat));
let theta: Float0 = rand_state.gen_range(0.0..(PI as Float0));
let phi: Float0 = rand_state.gen_range(0.0..(2.0 * PI as Float0));
(
Float3::new([
theta.sin() * phi.cos(),
Expand All @@ -54,15 +54,15 @@ pub enum SamplingFunctions {
}

#[allow(dead_code)]
fn cosine_weighted_sample_1(normal: &Float3, rand_state: &mut RNGType) -> (Float3, Flooat) {
fn pdf(cos_theta: Flooat) -> Flooat {
cos_theta / PI as Flooat
fn cosine_weighted_sample_1(normal: &Float3, rand_state: &mut RNGType) -> (Float3, Float0) {
fn pdf(cos_theta: Float0) -> Float0 {
cos_theta / PI as Float0
}
let (v, u) = generate_coordinate_system(normal);
let r1: Flooat = rand_state.gen_range(0.0..1.0);
let r2: Flooat = rand_state.gen_range(0.0..1.0);
let r1: Float0 = rand_state.gen_range(0.0..1.0);
let r2: Float0 = rand_state.gen_range(0.0..1.0);

let phi = 2.0 * PI as Flooat * r1;
let phi = 2.0 * PI as Float0 * r1;
let r = r2.sqrt();
let x = r * phi.cos();
let y = (1.0 - r2).sqrt(); // this is cos_theta
Expand All @@ -77,16 +77,16 @@ fn cosine_weighted_sample_1(normal: &Float3, rand_state: &mut RNGType) -> (Float
}

#[allow(dead_code)]
fn cosine_weighted_sample_2(normal: &Float3, rand_state: &mut RNGType) -> (Float3, Flooat) {
fn pdf(cos_theta: Flooat) -> Flooat {
cos_theta / PI as Flooat
fn cosine_weighted_sample_2(normal: &Float3, rand_state: &mut RNGType) -> (Float3, Float0) {
fn pdf(cos_theta: Float0) -> Float0 {
cos_theta / PI as Float0
}
let (v, u) = generate_coordinate_system(normal);
let r1: Flooat = rand_state.gen_range(0.0..1.0);
let r2: Flooat = rand_state.gen_range(0.0..1.0);
let r1: Float0 = rand_state.gen_range(0.0..1.0);
let r2: Float0 = rand_state.gen_range(0.0..1.0);
let cos_theta = r1.sqrt();
let sin_theta = (1.0 - cos_theta * cos_theta).sqrt();
let phi = r2 * 2.0 * PI as Flooat;
let phi = r2 * 2.0 * PI as Float0;

let local_sample = Float3::new([sin_theta * phi.cos(), cos_theta, sin_theta * phi.sin()]);
let transformation_matrix = Float3x3::new_from_columns([u.0, normal.0, v.0]);
Expand All @@ -102,7 +102,7 @@ impl Material {
hit_record: &HitRecord,
rand_state: &mut RNGType,
sampletype: &SamplingFunctions,
) -> (Ray, Flooat) {
) -> (Ray, Float0) {
let mut random = match sampletype {
SamplingFunctions::RandomUnitVector => random_unit_vector(rand_state),
SamplingFunctions::CosineWeightedSample1 => {
Expand Down Expand Up @@ -242,15 +242,15 @@ mod tests {
use super::*;

#[allow(dead_code)]
fn avg_cosine(samples: Vec<Float3>, normal: Float3) -> Flooat {
fn avg_cosine(samples: Vec<Float3>, normal: Float3) -> Float0 {
samples
.iter()
.map(|v| {
let cos_theta = v.dot(&normal) / (v.length() * normal.length());
cos_theta.max(0.0)
})
.sum::<Flooat>()
/ samples.len() as Flooat
.sum::<Float0>()
/ samples.len() as Float0
}

#[test]
Expand All @@ -261,9 +261,9 @@ mod tests {
.map(|_| cosine_weighted_sample_1(&normal, &mut rng).0)
.collect();

let average_cosine: Flooat =
samples.iter().map(|v| v.y()).sum::<Flooat>() / samples.len() as Flooat;
let expected_average_cosine: Flooat = 2.0 / PI as Flooat;
let average_cosine: Float0 =
samples.iter().map(|v| v.y()).sum::<Float0>() / samples.len() as Float0;
let expected_average_cosine: Float0 = 2.0 / PI as Float0;

assert!(
(average_cosine - expected_average_cosine).abs() < 0.05,
Expand All @@ -280,9 +280,9 @@ mod tests {
.map(|_| cosine_weighted_sample_2(&normal, &mut rng).0)
.collect();

let average_cosine: Flooat =
samples.iter().map(|v| v.y()).sum::<Flooat>() / samples.len() as Flooat;
let expected_average_cosine: Flooat = 2.0 / PI as Flooat;
let average_cosine: Float0 =
samples.iter().map(|v| v.y()).sum::<Float0>() / samples.len() as Float0;
let expected_average_cosine: Float0 = 2.0 / PI as Float0;

assert!(
(average_cosine - expected_average_cosine).abs() < 0.05,
Expand Down
4 changes: 2 additions & 2 deletions src/object/cube.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{material::Material, ray::Ray, scene::Flooat, utils::vector::Float3};
use crate::{material::Material, ray::Ray, scene::Float0, utils::vector::Float3};

use super::{HitRecord, Hittable};

Expand All @@ -16,7 +16,7 @@ impl Cube {
}

impl Hittable for Cube {
fn hit(&self, ray: &Ray, t_min: Flooat, t_max: Flooat) -> Option<HitRecord> {
fn hit(&self, ray: &Ray, t_min: Float0, t_max: Float0) -> Option<HitRecord> {
let mut t_min = t_min;
let mut t_max = t_max;
for i in 0..3 {
Expand Down
6 changes: 3 additions & 3 deletions src/object/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::str::FromStr;
use crate::{
material::Material,
ray::Ray,
scene::Flooat,
scene::Float0,
utils::vector::{Float2, Float3},
};

Expand Down Expand Up @@ -37,13 +37,13 @@ impl FromStr for ObjectType {
}

pub trait Hittable: Sync + std::fmt::Debug {
fn hit(&self, ray: &Ray, t_min: Flooat, t_max: Flooat) -> Option<HitRecord>;
fn hit(&self, ray: &Ray, t_min: Float0, t_max: Float0) -> Option<HitRecord>;
}
#[derive(Debug)]
pub struct HitRecord<'a> {
pub point: Float3,
pub normal: Float3,
pub t: Flooat,
pub t: Float0,
pub front_face: bool,
pub material: &'a Material,
pub uv: Option<Float2>,
Expand Down
4 changes: 2 additions & 2 deletions src/object/plane.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{material::Material, ray::Ray, scene::Flooat, utils::vector::Float3};
use crate::{material::Material, ray::Ray, scene::Float0, utils::vector::Float3};

use super::{HitRecord, Hittable};

Expand All @@ -20,7 +20,7 @@ impl Plane {
}

impl Hittable for Plane {
fn hit(&self, ray: &Ray, t_min: Flooat, t_max: Flooat) -> Option<HitRecord> {
fn hit(&self, ray: &Ray, t_min: Float0, t_max: Float0) -> Option<HitRecord> {
let denom = self.normal.dot(&ray.direction);
if denom.abs() > 1e-6 {
let v = self.point - ray.origin;
Expand Down
4 changes: 2 additions & 2 deletions src/object/quad.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
material::Material,
ray::Ray,
scene::Flooat,
scene::Float0,
utils::vector::{Float2, Float3},
};

Expand All @@ -19,7 +19,7 @@ pub struct Quad {
}

impl Hittable for Quad {
fn hit(&self, ray: &Ray, t_min: Flooat, t_max: Flooat) -> Option<HitRecord> {
fn hit(&self, ray: &Ray, t_min: Float0, t_max: Float0) -> Option<HitRecord> {
let normal = (self.b - self.a).cross(&(self.c - self.a)).normalize();
let denom = ray.direction.dot(&normal);

Expand Down
8 changes: 4 additions & 4 deletions src/object/sphere.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
use crate::{material::Material, ray::Ray, scene::Flooat, utils::vector::Float3};
use crate::{material::Material, ray::Ray, scene::Float0, utils::vector::Float3};

use super::{HitRecord, Hittable};

#[derive(Debug)]
pub struct Sphere {
center: Float3,
radius: Flooat,
radius: Float0,
material: Material,
}

impl Sphere {
pub fn new(center: Float3, radius: Flooat, material: Material) -> Self {
pub fn new(center: Float3, radius: Float0, material: Material) -> Self {
Sphere {
center,
radius,
Expand All @@ -20,7 +20,7 @@ impl Sphere {
}

impl Hittable for Sphere {
fn hit(&self, ray: &Ray, t_min: Flooat, t_max: Flooat) -> Option<HitRecord> {
fn hit(&self, ray: &Ray, t_min: Float0, t_max: Float0) -> Option<HitRecord> {
let oc = ray.origin - self.center;
let a = ray.direction.length_squared();
let half_b = oc.dot(&ray.direction);
Expand Down
6 changes: 3 additions & 3 deletions src/object/triangle_mesh.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{material::Material, scene::Flooat, utils::vector::Float3};
use crate::{material::Material, scene::Float0, utils::vector::Float3};

use super::{HitRecord, Hittable};

Expand All @@ -14,8 +14,8 @@ impl Hittable for TriangleMesh {
fn hit(
&self,
_ray: &crate::ray::Ray,
_arg: Flooat,
_closest_so_far: Flooat,
_arg: Float0,
_closest_so_far: Float0,
) -> Option<HitRecord> {
unimplemented!()
}
Expand Down
14 changes: 7 additions & 7 deletions src/pathtracer/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::material::SamplingFunctions;
use crate::scene::{Flooat, RNGType, Scene};
use crate::scene::{Float0, RNGType, Scene};
use crate::utils::vector::Float3;
use rayon::prelude::*;

Expand Down Expand Up @@ -34,10 +34,10 @@ impl PathTracer {

for _sample in 0..self.samples {
let ray = scene.camera.get_ray(
x as Flooat,
y as Flooat,
self.width as Flooat,
self.height as Flooat,
x as Float0,
y as Float0,
self.width as Float0,
self.height as Float0,
&mut rand_state,
);
let is_left = x < self.width / 2;
Expand All @@ -54,7 +54,7 @@ impl PathTracer {
color += scene.trace_ray(&ray, 10, &mut rand_state, &sample_type);
}

*pixel = color.scale(1.0 / self.samples as Flooat);
*pixel = color.scale(1.0 / self.samples as Float0);
});

#[cfg(feature = "oidn")]
Expand Down Expand Up @@ -86,7 +86,7 @@ fn denoise_image(width: usize, height: usize, buffer: &mut [Float3]) {
let start = i * 3;
let end = start + 3;
let slice = &input[start..end];
*pixel = Float3::new([slice[0] as Flooat, slice[1] as Flooat, slice[2] as Flooat]);
*pixel = Float3::new([slice[0] as Float0, slice[1] as Float0, slice[2] as Float0]);
}
}

Expand Down
Loading

0 comments on commit c3d1c92

Please sign in to comment.