From a2e8d13f229725e6146387b8eef97ae0591f339f Mon Sep 17 00:00:00 2001 From: MihailRis Date: Sun, 27 Oct 2024 23:14:06 +0300 Subject: [PATCH 1/2] update doc/*/world-generator.md --- doc/en/world-generator.md | 1 + doc/ru/world-generator.md | 1 + 2 files changed, 2 insertions(+) diff --git a/doc/en/world-generator.md b/doc/en/world-generator.md index 15d9ea54..b6e053ac 100644 --- a/doc/en/world-generator.md +++ b/doc/en/world-generator.md @@ -299,6 +299,7 @@ Changes the heightmap size. Available interpolation modes: - 'nearest' - no interpolation - 'linear' - bilinear interpolation +- 'cubic' - bicubic interpolation ### heightmap:crop(...) diff --git a/doc/ru/world-generator.md b/doc/ru/world-generator.md index 98be0ff4..5ccdbc68 100644 --- a/doc/ru/world-generator.md +++ b/doc/ru/world-generator.md @@ -303,6 +303,7 @@ map:resize(ширина, высота, интерполяция) Доступные режимы интерполяции: - 'nearest' - без интерполяции - 'linear' - билинейная интерполяция +- 'cubic' - бикубическая интерполяция ### heightmap:crop(...) From c4336818429e4d4e2946d3c69fc530f398b42d68 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Sun, 27 Oct 2024 23:43:06 +0300 Subject: [PATCH 2/2] revert ChancellorIkseew/bicubic-interpolation --- doc/en/world-generator.md | 1 - doc/ru/world-generator.md | 1 - src/maths/Heightmap.cpp | 68 +-------------------------------------- 3 files changed, 1 insertion(+), 69 deletions(-) diff --git a/doc/en/world-generator.md b/doc/en/world-generator.md index b6e053ac..15d9ea54 100644 --- a/doc/en/world-generator.md +++ b/doc/en/world-generator.md @@ -299,7 +299,6 @@ Changes the heightmap size. Available interpolation modes: - 'nearest' - no interpolation - 'linear' - bilinear interpolation -- 'cubic' - bicubic interpolation ### heightmap:crop(...) diff --git a/doc/ru/world-generator.md b/doc/ru/world-generator.md index 5ccdbc68..98be0ff4 100644 --- a/doc/ru/world-generator.md +++ b/doc/ru/world-generator.md @@ -303,7 +303,6 @@ map:resize(ширина, высота, интерполяция) Доступные режимы интерполяции: - 'nearest' - без интерполяции - 'linear' - билинейная интерполяция -- 'cubic' - бикубическая интерполяция ### heightmap:crop(...) diff --git a/src/maths/Heightmap.cpp b/src/maths/Heightmap.cpp index 7bf45c05..8db33f6b 100644 --- a/src/maths/Heightmap.cpp +++ b/src/maths/Heightmap.cpp @@ -50,73 +50,7 @@ static inline float sample_at( return a00 + a10*tx + a01*ty + a11*tx*ty; } - case InterpolationType::CUBIC: { - float b1 = - ((tx - 1) * (tx - 2) * (tx + 1) * (ty - 1) * (ty - 2) * (ty + 1)) / 4; - float b2 = - (tx * (tx + 1) * (tx - 2) * (ty - 1) * (ty - 2) * (ty + 1)) / -4; - float b3 = - (tx * (tx + 1) * (tx - 2) * (ty - 1) * (ty - 2) * (ty + 1)) / -4; - float b4 = - (tx * (tx + 1) * (tx + 2) * ty * (ty + 1) * (ty - 2)) / 4; - float b5 = - (tx * (tx - 1) * (tx - 2) * (ty - 1) * (ty - 2) * (ty + 1)) / -12; - float b6 = - ((tx - 1) * (tx - 2) * (tx + 1) * ty * (ty - 1) * (ty - 2)) / -12; - float b7 = - (tx * (tx - 1) * (tx - 2) * ty * (ty + 1) * (ty - 2)) / 12; - float b8 = - (tx * (tx + 1) * (tx - 2) * ty * (ty - 1) * (ty - 2)) / 12; - float b9 = - (tx * (tx - 1) * (tx + 1) * (ty - 1) * (ty - 2) * (ty + 1)) / 12; - float b10 = - ((tx - 1) * (tx - 2) * (tx + 1) * ty * (ty - 1) * (ty + 1)) /12; - float b11 = - (tx * (tx - 1) * (tx - 2) * ty * (ty + 1) * (ty - 2)) / 36; - float b12 = - (tx * (tx - 1) * (tx + 1) * ty * (ty + 1) * (ty - 2)) / -12; - float b13 = - (tx * (tx + 1) * (tx - 2) * ty * (ty - 1) * (ty + 1)) / -12; - float b14 = - (tx * (tx - 1) * (tx + 1) * ty * (ty - 1) * (ty - 2)) / -36; - float b15 = - (tx * (tx - 1) * (tx - 2) * ty * (ty - 1) * (ty + 1)) / -36; - float b16 = - (tx * (tx - 1) * (tx + 1) * ty * (ty - 1) * (ty + 1)) / 36; - - - float a1 = b1 * val; - float a2 = b2 * sample_at(buffer, width, ix, iy + 1 < height ? iy + 1 : iy); - float a3 = b3 * sample_at(buffer, width, ix + 1 < width ? ix + 1 : ix, iy); - float a4 = b4 * sample_at(buffer, width, - ix + 1 < width ? ix + 1 : ix, iy + 1 < height ? iy + 1 : iy); - float a5 = b5 * sample_at(buffer, width, ix, iy > 1 ? iy - 1 : iy); - float a6 = b6 * sample_at(buffer, width, ix > 1 ? ix - 1 : ix, iy); - float a7 = b7 * sample_at(buffer, width, - ix + 1 < width ? ix + 1 : ix, iy > 1 ? iy - 1 : iy); - float a8 = b8 * sample_at(buffer, width, - ix > 1 ? ix - 1 : ix, iy + 1 < height ? iy + 1 : iy); - float a9 = b9 * sample_at(buffer, width, - ix, iy + 2 < height ? iy + 2 : iy); - float a10 = b10 * sample_at(buffer, width, - ix + 2 < width ? ix + 2 : ix, iy); - float a11 = b11 * sample_at( buffer, width, - ix > 1 ? ix - 1 : ix, iy > 1 ? iy - 1 : iy); - float a12 = b12 * sample_at(buffer, width, - ix + 1 < width ? ix + 1 : ix, iy + 2 < height ? iy + 2 : iy); - float a13 = b13 * sample_at(buffer, width, - ix + 2 < width ? ix + 2 : ix, iy + 1 < height ? iy + 1 : iy); - float a14 = b14 * sample_at(buffer, width, - ix > 1 ? ix - 1 : ix, iy + 2 < height ? iy + 2 : iy); - float a15 = b15 * sample_at(buffer, width, - ix + 2 < width ? ix + 2 : ix, iy > 1 ? iy - 1 : iy); - float a16 = b16 * sample_at(buffer, width, - ix + 2 < width ? ix + 2 : ix, iy + 2 < height ? iy + 2 : iy); - - return a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8 + - a9 + a10 + a11 + a12 + a13 + a14 + a15 + a16; - } - + // TODO: implement CUBIC (Bicubic) interpolation default: throw std::runtime_error("interpolation type is not implemented"); }