From 6ac1e899f8dc5bd06ac480e4c4e17f8cda8ed35f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Thu, 17 Mar 2016 19:56:57 +0100 Subject: [PATCH] Added terrain ray marching visual testing --- src/interface/commandline/tests.cpp | 63 +++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/src/interface/commandline/tests.cpp b/src/interface/commandline/tests.cpp index 4ef7e7b..37dca84 100644 --- a/src/interface/commandline/tests.cpp +++ b/src/interface/commandline/tests.cpp @@ -37,6 +37,7 @@ #include "NoiseFunctionSimplex.h" #include "Zone.h" #include "MaterialNode.h" +#include "TerrainRayWalker.h" #include #include @@ -581,12 +582,72 @@ static void testCanvasAliasing() { } } +static void testTerrainRayMarching() { + int width = 2000; + int height = 600; + Texture2D result(width, height); + result.fill(COLOR_WHITE); + + Scenery scenery; + SoftwareRenderer renderer(&scenery); + + auto terrain = scenery.getTerrain(); + terrain->propWaterHeight()->setValue(0.0); + terrain->propHeightNoise()->setConfig(to_double(height), 1.0, 0.5, 0.1); + + TextureLayerDefinition disp(NULL, "disp"); + disp.propDisplacementNoise()->setConfig(to_double(height) * 0.4); + terrain->propDisplacements()->addLayer(disp); + + terrain->validate(); + + 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); + } + + 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); + } + + // 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() { testNoise(); testCanvasAliasing(); testTextures(); testGodRays(); testCelestialBodies(); + testTerrainRayMarching(); testNearFrustum(); testCloudsLighting(); testCloudModels(); @@ -597,4 +658,6 @@ void runTestSuite() { testGroundShadowQuality(); testCloudQuality(); testAtmosphereBruneton(); + + cout << "Done." << endl; }