From 1cfdde033b5d1d5ea2ca1dcb19eb053879dcac19 Mon Sep 17 00:00:00 2001 From: lisyarus Date: Sun, 13 Sep 2020 10:36:44 +0300 Subject: [PATCH] Scale pcg::perlin output to [0,1] --- libs/pcg/source/perlin.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libs/pcg/source/perlin.cpp b/libs/pcg/source/perlin.cpp index 20264b16..9d3c87be 100644 --- a/libs/pcg/source/perlin.cpp +++ b/libs/pcg/source/perlin.cpp @@ -44,7 +44,8 @@ namespace psemek::pcg float const d01 = tx * grad_map_(ix, iy+1)[0] + (ty-1.f) * grad_map_(ix, iy+1)[1]; float const d11 = (tx-1.f) * grad_map_(ix+1, iy+1)[0] + (ty-1.f) * grad_map_(ix+1, iy+1)[1]; - return smoothstep(smoothstep(d00, d10, tx), smoothstep(d01, d11, tx), ty); + float v = smoothstep(smoothstep(d00, d10, tx), smoothstep(d01, d11, tx), ty) * std::sqrt(2.f); + return 0.5f + v * 0.5f; } }