34 lines
868 B
Rust
34 lines
868 B
Rust
use std::sync::Arc;
|
|
use crate::hittable::HitRecord;
|
|
use crate::{Color, Ray, Vec3};
|
|
use crate::texture::{SolidColor, Texture};
|
|
|
|
pub struct Isotropic {
|
|
pub albedo: Arc<dyn Texture>
|
|
}
|
|
|
|
impl Isotropic {
|
|
pub fn scatter(&self, ray: &Ray, hit_record: &HitRecord) -> Option<(Option<Ray>, Color)> {
|
|
Some((
|
|
Some(
|
|
Ray::new(
|
|
hit_record.point,
|
|
Vec3::random_in_unit_sphere(),
|
|
ray.time())),
|
|
self.albedo.value(hit_record.u, hit_record.v, &hit_record.point)
|
|
))
|
|
}
|
|
}
|
|
|
|
impl From<Color> for Isotropic {
|
|
fn from(albedo: Color) -> Self {
|
|
let texture = SolidColor::from(albedo);
|
|
Isotropic { albedo: Arc::new(texture) }
|
|
}
|
|
}
|
|
impl From<Arc<dyn Texture>> for Isotropic {
|
|
fn from(albedo: Arc<dyn Texture>) -> Self {
|
|
Isotropic { albedo }
|
|
}
|
|
}
|