-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e6d87e2
commit 9ae1e0c
Showing
10 changed files
with
103 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
pub mod camera; | ||
pub mod intersect; | ||
pub mod ray; | ||
pub mod scene; | ||
mod camera; | ||
mod material; | ||
mod primitive; | ||
mod ray; | ||
mod scene; | ||
|
||
pub use camera::Camera; | ||
pub use intersect::{Intersect, RayIntersection}; | ||
pub use material::Material; | ||
pub use primitive::{Primitive, RayIntersection}; | ||
pub use ray::Ray; | ||
pub use scene::Scene; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
use crate::core::{Ray, RayIntersection}; | ||
use palette::LinSrgb; | ||
use rand::rngs::ThreadRng; | ||
|
||
pub trait Material { | ||
fn scatter( | ||
&self, | ||
rng: &mut ThreadRng, | ||
ray: &Ray, | ||
intersection: &RayIntersection, | ||
) -> (Ray, LinSrgb<f64>); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,16 @@ | ||
use crate::core::Ray; | ||
use crate::core::{Material, Ray}; | ||
use nalgebra::{Point3, Vector3}; | ||
use std::ops::Range; | ||
use std::rc::Rc; | ||
|
||
pub struct RayIntersection { | ||
pub t: f64, | ||
pub pos: Point3<f64>, | ||
pub normal: Vector3<f64>, | ||
pub material: Rc<dyn Material>, | ||
} | ||
|
||
pub trait Intersect { | ||
fn intersect(&self, _ray: &Ray, _range: &Range<f64>) -> Option<RayIntersection> { | ||
pub trait Primitive { | ||
fn intersect(&self, _ray: &Ray, _range: &Range<f64>) -> Option<(f64, RayIntersection)> { | ||
None | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
pub mod config; | ||
pub mod core; | ||
pub mod shapes; | ||
pub mod materials; | ||
pub mod primitives; | ||
pub mod utils; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
mod lambertian; | ||
|
||
pub use lambertian::Lambertian; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
use crate::core::{Material, Ray, RayIntersection}; | ||
use crate::utils; | ||
use palette::LinSrgb; | ||
use rand::rngs::ThreadRng; | ||
|
||
pub struct Lambertian { | ||
albedo: LinSrgb<f64>, | ||
} | ||
|
||
impl Lambertian { | ||
pub fn new(albedo: LinSrgb<f64>) -> Self { | ||
Self { albedo } | ||
} | ||
} | ||
|
||
impl Material for Lambertian { | ||
fn scatter( | ||
&self, | ||
rng: &mut ThreadRng, | ||
_ray: &Ray, | ||
intersection: &RayIntersection, | ||
) -> (Ray, LinSrgb<f64>) { | ||
let dir = intersection.normal + utils::rand_unit_vec3(rng); | ||
let ray = Ray::new(intersection.pos, dir); | ||
(ray, self.albedo) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
pub mod sphere; | ||
mod sphere; | ||
|
||
pub use sphere::Sphere; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters