|
@@ -833,18 +833,23 @@ Image GenImagePerlinNoise(int width, int height, int offsetX, int offsetY, float
|
|
|
{
|
|
|
for (int x = 0; x < width; x++)
|
|
|
{
|
|
|
- float nx = (float)(x + offsetX)*scale/(float)width;
|
|
|
- float ny = (float)(y + offsetY)*scale/(float)height;
|
|
|
-
|
|
|
+ float nx = (float)(x + offsetX)*(scale/(float)width);
|
|
|
+ float ny = (float)(y + offsetY)*(scale/(float)height);
|
|
|
+
|
|
|
+ // Basic perlin noise implementation (not used)
|
|
|
+ //float p = (stb_perlin_noise3(nx, ny, 0.0f, 0, 0, 0);
|
|
|
+
|
|
|
+ // Calculate a better perlin noise using fbm (fractal brownian motion)
|
|
|
// Typical values to start playing with:
|
|
|
// lacunarity = ~2.0 -- spacing between successive octaves (use exactly 2.0 for wrapping output)
|
|
|
// gain = 0.5 -- relative weighting applied to each successive octave
|
|
|
// octaves = 6 -- number of "octaves" of noise3() to sum
|
|
|
+ float p = stb_perlin_fbm_noise3(nx, ny, 1.0f, 2.0f, 0.5f, 6);
|
|
|
+
|
|
|
+ // We need to normalize the data from [-1..1] to [0..1]
|
|
|
+ float np = (p + 1.0f)/2.0f;
|
|
|
|
|
|
- // NOTE: We need to translate the data from [-1..1] to [0..1]
|
|
|
- float p = (stb_perlin_fbm_noise3(nx, ny, 1.0f, 2.0f, 0.5f, 6) + 1.0f)/2.0f;
|
|
|
-
|
|
|
- int intensity = (int)(p*255.0f);
|
|
|
+ int intensity = (int)(np*255.0f);
|
|
|
pixels[y*width + x] = (Color){ intensity, intensity, intensity, 255 };
|
|
|
}
|
|
|
}
|