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
use crate::{math::scale_shift, noise_fns::NoiseFn};
use core::marker::PhantomData;
pub struct Exponent<T, Source, const DIM: usize>
where
Source: NoiseFn<T, DIM>,
{
pub source: Source,
pub exponent: f64,
phantom: PhantomData<T>,
}
impl<T, Source, const DIM: usize> Exponent<T, Source, DIM>
where
Source: NoiseFn<T, DIM>,
{
pub fn new(source: Source) -> Self {
Self {
source,
exponent: 1.0,
phantom: PhantomData,
}
}
pub fn set_exponent(self, exponent: f64) -> Self {
Self { exponent, ..self }
}
}
impl<T, Source, const DIM: usize> NoiseFn<T, DIM> for Exponent<T, Source, DIM>
where
Source: NoiseFn<T, DIM>,
{
fn get(&self, point: [T; DIM]) -> f64 {
let mut value = self.source.get(point);
value = (value + 1.0) / 2.0;
value = value.abs();
value = value.powf(self.exponent);
scale_shift(value, 2.0)
}
}