From ba3d86bbdaa6061d4ba9d2b49374f12ef462a3a3 Mon Sep 17 00:00:00 2001 From: MAGGen-hub <56871670+MAGGen-hub@users.noreply.github.com> Date: Thu, 4 Jan 2024 02:17:24 +0300 Subject: [PATCH] Bug fixes for OpenSimplex2S Noise 2D (GLSL) and Value Cubic Noise 3D (GLSL and HLSL) (#127) * Fixed fragmentation bug in _fnlSingleOpenSimplex2S2D (GLSL) In GLSL version OpenSimplex2S2D was divided into rhombic fragments. This fix was based on HLSL version code, that has no fragmentation bug: see https://github.com/Auburn/FastNoiseLite/blob/df34389c6b3cbba88fd7caf9d376587ebcb31522/HLSL/FastNoiseLite.hlsl#L1059C22-L1059C22 * Fixed contrast bug in _fnlSingleValueCubic3D (GLSL) In GLSL version ValueCubic3D produced values that was outside of default color ramp. This fix was based on C++ version code, that has no contrast bug: see https://github.com/Auburn/FastNoiseLite/blob/df34389c6b3cbba88fd7caf9d376587ebcb31522/Cpp/FastNoiseLite.h#L1914 * Fixed contrast bug in _fnlSingleValueCubic3D (HLSL) In HLSL version ValueCubic3D produced values that was outside of default color ramp. This fix was based on C++ version code, that has no contrast bug: see https://github.com/Auburn/FastNoiseLite/blob/df34389c6b3cbba88fd7caf9d376587ebcb31522/Cpp/FastNoiseLite.h#L1914 --- GLSL/FastNoiseLite.glsl | 6 +++--- HLSL/FastNoiseLite.hlsl | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/GLSL/FastNoiseLite.glsl b/GLSL/FastNoiseLite.glsl index 4cb576f..330e7d2 100644 --- a/GLSL/FastNoiseLite.glsl +++ b/GLSL/FastNoiseLite.glsl @@ -787,8 +787,8 @@ float _fnlSingleOpenSimplex2S2D(int seed, FNLfloat x, FNLfloat y) float y0 = yi - t; int aMask = int((xi + yi + 1.f) * -0.5f); - int bMask = int((xi - float(aMask) + 2.f) * 0.5f - yi); - int cMask = int((yi - float(aMask) + 2.f) * 0.5f - xi); + int bMask = int((xi - (float(aMask) + 2.f)) * 0.5f - yi); + int cMask = int((yi - (float(aMask) + 2.f)) * 0.5f - xi); float a0 = (2.f / 3.f) - x0 * x0 - y0 * y0; float value = (a0 * a0) * (a0 * a0) * _fnlGradCoord2D(seed, i, j, x0, y0); @@ -1446,7 +1446,7 @@ float _fnlSingleValueCubic3D(int seed, FNLfloat x, FNLfloat y, FNLfloat z) _fnlCubicLerp(_fnlValCoord3D(seed, x0, y2, z3), _fnlValCoord3D(seed, x1, y2, z3), _fnlValCoord3D(seed, x2, y2, z3), _fnlValCoord3D(seed, x3, y2, z3), xs), _fnlCubicLerp(_fnlValCoord3D(seed, x0, y3, z3), _fnlValCoord3D(seed, x1, y3, z3), _fnlValCoord3D(seed, x2, y3, z3), _fnlValCoord3D(seed, x3, y3, z3), xs), ys), - zs) * (1.f / 1.5f * 1.5f * 1.5f); + zs) * (1.f / (1.5f * 1.5f * 1.5f)); } diff --git a/HLSL/FastNoiseLite.hlsl b/HLSL/FastNoiseLite.hlsl index 73a06f4..7781cbe 100644 --- a/HLSL/FastNoiseLite.hlsl +++ b/HLSL/FastNoiseLite.hlsl @@ -1714,7 +1714,7 @@ static float _fnlSingleValueCubic3D(int seed, FNLfloat x, FNLfloat y, FNLfloat z _fnlCubicLerp(_fnlValCoord3D(seed, x0, y2, z3), _fnlValCoord3D(seed, x1, y2, z3), _fnlValCoord3D(seed, x2, y2, z3), _fnlValCoord3D(seed, x3, y2, z3), xs), _fnlCubicLerp(_fnlValCoord3D(seed, x0, y3, z3), _fnlValCoord3D(seed, x1, y3, z3), _fnlValCoord3D(seed, x2, y3, z3), _fnlValCoord3D(seed, x3, y3, z3), xs), ys), - zs) * (1 / 1.5f * 1.5f * 1.5f); + zs) * (1 / (1.5f * 1.5f * 1.5f)); } // Value noise