summaryrefslogtreecommitdiffhomepage
path: root/src/rtextures.c
diff options
context:
space:
mode:
authorRay <[email protected]>2023-05-21 00:14:09 +0200
committerRay <[email protected]>2023-05-21 00:14:09 +0200
commitf31df7521a9e59f7a1af3f923630900ad74eb1bc (patch)
tree7566dcabded8f43d80f60ac1b4c097d448dd0f32 /src/rtextures.c
parent51387dfbfba7f9e8d1698183ef279c5785fd0d71 (diff)
downloadraylib-f31df7521a9e59f7a1af3f923630900ad74eb1bc.tar.gz
raylib-f31df7521a9e59f7a1af3f923630900ad74eb1bc.zip
REVIEWED: `GenImagePerlinNoise()`, no change
Diffstat (limited to 'src/rtextures.c')
-rw-r--r--src/rtextures.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/rtextures.c b/src/rtextures.c
index 6bca43d1..2d8056d6 100644
--- a/src/rtextures.c
+++ b/src/rtextures.c
@@ -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 };
}
}