From 36bf4372b8169105b0c201ec37a4bfd4b82e3509 Mon Sep 17 00:00:00 2001 From: dane_madsen Date: Sun, 21 May 2023 12:48:54 +1000 Subject: [PATCH] Added two if statements to clap the value returned by stb_perlin_fbm_noise3 to between -1.0f and 1.0f. Not sure why this was required but it fixed the issue with random spikes. --- src/rtextures.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/rtextures.c b/src/rtextures.c index 2d8056d64..462e4c790 100644 --- a/src/rtextures.c +++ b/src/rtextures.c @@ -846,10 +846,14 @@ Image GenImagePerlinNoise(int width, int height, int offsetX, int offsetY, float // octaves = 6 -- number of "octaves" of noise3() to sum float p = stb_perlin_fbm_noise3(nx, ny, 1.0f, 2.0f, 0.5f, 6); + // Clamp between -1.0f and 1.0f + if(p < -1.0f) p = -1.0f; + if(p > 1.0f) p = 1.0f; + // We need to normalize the data from [-1..1] to [0..1] float np = (p + 1.0f)/2.0f; - int intensity = (int)(np*255.0f); + int intensity = (int)(np*255.0); pixels[y*width + x] = (Color){ intensity, intensity, intensity, 255 }; } }