diff --git a/demos/test/simplex.cpp b/demos/test/simplex.cpp index 72a0ee1d..e71b2cbb 100644 --- a/demos/test/simplex.cpp +++ b/demos/test/simplex.cpp @@ -42,9 +42,10 @@ int main(int argc, char **argv) for (int i = 0; i < size.x; ++i) { float p = 0.5f * s.Interp(zoom * vec2(i, j)); -#if 0 +#if 1 for (int k = 2; k < 128; k *= 2) p += 0.5f / k * s.Interp(zoom * k * vec2(i, j)); + //p += 0.5f / k * lol::abs(s.Interp(zoom * k * vec2(i, j))); #endif data[i][j] = vec4(saturate(0.5f + p), 0.f, 0.f, 1.f); } diff --git a/src/lol/math/simplex_interpolator.h b/src/lol/math/simplex_interpolator.h index 119bc4e7..7160641f 100644 --- a/src/lol/math/simplex_interpolator.h +++ b/src/lol/math/simplex_interpolator.h @@ -72,8 +72,10 @@ protected: vec_t const delta = pos - corner; vec_t const &gradient = this->m_gradients[origin]; - // FIXME: where does the 0.75 come from? - float dist = 0.5f - 0.75f * sqlength(delta); + /* We use 4/3 because the maximum radius of influence for + * a given corner is sqrt(3/4). FIXME: check whether this + * holds for higher dimensions. */ + float dist = 1.0f - 4.f / 3.f * sqlength(delta); if (dist > 0) { dist *= dist; @@ -88,11 +90,9 @@ protected: } } - // Approximative scaling factor “100” seems to work well - // ie. gives a max value of 1 (a bit more in fact) for normed gradients // FIXME: another paper uses the value 70 for dimension 2, 32 for // dimension 3, and 27 for dimension 4; find where this comes from. - return result * 100.f; + return result * 70.f / 16.f; } /* For a given position [0…1]^n inside a square/cube/hypercube etc.,