From d3e94706aedc37e659bfd1cd2dcee4c0f1cb2d02 Mon Sep 17 00:00:00 2001
From: Hoshinova <nucleohoshinova@gmail.com>
Date: Wed, 27 Sep 2023 18:01:17 +0200
Subject: [PATCH] Fix #112180: Noise with high detail and lacunarity outputs
 erratic values

This patch fixes #112180 by aligning the floor fraction function with
the GLSL/SVM ones, through the use of the floor math function.

Pull Request: https://projects.blender.org/blender/blender/pulls/112962

Pull Request: https://projects.blender.org/blender/blender/pulls/131680
---
 source/blender/blenlib/intern/noise.cc | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/source/blender/blenlib/intern/noise.cc b/source/blender/blenlib/intern/noise.cc
index 65a6f102a7b..3dd6863cb60 100644
--- a/source/blender/blenlib/intern/noise.cc
+++ b/source/blender/blenlib/intern/noise.cc
@@ -379,8 +379,9 @@ BLI_INLINE float noise_grad(uint32_t hash, float x, float y, float z, float w)
 
 BLI_INLINE float floor_fraction(float x, int &i)
 {
-  i = int(x) - ((x < 0) ? 1 : 0);
-  return x - i;
+  float x_floor = math::floor(x);
+  i = int(x_floor);
+  return x - x_floor;
 }
 
 BLI_INLINE float perlin_noise(float position)
-- 
GitLab