Fixed terrain preview

This commit is contained in:
Michaël Lemaire 2013-12-15 14:28:46 +01:00
parent 00e04df25a
commit 97a950947a
7 changed files with 121 additions and 67 deletions

View file

@ -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
{

View file

@ -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<LightComponent> 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)

View file

@ -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;

View file

@ -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<LightComponent> &lights)
{
this->lights = lights;
}
AtmosphereDefinition* BaseAtmosphereRenderer::getDefinition()
{
return parent->getScenery()->getAtmosphere();

View file

@ -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<LightComponent> &lights);
protected:
virtual AtmosphereDefinition* getDefinition();
SoftwareRenderer* parent;
std::vector<LightComponent> lights;
};
class SoftwareBrunetonAtmosphereRenderer: public BaseAtmosphereRenderer

View file

@ -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<LightComponent> &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);

View file

@ -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<LightComponent> &lights);
void setPreviewCallbacks(RenderArea::RenderCallbackStart start, RenderArea::RenderCallbackDraw draw, RenderArea::RenderCallbackUpdate update);
void start(RenderArea::RenderParams params);