From 0ab1719d2527beed9502aab55dbfb89fff494ebe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Thu, 17 Dec 2015 19:29:04 +0100 Subject: [PATCH] Added better render tests for atmosphere artifacts --- src/definition/DefinitionWatcher.h | 12 +++--- src/interface/commandline/main.cpp | 3 ++ src/interface/commandline/tests.cpp | 47 ++++++++++++++++------- src/render/software/OverlayRasterizer.cpp | 8 ++-- src/system/Memory.cpp | 2 +- 5 files changed, 48 insertions(+), 24 deletions(-) diff --git a/src/definition/DefinitionWatcher.h b/src/definition/DefinitionWatcher.h index e634ae4..cf6ce94 100644 --- a/src/definition/DefinitionWatcher.h +++ b/src/definition/DefinitionWatcher.h @@ -20,6 +20,12 @@ class DEFINITIONSHARED_EXPORT DefinitionWatcher { */ virtual void nodeChanged(const DefinitionNode *node, const DefinitionDiff *diff); + protected: + /** + * Start watching a path in a definition tree. + */ + void startWatching(const DefinitionNode *root, const string &path, bool init_diff = true); + /** * Abstract convenience to receive integer node changes. */ @@ -29,12 +35,6 @@ class DEFINITIONSHARED_EXPORT DefinitionWatcher { * Abstract convenience to receive float node changes. */ virtual void floatNodeChanged(const string &path, double new_value, double old_value); - - protected: - /** - * Start watching a path in a definition tree. - */ - void startWatching(const DefinitionNode *root, const string &path, bool init_diff = true); }; } } diff --git a/src/interface/commandline/main.cpp b/src/interface/commandline/main.cpp index 9d3cba3..7e6ca74 100644 --- a/src/interface/commandline/main.cpp +++ b/src/interface/commandline/main.cpp @@ -4,6 +4,7 @@ #include "AtmosphereDefinition.h" #include "CameraDefinition.h" #include "TimeManager.h" +#include "Logs.h" #include @@ -126,6 +127,8 @@ int main(int argc, char **argv) { scenery->autoPreset(); } + Logs::debug("CommandLine") << "Rendered scenery :" << endl << scenery->toString() << endl; + TimeManager time; time.setWind(conf_wind_x, conf_wind_z); if (conf_daytime_start >= 0.0) { diff --git a/src/interface/commandline/tests.cpp b/src/interface/commandline/tests.cpp index fb9a50e..0703d4c 100644 --- a/src/interface/commandline/tests.cpp +++ b/src/interface/commandline/tests.cpp @@ -4,6 +4,8 @@ #include "CameraDefinition.h" #include "TerrainDefinition.h" #include "AtmosphereDefinition.h" +#include "AtmosphereRenderer.h" +#include "AtmosphereResult.h" #include "TexturesDefinition.h" #include "GodRaysDefinition.h" #include "TextureLayerDefinition.h" @@ -231,22 +233,41 @@ static void testCloudsNearGround() { startTestRender(&renderer, "clouds_near_ground", 2); } -static void testSunNearHorizon() { +static void testAtmosphereBruneton() { Scenery scenery; - scenery.autoPreset(28); - scenery.getCamera()->setLocation(VECTOR_ZERO); - scenery.getCamera()->setTarget(VECTOR_EAST); - scenery.getClouds()->clear(); - scenery.getTextures()->applyPreset(TexturesDefinition::TEXTURES_PRESET_CANYON); - scenery.getTerrain()->propWaterHeight()->setValue(-1.0); + scenery.getAtmosphere()->applyPreset(AtmosphereDefinition::ATMOSPHERE_PRESET_CLEAR_DAY); + scenery.getCamera()->setTarget(Vector3(10.0, 1.0, 0.0)); + scenery.getCamera()->setLocation(Vector3(0.0, 1.0, 0.0)); SoftwareCanvasRenderer renderer(&scenery); - renderer.setSize(400, 300); - renderer.setQuality(0.3); + renderer.setSize(800, 400); + renderer.getGodRaysSampler()->setEnabled(false); - for (int i = 0; i <= 20; i++) { - scenery.getAtmosphere()->propDayTime()->setValue(0.24 + 0.001 * to_double(i)); - startTestRender(&renderer, "sun_near_horizon", i); + class TestRasterizer : public OverlayRasterizer { + public: + TestRasterizer(SoftwareCanvasRenderer *renderer) + : OverlayRasterizer(renderer, renderer->getProgressHelper()), renderer(renderer) { + } + virtual Color processPixel(int, int, double relx, double rely) const override { + if (rely > 0.0) { + Vector3 dir = (relx < 0.0) ? Vector3(1.0, rely, relx + 1.0) : Vector3(-1.0, rely, relx - 1.0); + auto result = renderer->getAtmosphereRenderer()->getSkyColor(dir); + return result.final; + } else { + auto result = renderer->getAtmosphereRenderer()->applyAerialPerspective( + Vector3(-relx * 400.0, (rely + 1.0) * 20.0 - 10.0, 0.0), COLOR_BLACK); + return result.final; + } + } + SoftwareCanvasRenderer *renderer; + }; + TestRasterizer rasterizer(&renderer); + renderer.setSoloRasterizer(&rasterizer); + + for (int i = 0; i <= 60; i++) { + double daytime = (i < 40) ? (0.24 + 0.0005 * to_double(i)) : (0.26 + 0.005 * to_double(i - 40)); + scenery.getAtmosphere()->propDayTime()->setValue(daytime); + startTestRender(&renderer, "atmosphere_bruneton", i); } } @@ -327,7 +348,7 @@ void runTestSuite() { testGodRays(); testNearFrustum(); testCloudsNearGround(); - testSunNearHorizon(); + testAtmosphereBruneton(); testVegetationModels(); testOpenGLVegetationImpostor(); } diff --git a/src/render/software/OverlayRasterizer.cpp b/src/render/software/OverlayRasterizer.cpp index 34f40bc..604cd9a 100644 --- a/src/render/software/OverlayRasterizer.cpp +++ b/src/render/software/OverlayRasterizer.cpp @@ -18,10 +18,10 @@ int OverlayRasterizer::prepareRasterization() { void OverlayRasterizer::rasterizeToCanvas(CanvasPortion *canvas) { double width = to_double(renderer->render_camera->getWidth()); double height = to_double(renderer->render_camera->getHeight()); - Vector3 topleft = renderer->unprojectPoint(Vector3(height, 0.0, 1.0)); - Vector3 bottomleft = renderer->unprojectPoint(Vector3(0.0, 0.0, 1.0)); - Vector3 topright = renderer->unprojectPoint(Vector3(height, width, 1.0)); - Vector3 bottomright = renderer->unprojectPoint(Vector3(0.0, width, 1.0)); + Vector3 topleft = renderer->unprojectPoint(Vector3(0.0, height, 1.0001)); + Vector3 bottomleft = renderer->unprojectPoint(Vector3(0.0, 0.0, 1.0001)); + Vector3 topright = renderer->unprojectPoint(Vector3(width, height, 1.0001)); + Vector3 bottomright = renderer->unprojectPoint(Vector3(width, 0.0, 1.0001)); pushQuad(canvas, topleft, bottomleft, bottomright, topright); } diff --git a/src/system/Memory.cpp b/src/system/Memory.cpp index ffe31eb..0e4eb2b 100644 --- a/src/system/Memory.cpp +++ b/src/system/Memory.cpp @@ -1,6 +1,6 @@ #include "Memory.h" -#include +#include #include #include