From 3a841ac130f90c607c29aa79288b943bbfe569b1 Mon Sep 17 00:00:00 2001 From: Ray Date: Sun, 21 May 2023 10:28:04 +0200 Subject: [PATCH] REVIEWED: `GenImagePerlinNoise()`, clamp values #3071 --- src/rtextures.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/rtextures.c b/src/rtextures.c index 2d8056d64..875942586 100644 --- a/src/rtextures.c +++ b/src/rtextures.c @@ -846,6 +846,10 @@ 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;