aboutsummaryrefslogtreecommitdiff
path: root/src/texture/noise_texture.rs
blob: 7fe3cdba8cc3fc1155c74f2b6d2da4e8f4a11d7c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
use super::{perlin::Perlin, Texture};
use crate::{vec3::Color, vec3::Point3};

pub struct NoiseTexture {
    noise: Perlin,
    scale: f64,
}

impl NoiseTexture {
    pub fn new(scale: f64) -> Self {
        Self {
            noise: Perlin::new(),
            scale,
        }
    }
}

impl Texture for NoiseTexture {
    fn value(&self, _: f64, _: f64, p: &Point3) -> Color {
        Color {
            x: 1.0,
            y: 1.0,
            z: 1.0,
        } * 0.5
            * (1.0 + (self.scale * p.z + 10.0 * self.noise.turb(p, 7)).sin())
    }
}