18 lines
402 B
Rust
18 lines
402 B
Rust
use serde::Deserialize;
|
|
|
|
use crate::{
|
|
objects::{hit::Hit, materials::traits::Material},
|
|
ray::Ray,
|
|
vec3::Vec3,
|
|
};
|
|
|
|
#[derive(Debug, Deserialize)]
|
|
pub struct Normal {}
|
|
|
|
impl Material for Normal {
|
|
fn scatter(&self, hit: &Hit, ray: &Ray) -> Option<(Ray, Vec3)> {
|
|
let refl = ray.dir().reflect(hit.n()).get_unit();
|
|
Some((Ray::new(*hit.p(), refl), (hit.n() + 1.) / 2.))
|
|
}
|
|
}
|