diff --git a/noise/basis.cpp b/noise/basis.cpp index 30255c10..e78363a5 100644 --- a/noise/basis.cpp +++ b/noise/basis.cpp @@ -101,6 +101,12 @@ value::eval (double x, double y) const { double x_fac = x - x_int; double y_fac = y - y_int; + // Shift the coordinate system down a little to ensure we get unit weights + // for the lerp. It's better to do this than abs the fractional portion so + // we don't get reflections along the origin. + if (x < 0) { x_fac = 1.0 + x_fac; x_int -= 1; } + if (y < 0) { y_fac = 1.0 + y_fac; y_int -= 1; } + // Generate the four corner values double p0 = generate (x_int, y_int, this->seed); double p1 = generate (x_int + 1, y_int, this->seed); @@ -144,6 +150,12 @@ gradient::eval (double x, double y) const { double x_fac = x - x_int; double y_fac = y - y_int; + // Shift the coordinate system down a little to ensure we get unit weights + // for the lerp. It's better to do this than abs the fractional portion so + // we don't get reflections along the origin. + if (x < 0) { x_fac = 1.0 + x_fac; x_int -= 1; } + if (y < 0) { y_fac = 1.0 + y_fac; y_int -= 1; } + // Generate the four corner values. It's not strictly necessary to // normalise the values, but we get a more consistent and visually // appealing range of outputs with normalised values. @@ -191,6 +203,12 @@ cellular::eval (double x, double y) const { double x_fac = x - x_int; double y_fac = y - y_int; + // Generate the four corner values. It's not strictly necessary to + // normalise the values, but we get a more consistent and visually + // appealing range of outputs with normalised values. + if (x < 0) { x_fac = 1.0 + x_fac; x_int -= 1; } + if (y < 0) { y_fac = 1.0 + y_fac; y_int -= 1; } + // +---+---+---+ // | 0 | 1 | 2 | // +---+---+---+