Noise Modeler Library  0.1
Library for procedurally generating noise-based terrains and other content
 All Classes Files Functions Variables Enumerations Enumerator Groups Pages
glslsourcehybridmultifractal.hpp
1 #ifndef GLSLSOURCEHYBRIDMULTIFRACTAL_HPP
2 #define GLSLSOURCEHYBRIDMULTIFRACTAL_HPP
3 
4 constexpr const char * source_hybridmultifractal = R"lobotomized(
5 
6 //depends on snoise
7 float hybridmultifractal(vec2 pos, float octaves, float lacunarity, float h, float offset, float seed){
8  //compute first octave
9  float result = snoise(pos, seed) + offset;
10  float weight = result;
11  float frequency = lacunarity;
12 
13  for(int i=1; i<octaves; ++i) {
14  //prevent divergence
15  weight = min(weight, 1.0f);
16 
17  //get next higher frequency
18  float exponent = pow(pow(lacunarity, i), -h); //these may perhaps be precomputed
19  float signal = (snoise(pos*frequency, seed) + offset) * exponent;
20  //add it in, weighted by previous freq's local value
21  result += weight * signal;
22  //update the (monotonically decreasing) weighting value
23  //(this is why H must specify a high fractal dimension)
24  weight *= signal;
25 
26  //increase frequency
27  frequency *= lacunarity;
28  }
29 /*
30  //take care of remainder in ``octaves''
31  float remainder = octaves - floor(octaves);
32  if(remainder>0){
33  //spatial freq. is preset in loop above
34  float exponent = pow(pow(lacunarity, octaves), -h);
35  result += remainder * snoise(pos*frequency, seed) * exponent;
36  }
37  */
38 
39  return result;
40 }
41 
42 )lobotomized";
43 
44 #endif // GLSLSOURCEHYBRIDMULTIFRACTAL_HPP