From 2b022155668b1748e52c6e452cf310b0fd7e4271 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Fri, 18 Mar 2016 00:27:01 +0100 Subject: [PATCH] Improved terrain ray walking test --- src/interface/commandline/tests.cpp | 75 ++++++++++++++++------------- 1 file changed, 42 insertions(+), 33 deletions(-) diff --git a/src/interface/commandline/tests.cpp b/src/interface/commandline/tests.cpp index 37dca84..2fa7ee3 100644 --- a/src/interface/commandline/tests.cpp +++ b/src/interface/commandline/tests.cpp @@ -586,7 +586,6 @@ static void testTerrainRayMarching() { int width = 2000; int height = 600; Texture2D result(width, height); - result.fill(COLOR_WHITE); Scenery scenery; SoftwareRenderer renderer(&scenery); @@ -601,44 +600,54 @@ static void testTerrainRayMarching() { terrain->validate(); - int multisample = 8; + for (int i = 0; i < 6; i++) { + int multisample = 8; - // Draw terrain shape - for (int x = 0; x < width * multisample; x++) { - double altitude = terrain->getInterpolatedHeight(to_double(x) / to_double(multisample), 0.0, true, false); - int y = height / 2 + round_to_int(altitude); - if (y >= 0 && y < height) { - result.setPixel(x / multisample, y, COLOR_GREY); + result.fill(COLOR_WHITE); + + // Draw terrain shape + for (int x = 0; x < width * multisample; x++) { + double altitude = terrain->getInterpolatedHeight(to_double(x) / to_double(multisample), 0.0, true, false); + int y = height / 2 + round_to_int(altitude); + if (y >= 0 && y < height) { + result.setPixel(x / multisample, y, COLOR_GREY); + } + + Vector3 displaced = renderer.getTerrainRenderer()->getDisplaced(to_double(x) / to_double(multisample), 0.0, true); + int hx = round_to_int(displaced.x); + int hy = height / 2 + round_to_int(displaced.y); + if (hx >= 0 && hx < width && hy >= 0 && hy < height) { + result.setPixel(hx, hy, COLOR_BLACK); + } + + result.setPixel(x / multisample, height / 2 + round_to_int(terrain->propWaterHeight()->getValue()), COLOR_BLUE); } - Vector3 displaced = renderer.getTerrainRenderer()->getDisplaced(to_double(x) / to_double(multisample), 0.0, true); - int hx = round_to_int(displaced.x); - int hy = height / 2 + round_to_int(displaced.y); - if (hx >= 0 && hx < width && hy >= 0 && hy < height) { - result.setPixel(hx, hy, COLOR_BLACK); + + // Draw direction hint + double offset = to_double(i) * 0.2; + Vector3 direction = Vector3(offset, -1.0, 0.0).normalize(); + for (int y = 0; y < height; y++) { + result.setPixel(height / 4 + round_to_int(to_double(y) * direction.x), height - 1 - y, COLOR_GREEN); } - result.setPixel(x / multisample, height / 2 + round_to_int(terrain->propWaterHeight()->getValue()), COLOR_BLUE); + // Draw ray marcher hits + TerrainRayWalker walker(&renderer); + walker.setQuality(1.0, 0.1, 5.0, 1.0, to_double(height), 0.1); + walker.update(); + for (int x = 0; x < width * multisample; x++) { + TerrainRayWalker::TerrainHitResult hit; + double max_height = terrain->getHeightInfo().max_height; + walker.startWalking(Vector3(to_double(x) / to_double(multisample) - to_double(max_height) * offset, to_double(max_height), 0.0), direction, 0.0, hit); + int hx = round_to_int(hit.hit_location.x); + int hy = height / 2 + round_to_int(hit.hit_location.y); + if (hx >= 0 && hx < width && hy >= 0 && hy < height) { + result.setPixel(hx, hy, COLOR_RED); + } + } + + result.saveToFile(getFileName("terrain_ray_marching", i)); } - - // Draw ray marcher iterations - TerrainRayWalker walker(&renderer); - walker.setQuality(1.0, 0.1, 5.0, 1.0, to_double(height), 0.1); - walker.update(); - double offset = 0.0; - Vector3 direction = Vector3(offset, -1.0, 0.0).normalize(); - for (int x = 0; x < width * multisample; x++) { - TerrainRayWalker::TerrainHitResult hit; - double max_height = terrain->getHeightInfo().max_height; - walker.startWalking(Vector3(to_double(x) / to_double(multisample) - to_double(max_height) * offset, to_double(max_height), 0.0), direction, 0.0, hit); - int hx = round_to_int(hit.hit_location.x); - int hy = height / 2 + round_to_int(hit.hit_location.y); - if (hx >= 0 && hx < width && hy >= 0 && hy < height) { - result.setPixel(hx, hy, COLOR_RED); - } - } - - result.saveToFile(getFileName("terrain_ray_marching")); } void runTestSuite() {