Noise Modeler Library  0.1
Library for procedurally generating noise-based terrains and other content
 All Classes Files Functions Variables Enumerations Enumerator Groups Pages
glslsourceridgedmultifractal.hpp
1 #ifndef GLSLSOURCERIDGEDMULTIFRACTAL_HPP
2 #define GLSLSOURCERIDGEDMULTIFRACTAL_HPP
3 
4 constexpr const char * source_ridgedmultifractal = R"lobotomized(
5 
6 //depends on snoise
7 float ridgedmultifractal(vec2 pos, float octaves, float lacunarity, float h, float offset, float gain, float seed){
8 
9  //compute first octave
10  float signal = snoise(pos, seed);
11  signal = abs(signal);
12  signal = offset - signal;
13  signal *= signal;
14 
15  float result = signal;
16  float frequency = lacunarity;
17  float weight = 1;
18 
19  for(int i=1; weight>0.001f && i<octaves; ++i){ //TODO get rid of magic constant
20  weight = signal*gain;
21  weight = clamp(weight, 0, 1);
22  signal = snoise(pos*frequency, seed);
23  signal = abs(signal);
24  signal = offset - signal;
25  signal *= signal;
26  signal *= weight;
27 
28  float exponent = pow(pow(lacunarity, i), -h);
29  result += signal * exponent;
30  weight *= signal; // update the monotonically decreasing weight
31 
32  frequency *= lacunarity;
33  }
34  return result;
35 }
36 
37 )lobotomized";
38 
39 #endif // GLSLSOURCERIDGEDMULTIFRACTAL_HPP