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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
use crate::prelude::*;
pub struct Value {}
impl Noise for Value {
fn new() -> Self {
Self {
}
}
fn get_2d(&self, p: (FP, FP)) -> FP {
let x = FP2::new(p.0, p.1);
let i = glm::floor(&x);
let f = glm::fract(&x);
let a = self.hash2d(i);
let b = self.hash2d(i + FP2::new(1.0, 0.0));
let c = self.hash2d(i + FP2::new(0.0, 1.0));
let d = self.hash2d(i + FP2::new(1.0, 1.0));
let u = FP2::new( f.x * f.x * (3.0 - 2.0 * f.x), f.y * f.y * (3.0 - 2.0 * f.y));
self.mix(&a, &b, &u.x) + (c - a) * u.y * (1.0 - u.x) + (d - b) * u.x * u.y
}
fn fbm_2d(&self, p: (FP, FP), octaves: i32) -> FP {
let mut x = FP2::new(p.0, p.1);
let mut v = 0.0;
let mut a = 0.5;
let shift = FP2::new(100.0, 100.0);
let rot = Matrix2::new(0.87758256189, 0.4794255386, -0.4794255386, 0.87758256189);
for _i in 0..octaves {
v += a * self.get_2d((x.x, x.y));
x = rot * x * 2.0 + shift;
a *= 0.5;
}
v
}
}