feat(raytracer): add minimal phong lighting demo

This commit is contained in:
2024-11-17 23:50:05 +01:00
parent e8a2b0f059
commit b458b99c82
11 changed files with 1192 additions and 51 deletions

View File

@@ -2,12 +2,27 @@ use super::types::{Intersect, Material, Point3, Ray, Scalar, Vector3};
extern crate nalgebra as na;
/// A sphere in 3D space
pub struct Sphere {
/// Center of the sphere
center: Point3,
/// Radius of the sphere
radius: Scalar,
/// PHONG material of the sphere
material: Material,
}
impl Sphere {
/// Create a new sphere at `center` with `radius` and `material`.
pub fn new(center: Point3, radius: Scalar, material: Material) -> Sphere {
Sphere {
center,
radius,
material,
}
}
}
/// Numerical error tolerance
const EPSILON: Scalar = 1e-5;
@@ -35,6 +50,7 @@ impl Intersect for Sphere {
if t < Scalar::MAX {
let isect_pt: Point3 = ray.origin + ray.direction * t;
return Some((
isect_pt,
(isect_pt - self.center) / self.radius,