noises_and_patterns/noise/
value.rs

1use crate::prelude::*;
2
3// Based on https://www.shadertoy.com/view/4dS3Wd
4
5pub struct Value {}
6
7impl Noise for Value {
8
9    fn new() -> Self {
10        Self {
11
12        }
13    }
14
15    fn get_2d(&self, p: (FP, FP)) -> FP {
16        let x = FP2::new(p.0, p.1);
17        let i = glm::floor(&x);
18        let f = glm::fract(&x);
19
20	    let a = self.hash21(i);
21        let b = self.hash21(i + FP2::new(1.0, 0.0));
22        let c = self.hash21(i + FP2::new(0.0, 1.0));
23        let d = self.hash21(i + FP2::new(1.0, 1.0));
24
25        let u = FP2::new( f.x * f.x * (3.0 - 2.0 * f.x), f.y * f.y * (3.0 - 2.0 * f.y));
26
27        let xx = self.mix(&a, &b, &u.x);
28        let yy = self.mix(&c, &d, &u.x);
29
30        self.mix(&xx, &yy, &u.y)
31    }
32
33}