diff --git a/src/definition/AtmosphereDefinition.h b/src/definition/AtmosphereDefinition.h index 6ea1781..ae3a635 100644 --- a/src/definition/AtmosphereDefinition.h +++ b/src/definition/AtmosphereDefinition.h @@ -15,7 +15,8 @@ class AtmosphereDefinition : public BaseDefinition public: typedef enum { - ATMOSPHERE_MODEL_BRUNETON = 0 + ATMOSPHERE_MODEL_DISABLED = 0, + ATMOSPHERE_MODEL_BRUNETON = 1 } AtmosphereModel; typedef enum { diff --git a/src/render/preview/TerrainShapePreviewRenderer.cpp b/src/render/preview/TerrainShapePreviewRenderer.cpp index 146e3c2..64afaf2 100644 --- a/src/render/preview/TerrainShapePreviewRenderer.cpp +++ b/src/render/preview/TerrainShapePreviewRenderer.cpp @@ -11,46 +11,29 @@ #include "LightStatus.h" #include "TerrainRenderer.h" -/*static void _getLightingStatus(Renderer*, LightStatus* status, Vector3, int) -{ - LightComponent light; - - light.color.r = 0.6; - light.color.g = 0.6; - light.color.b = 0.6; - light.direction.x = -1.0; - light.direction.y = -0.5; - light.direction.z = 1.0; - light.direction = v3Normalize(light.direction); - light.altered = 1; - light.reflection = 0.0; - status->pushComponent(light); - - light.color.r = 0.2; - light.color.g = 0.2; - light.color.b = 0.2; - light.direction.x = 1.0; - light.direction.y = -0.5; - light.direction.z = -1.0; - light.direction = v3Normalize(light.direction); - light.altered = 0; - light.reflection = 0.0; - status->pushComponent(light); -} - -static Vector3 _getCameraLocation(Renderer*, Vector3 location) -{ - location.x -= 10.0; - location.y += 15.0; - location.z += 10.0; - return location; -}*/ - TerrainShapePreviewRenderer::TerrainShapePreviewRenderer(TerrainDefinition* terrain) { _terrain = terrain; render_quality = 3; + + disableClouds(); + + getScenery()->getTextures()->clear(); + getScenery()->getTextures()->addLayer(); + TextureLayerDefinition* layer = getScenery()->getTextures()->getTextureLayer(0); + layer->terrain_zone->clear(); + layer->displacement_height = 0.0; + layer->material->base = colorToHSL(COLOR_WHITE); + layer->material->reflection = 0.05; + layer->material->shininess = 2.0; + layer->validate(); + layer->_detail_noise->clearLevels(); +} + +Vector3 TerrainShapePreviewRenderer::getCameraLocation(const Vector3 &target) +{ + return target.add(Vector3(-10.0, 15.0, 10.0)); } void TerrainShapePreviewRenderer::bindEvent(BasePreview* preview) @@ -67,17 +50,32 @@ void TerrainShapePreviewRenderer::updateEvent() prepare(); - /*getCameraLocation = _getCameraLocation; - atmosphere->getLightingStatus = _getLightingStatus;*/ + LightComponent light; + std::vector lights; - TextureLayerDefinition* layer = getScenery()->getTextures()->getTextureLayer(0); - layer->terrain_zone->clear(); - layer->displacement_height = 0.0; - layer->material->base = colorToHSL(COLOR_WHITE); - layer->material->reflection = 0.05; - layer->material->shininess = 2.0; - layer->validate(); - layer->_detail_noise->clearLevels(); + light.color.r = 0.6; + light.color.g = 0.6; + light.color.b = 0.6; + light.direction.x = -1.0; + light.direction.y = -0.5; + light.direction.z = 1.0; + light.direction = light.direction.normalize(); + light.altered = 1; + light.reflection = 0.0; + lights.push_back(light); + + light.color.r = 0.2; + light.color.g = 0.2; + light.color.b = 0.2; + light.direction.x = 1.0; + light.direction.y = -0.5; + light.direction.z = -1.0; + light.direction = light.direction.normalize(); + light.altered = 0; + light.reflection = 0.0; + lights.push_back(light); + + disableAtmosphere(lights); } Color TerrainShapePreviewRenderer::getColor2D(double x, double y, double scaling) diff --git a/src/render/preview/TerrainShapePreviewRenderer.h b/src/render/preview/TerrainShapePreviewRenderer.h index 37f5b48..21ea419 100644 --- a/src/render/preview/TerrainShapePreviewRenderer.h +++ b/src/render/preview/TerrainShapePreviewRenderer.h @@ -14,6 +14,8 @@ public: explicit TerrainShapePreviewRenderer(TerrainDefinition* terrain); protected: + virtual Vector3 getCameraLocation(const Vector3 &target) override; + virtual void bindEvent(BasePreview* preview) override; virtual void updateEvent() override; virtual Color getColor2D(double x, double y, double scaling) override; diff --git a/src/render/software/AtmosphereRenderer.cpp b/src/render/software/AtmosphereRenderer.cpp index 6462021..0e78f6f 100644 --- a/src/render/software/AtmosphereRenderer.cpp +++ b/src/render/software/AtmosphereRenderer.cpp @@ -24,6 +24,12 @@ static inline double _getDayFactor(double daytime) static inline void _applyWeatherEffects(AtmosphereDefinition* definition, AtmosphereResult* result) { + if (definition->model == AtmosphereDefinition::ATMOSPHERE_MODEL_DISABLED) + { + result->updateFinal(); + return; + } + double distance = result->distance; double max_distance = 100.0 - 90.0 * definition->humidity; double distancefactor, dayfactor; @@ -76,26 +82,10 @@ BaseAtmosphereRenderer::BaseAtmosphereRenderer(SoftwareRenderer* renderer): void BaseAtmosphereRenderer::getLightingStatus(LightStatus* status, Vector3, int) { - LightComponent light; - - light.color.r = 1.0; - light.color.g = 1.0; - light.color.b = 1.0; - light.direction.x = -0.7; - light.direction.y = -0.7; - light.direction.z = 0.7; - light.altered = 0; - light.reflection = 0.0; - status->pushComponent(light); - light.color.r = 0.3; - light.color.g = 0.31; - light.color.b = 0.34; - light.direction.x = 0.7; - light.direction.y = -0.7; - light.direction.z = -0.7; - light.altered = 0; - light.reflection = 0.0; - status->pushComponent(light); + for (LightComponent light:lights) + { + status->pushComponent(light); + } } AtmosphereResult BaseAtmosphereRenderer::applyAerialPerspective(Vector3, Color base) @@ -121,6 +111,40 @@ Vector3 BaseAtmosphereRenderer::getSunDirection() return Vector3(cos(sun_angle), sin(sun_angle), 0.0); } +void BaseAtmosphereRenderer::setBasicLights() +{ + LightComponent light; + + lights.clear(); + + light.color.r = 0.6; + light.color.g = 0.6; + light.color.b = 0.6; + light.direction.x = -1.0; + light.direction.y = -0.5; + light.direction.z = 1.0; + light.direction = light.direction.normalize(); + light.altered = 1; + light.reflection = 0.0; + lights.push_back(light); + + light.color.r = 0.2; + light.color.g = 0.2; + light.color.b = 0.2; + light.direction.x = 1.0; + light.direction.y = -0.5; + light.direction.z = -1.0; + light.direction = light.direction.normalize(); + light.altered = 0; + light.reflection = 0.0; + lights.push_back(light); +} + +void BaseAtmosphereRenderer::setStaticLights(const std::vector &lights) +{ + this->lights = lights; +} + AtmosphereDefinition* BaseAtmosphereRenderer::getDefinition() { return parent->getScenery()->getAtmosphere(); diff --git a/src/render/software/AtmosphereRenderer.h b/src/render/software/AtmosphereRenderer.h index 969c8fc..fe05468 100644 --- a/src/render/software/AtmosphereRenderer.h +++ b/src/render/software/AtmosphereRenderer.h @@ -4,6 +4,7 @@ #include "software_global.h" #include "Color.h" +#include "LightComponent.h" namespace paysages { namespace software { @@ -19,9 +20,13 @@ public: virtual AtmosphereResult getSkyColor(Vector3 direction); virtual Vector3 getSunDirection(); + void setBasicLights(); + void setStaticLights(const std::vector &lights); + protected: virtual AtmosphereDefinition* getDefinition(); SoftwareRenderer* parent; + std::vector lights; }; class SoftwareBrunetonAtmosphereRenderer: public BaseAtmosphereRenderer diff --git a/src/render/software/SoftwareRenderer.cpp b/src/render/software/SoftwareRenderer.cpp index c9e1c8f..19a601a 100644 --- a/src/render/software/SoftwareRenderer.cpp +++ b/src/render/software/SoftwareRenderer.cpp @@ -88,7 +88,14 @@ void SoftwareRenderer::prepare() { // Prepare sub renderers delete atmosphere_renderer; - atmosphere_renderer = new SoftwareBrunetonAtmosphereRenderer(this); + if (getScenery()->getAtmosphere()->model == AtmosphereDefinition::ATMOSPHERE_MODEL_BRUNETON) + { + atmosphere_renderer = new SoftwareBrunetonAtmosphereRenderer(this); + } + else + { + atmosphere_renderer = new BaseAtmosphereRenderer(this); + } delete clouds_renderer; clouds_renderer = new CloudsRenderer(this); @@ -125,6 +132,15 @@ void SoftwareRenderer::disableClouds() scenery->getClouds()->clear(); } +void SoftwareRenderer::disableAtmosphere(const std::vector &lights) +{ + scenery->getAtmosphere()->model = AtmosphereDefinition::ATMOSPHERE_MODEL_DISABLED; + + delete atmosphere_renderer; + atmosphere_renderer = new BaseAtmosphereRenderer(this); + atmosphere_renderer->setStaticLights(lights); +} + void SoftwareRenderer::setPreviewCallbacks(RenderArea::RenderCallbackStart start, RenderArea::RenderCallbackDraw draw, RenderArea::RenderCallbackUpdate update) { render_area->setPreviewCallbacks(start, draw, update); diff --git a/src/render/software/SoftwareRenderer.h b/src/render/software/SoftwareRenderer.h index fa66c5e..cbc18d5 100644 --- a/src/render/software/SoftwareRenderer.h +++ b/src/render/software/SoftwareRenderer.h @@ -66,8 +66,16 @@ public: /*! * \brief Disable the clouds feature. + * + * This toggle is permanent, provided the clouds part of the sceney is not changed. */ void disableClouds(); + /*! + * \brief Disable atmosphere and sky lighting, replacing it by static lights. + * + * This function needs to be called after each prepare(). + */ + void disableAtmosphere(const std::vector &lights); void setPreviewCallbacks(RenderArea::RenderCallbackStart start, RenderArea::RenderCallbackDraw draw, RenderArea::RenderCallbackUpdate update); void start(RenderArea::RenderParams params);