Skip to content

Commit

Permalink
New Texture implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Red-Rapious committed Sep 11, 2023
1 parent b92da1c commit b4560fe
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
1 change: 0 additions & 1 deletion app/src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use lib_ray_tracer::{
camera::{self, Camera},
geometry::Sphere,
material::Material,
texture::CheckerTexture,
world::World,
Renderer,
};
Expand Down
29 changes: 27 additions & 2 deletions src/texture.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,31 @@
use nalgebra::{Point3, Vector3};

pub trait Texture {
#[derive(Clone, Copy)]
pub enum Texture {
SolidColor(Vector3<f64>),
CheckerTexture(f64, &'static Texture, &'static Texture),
}

impl Texture {
pub fn value(&self, u: f64, v: f64, p: Point3<f64>) -> Vector3<f64> {
match *self {
Self::SolidColor(color) => color,
Self::CheckerTexture(inv_scale, color_even, color_odd) => {
let x_int = (inv_scale * p.x) as usize;
let y_int = (inv_scale * p.y) as usize;
let z_int = (inv_scale * p.z) as usize;

if (x_int + y_int + z_int % 2) == 0 {
color_even.value(u, v, p)
} else {
color_odd.value(u, v, p)
}
}
}
}
}

/*pub trait Texture {
fn value(&self, u: f64, v: f64, p: Point3<f64>) -> Vector3<f64>;
}
Expand Down Expand Up @@ -62,4 +87,4 @@ impl Texture for CheckerTexture {
self.odd.value(u, v, p)
}
}
}
}*/

0 comments on commit b4560fe

Please sign in to comment.