Refactored AtmosphereDefinition

This commit is contained in:
Michaël Lemaire 2013-11-16 00:27:40 +01:00
parent 1cccae90be
commit 4f9e24b87d
20 changed files with 231 additions and 243 deletions

View file

@ -0,0 +1,122 @@
#include "AtmosphereDefinition.h"
#include "PackStream.h"
AtmosphereDefinition::AtmosphereDefinition(BaseDefinition* parent):
BaseDefinition(parent)
{
}
AtmosphereDefinition::~AtmosphereDefinition()
{
}
void AtmosphereDefinition::save(PackStream* stream) const
{
stream->write((int*)&model);
stream->write(&hour);
stream->write(&minute);
sun_color.save(stream);
stream->write(&sun_radius);
stream->write(&dome_lighting);
stream->write(&humidity);
}
void AtmosphereDefinition::load(PackStream* stream)
{
stream->read((int*)&model);
stream->read(&hour);
stream->read(&minute);
sun_color.load(stream);
stream->read(&sun_radius);
stream->read(&dome_lighting);
stream->read(&humidity);
validate();
}
void AtmosphereDefinition::copy(BaseDefinition* _destination) const
{
AtmosphereDefinition* destination = (AtmosphereDefinition*)_destination;
destination->model = model;
destination->hour = hour;
destination->minute = minute;
destination->sun_color = sun_color;
destination->sun_radius = sun_radius;
destination->dome_lighting = dome_lighting;
destination->humidity = humidity;
destination->validate();
}
void AtmosphereDefinition::validate()
{
if (hour < 0)
{
hour = 0;
}
if (hour > 23)
{
hour = 23;
}
if (minute < 0)
{
minute = 0;
}
if (minute > 59)
{
minute = 59;
}
_daytime = (double)hour / 24.0 + (double)minute / 1440.0;
}
void AtmosphereDefinition::applyPreset(AtmospherePreset preset)
{
sun_color.r = 1.0;
sun_color.g = 0.95;
sun_color.b = 0.9;
sun_color.a = 1.0;
sun_radius = 1.0;
humidity = 0.1;
model = ATMOSPHERE_MODEL_BRUNETON;
switch (preset)
{
case ATMOSPHERE_PRESET_CLEAR_DAY:
hour = 15;
minute = 0;
dome_lighting = 0.2;
break;
case ATMOSPHERE_PRESET_CLEAR_SUNSET:
hour = 17;
minute = 45;
dome_lighting = 0.3;
sun_radius = 0.03;
break;
case ATMOSPHERE_PRESET_HAZY_MORNING:
hour = 8;
minute = 30;
dome_lighting = 0.25;
humidity = 0.4;
break;
case ATMOSPHERE_PRESET_FOGGY:
hour = 15;
minute = 0;
dome_lighting = 0.1;
humidity = 0.7;
break;
case ATMOSPHERE_PRESET_STORMY:
hour = 15;
minute = 0;
dome_lighting = 0.05;
humidity = 0.9;
break;
default:
;
}
validate();
}

View file

@ -0,0 +1,56 @@
#ifndef ATMOSPHEREDEFINITION_H
#define ATMOSPHEREDEFINITION_H
#include "definition_global.h"
#include "BaseDefinition.h"
#include "Color.h"
namespace paysages {
namespace definition {
class AtmosphereDefinition : public BaseDefinition
{
public:
typedef enum
{
ATMOSPHERE_MODEL_BRUNETON = 0
} AtmosphereModel;
typedef enum
{
ATMOSPHERE_PRESET_CLEAR_DAY = 0,
ATMOSPHERE_PRESET_CLEAR_SUNSET = 1,
ATMOSPHERE_PRESET_HAZY_MORNING = 2,
ATMOSPHERE_PRESET_FOGGY = 3,
ATMOSPHERE_PRESET_STORMY = 4
} AtmospherePreset;
public:
AtmosphereDefinition(BaseDefinition* parent);
virtual ~AtmosphereDefinition();
virtual void save(PackStream* stream) const override;
virtual void load(PackStream* stream) override;
virtual void copy(BaseDefinition* destination) const override;
virtual void validate() override;
void applyPreset(AtmospherePreset preset);
public:
AtmosphereModel model;
int hour;
int minute;
double humidity;
Color sun_color;
double sun_radius;
double dome_lighting;
double _daytime;
};
}
}
#endif // ATMOSPHEREDEFINITION_H

View file

@ -29,23 +29,23 @@ void BaseDefinition::setName(QString name)
this->name = name; this->name = name;
} }
void BaseDefinition::save(PackStream* pack) const void BaseDefinition::save(PackStream* stream) const
{ {
pack->write(name); stream->write(name);
QListIterator<BaseDefinition*> it(children); QListIterator<BaseDefinition*> it(children);
while (it.hasNext()) while (it.hasNext())
{ {
it.next()->save(pack); it.next()->save(stream);
} }
} }
void BaseDefinition::load(PackStream* pack) void BaseDefinition::load(PackStream* stream)
{ {
name = pack->readString(); name = stream->readString();
QListIterator<BaseDefinition*> it(children); QListIterator<BaseDefinition*> it(children);
while (it.hasNext()) while (it.hasNext())
{ {
it.next()->load(pack); it.next()->load(stream);
} }
} }

View file

@ -19,8 +19,8 @@ public:
BaseDefinition(BaseDefinition* parent); BaseDefinition(BaseDefinition* parent);
virtual ~BaseDefinition(); virtual ~BaseDefinition();
virtual void save(PackStream* pack) const; virtual void save(PackStream* stream) const;
virtual void load(PackStream* pack); virtual void load(PackStream* stream);
virtual void copy(BaseDefinition* destination) const; virtual void copy(BaseDefinition* destination) const;
virtual void validate(); virtual void validate();

View file

@ -21,7 +21,8 @@ SOURCES += \
SurfaceMaterial.cpp \ SurfaceMaterial.cpp \
CameraDefinition.cpp \ CameraDefinition.cpp \
CloudsDefinition.cpp \ CloudsDefinition.cpp \
CloudLayerDefinition.cpp CloudLayerDefinition.cpp \
AtmosphereDefinition.cpp
HEADERS +=\ HEADERS +=\
definition_global.h \ definition_global.h \
@ -32,7 +33,8 @@ HEADERS +=\
SurfaceMaterial.h \ SurfaceMaterial.h \
CameraDefinition.h \ CameraDefinition.h \
CloudsDefinition.h \ CloudsDefinition.h \
CloudLayerDefinition.h CloudLayerDefinition.h \
AtmosphereDefinition.h
unix:!symbian { unix:!symbian {
maemo5 { maemo5 {

View file

@ -19,6 +19,7 @@ namespace definition {
class Layers; class Layers;
class CloudsDefinition; class CloudsDefinition;
class CloudLayerDefinition; class CloudLayerDefinition;
class AtmosphereDefinition;
} }
} }
using namespace paysages::definition; using namespace paysages::definition;

View file

@ -6,8 +6,8 @@
#include "main.h" #include "main.h"
#include "render.h" #include "render.h"
#include "renderer.h" #include "renderer.h"
#include "atmosphere/public.h"
#include "CameraDefinition.h" #include "CameraDefinition.h"
#include "AtmosphereDefinition.h"
#include "SoftwareRenderer.h" #include "SoftwareRenderer.h"
#include "Scenery.h" #include "Scenery.h"
@ -170,7 +170,7 @@ int main(int argc, char** argv)
AtmosphereDefinition* atmo = Scenery::getCurrent()->getAtmosphere(); AtmosphereDefinition* atmo = Scenery::getCurrent()->getAtmosphere();
atmo->hour = (int)floor(conf_daytime_start * 24.0); atmo->hour = (int)floor(conf_daytime_start * 24.0);
atmo->minute = (int)floor(fmod(conf_daytime_start, 1.0 / 24.0) * 24.0 * 60.0); atmo->minute = (int)floor(fmod(conf_daytime_start, 1.0 / 24.0) * 24.0 * 60.0);
AtmosphereDefinitionClass.validate(atmo); atmo->validate();
CameraDefinition* camera = Scenery::getCurrent()->getCamera(); CameraDefinition* camera = Scenery::getCurrent()->getCamera();
Vector3 step = {conf_camera_step_x, conf_camera_step_y, conf_camera_step_z}; Vector3 step = {conf_camera_step_x, conf_camera_step_y, conf_camera_step_z};

View file

@ -6,10 +6,10 @@
#include <QSlider> #include <QSlider>
#include <cmath> #include <cmath>
#include "atmosphere/public.h"
#include "AtmosphereColorPreviewRenderer.h" #include "AtmosphereColorPreviewRenderer.h"
#include "Scenery.h" #include "Scenery.h"
#include "BasePreview.h" #include "BasePreview.h"
#include "AtmosphereDefinition.h"
#include "renderer.h" #include "renderer.h"
static AtmosphereDefinition* _definition; static AtmosphereDefinition* _definition;
@ -45,7 +45,7 @@ FormAtmosphere::FormAtmosphere(QWidget *parent):
addAutoPreset(tr("Foggy")); addAutoPreset(tr("Foggy"));
addAutoPreset(tr("Stormy")); addAutoPreset(tr("Stormy"));
_definition = (AtmosphereDefinition*)AtmosphereDefinitionClass.create(); _definition = new AtmosphereDefinition(NULL);
previewWest = new BasePreview(this); previewWest = new BasePreview(this);
previewWestRenderer = new PreviewSkyRenderer(M_PI / 2.0); previewWestRenderer = new PreviewSkyRenderer(M_PI / 2.0);
@ -90,12 +90,12 @@ void FormAtmosphere::applyConfig()
void FormAtmosphere::configChangeEvent() void FormAtmosphere::configChangeEvent()
{ {
AtmosphereDefinitionClass.validate(_definition); _definition->validate();
BaseForm::configChangeEvent(); BaseForm::configChangeEvent();
} }
void FormAtmosphere::autoPresetSelected(int preset) void FormAtmosphere::autoPresetSelected(int preset)
{ {
atmosphereAutoPreset(_definition, (AtmospherePreset)preset); _definition->applyPreset((AtmosphereDefinition::AtmospherePreset)preset);
BaseForm::autoPresetSelected(preset); BaseForm::autoPresetSelected(preset);
} }

View file

@ -2,6 +2,7 @@
#include <cmath> #include <cmath>
#include "SoftwareRenderer.h" #include "SoftwareRenderer.h"
#include "AtmosphereDefinition.h"
#include "Scenery.h" #include "Scenery.h"
// TEMP // TEMP
@ -130,7 +131,7 @@ AtmosphereResult SoftwareBrunetonAtmosphereRenderer::applyAerialPerspective(Vect
/* Get base perspective */ /* Get base perspective */
switch (definition->model) switch (definition->model)
{ {
case ATMOSPHERE_MODEL_BRUNETON: case AtmosphereDefinition::ATMOSPHERE_MODEL_BRUNETON:
result = brunetonApplyAerialPerspective(renderer, location, base); result = brunetonApplyAerialPerspective(renderer, location, base);
break; break;
default: default:
@ -189,7 +190,7 @@ AtmosphereResult SoftwareBrunetonAtmosphereRenderer::getSkyColor(Vector3 directi
Vector3 location = v3Add(camera_location, v3Scale(direction, 6421.0)); Vector3 location = v3Add(camera_location, v3Scale(direction, 6421.0));
switch (definition->model) switch (definition->model)
{ {
case ATMOSPHERE_MODEL_BRUNETON: case AtmosphereDefinition::ATMOSPHERE_MODEL_BRUNETON:
result = brunetonGetSkyColor(renderer, camera_location, direction, sun_position, base); result = brunetonGetSkyColor(renderer, camera_location, direction, sun_position, base);
break; break;
default: default:

View file

@ -4,6 +4,7 @@
#include "Scenery.h" #include "Scenery.h"
#include "FluidMediumManager.h" #include "FluidMediumManager.h"
#include "AtmosphereRenderer.h" #include "AtmosphereRenderer.h"
#include "AtmosphereDefinition.h"
// Legacy compatibility // Legacy compatibility
@ -63,7 +64,7 @@ void SoftwareRenderer::prepare()
atmosphere_renderer = new SoftwareBrunetonAtmosphereRenderer(this); atmosphere_renderer = new SoftwareBrunetonAtmosphereRenderer(this);
// Setup transitional renderers (for C-legacy subsystems) // Setup transitional renderers (for C-legacy subsystems)
AtmosphereDefinitionClass.copy(scenery->getAtmosphere(), atmosphere->definition); scenery->getAtmosphere()->copy(atmosphere->definition);
atmosphere->applyAerialPerspective = _legacyApplyAerialPerspective; atmosphere->applyAerialPerspective = _legacyApplyAerialPerspective;
atmosphere->getSkyColor = _legacyGetSkyColor; atmosphere->getSkyColor = _legacyGetSkyColor;
atmosphere->getLightingStatus = _legacyGetLightingStatus; atmosphere->getLightingStatus = _legacyGetLightingStatus;

View file

@ -9,17 +9,17 @@
#include "CloudsDefinition.h" #include "CloudsDefinition.h"
#include "terrain/public.h" #include "terrain/public.h"
#include "textures/public.h" #include "textures/public.h"
#include "water/public.h"
#include "renderer.h" #include "renderer.h"
#include "terrain/ter_raster.h" #include "terrain/ter_raster.h"
#include "WaterDefinition.h" #include "WaterDefinition.h"
#include "AtmosphereDefinition.h"
static Scenery _main_scenery; static Scenery _main_scenery;
Scenery::Scenery(): Scenery::Scenery():
BaseDefinition(NULL) BaseDefinition(NULL)
{ {
atmosphere = (AtmosphereDefinition*)AtmosphereDefinitionClass.create(); atmosphere = new AtmosphereDefinition(this);
camera = new CameraDefinition; camera = new CameraDefinition;
clouds = new CloudsDefinition(this); clouds = new CloudsDefinition(this);
terrain = (TerrainDefinition*)TerrainDefinitionClass.create(); terrain = (TerrainDefinition*)TerrainDefinitionClass.create();
@ -27,6 +27,7 @@ Scenery::Scenery():
water = new WaterDefinition(this); water = new WaterDefinition(this);
addChild(camera); addChild(camera);
addChild(atmosphere);
addChild(water); addChild(water);
addChild(clouds); addChild(clouds);
@ -37,7 +38,6 @@ Scenery::Scenery():
Scenery::~Scenery() Scenery::~Scenery()
{ {
AtmosphereDefinitionClass.destroy(atmosphere);
TerrainDefinitionClass.destroy(terrain); TerrainDefinitionClass.destroy(terrain);
TexturesDefinitionClass.destroy(textures); TexturesDefinitionClass.destroy(textures);
} }
@ -60,7 +60,6 @@ void Scenery::save(PackStream* stream) const
noiseSave(stream); noiseSave(stream);
AtmosphereDefinitionClass.save(stream, atmosphere);
TerrainDefinitionClass.save(stream, terrain); TerrainDefinitionClass.save(stream, terrain);
TexturesDefinitionClass.save(stream, textures); TexturesDefinitionClass.save(stream, textures);
@ -76,7 +75,6 @@ void Scenery::load(PackStream* stream)
noiseLoad(stream); noiseLoad(stream);
AtmosphereDefinitionClass.load(stream, atmosphere);
TerrainDefinitionClass.load(stream, terrain); TerrainDefinitionClass.load(stream, terrain);
TexturesDefinitionClass.load(stream, textures); TexturesDefinitionClass.load(stream, textures);
@ -105,7 +103,7 @@ void Scenery::autoPreset(int seed)
terrainAutoPreset(terrain, TERRAIN_PRESET_STANDARD); terrainAutoPreset(terrain, TERRAIN_PRESET_STANDARD);
texturesAutoPreset(textures, TEXTURES_PRESET_FULL); texturesAutoPreset(textures, TEXTURES_PRESET_FULL);
atmosphereAutoPreset(atmosphere, ATMOSPHERE_PRESET_CLEAR_DAY); atmosphere->applyPreset(AtmosphereDefinition::ATMOSPHERE_PRESET_CLEAR_DAY);
water->applyPreset(WATER_PRESET_LAKE); water->applyPreset(WATER_PRESET_LAKE);
clouds->applyPreset(CloudsDefinition::CLOUDS_PRESET_PARTLY_CLOUDY); clouds->applyPreset(CloudsDefinition::CLOUDS_PRESET_PARTLY_CLOUDY);
@ -117,12 +115,12 @@ void Scenery::autoPreset(int seed)
void Scenery::setAtmosphere(AtmosphereDefinition* atmosphere) void Scenery::setAtmosphere(AtmosphereDefinition* atmosphere)
{ {
AtmosphereDefinitionClass.copy(atmosphere, this->atmosphere); atmosphere->copy(this->atmosphere);
} }
void Scenery::getAtmosphere(AtmosphereDefinition* atmosphere) void Scenery::getAtmosphere(AtmosphereDefinition* atmosphere)
{ {
AtmosphereDefinitionClass.copy(this->atmosphere, atmosphere); this->atmosphere->copy(atmosphere);
} }
void Scenery::setCamera(CameraDefinition* camera) void Scenery::setCamera(CameraDefinition* camera)
@ -180,6 +178,7 @@ void Scenery::getWater(WaterDefinition* water)
#include "clouds/public.h" #include "clouds/public.h"
#include "water/public.h"
static RayCastingResult _rayWalking(Renderer* renderer, Vector3 location, Vector3 direction, int, int, int, int) static RayCastingResult _rayWalking(Renderer* renderer, Vector3 location, Vector3 direction, int, int, int, int)
{ {

View file

@ -5,7 +5,6 @@
#include "BaseDefinition.h" #include "BaseDefinition.h"
class AtmosphereDefinition;
class TerrainDefinition; class TerrainDefinition;
class TexturesDefinition; class TexturesDefinition;
class Renderer; class Renderer;

View file

@ -11,6 +11,7 @@
#include <cstdlib> #include <cstdlib>
#include "System.h" #include "System.h"
#include "PackStream.h" #include "PackStream.h"
#include "AtmosphereDefinition.h"
#include "tools.h" #include "tools.h"
#include "tools/cache.h" #include "tools/cache.h"
#include "tools/texture.h" #include "tools/texture.h"
@ -1043,7 +1044,7 @@ static void _saveDebug4D(Texture4D* tex, const char* tag, int order)
} }
/*********************** Public methods ***********************/ /*********************** Public methods ***********************/
void brunetonInit() int brunetonInit()
{ {
int x, y, z, w, order; int x, y, z, w, order;
ParallelWork* work; ParallelWork* work;
@ -1060,7 +1061,7 @@ void brunetonInit()
&& _tryLoadCache2D(_irradianceTexture, "irradiance", 0) && _tryLoadCache2D(_irradianceTexture, "irradiance", 0)
&& _tryLoadCache4D(_inscatterTexture, "inscatter", 0)) && _tryLoadCache4D(_inscatterTexture, "inscatter", 0))
{ {
return; return 1;
} }
Texture2D* _deltaETexture = texture2DCreate(SKY_W, SKY_H); Texture2D* _deltaETexture = texture2DCreate(SKY_W, SKY_H);
@ -1149,8 +1150,12 @@ void brunetonInit()
texture4DDelete(_deltaSMTexture); texture4DDelete(_deltaSMTexture);
texture4DDelete(_deltaSRTexture); texture4DDelete(_deltaSRTexture);
texture4DDelete(_deltaJTexture); texture4DDelete(_deltaJTexture);
return 1;
} }
static const int _init = brunetonInit();
AtmosphereResult brunetonGetSkyColor(Renderer* renderer, Vector3 eye, Vector3 direction, Vector3 sun_position, Color base) AtmosphereResult brunetonGetSkyColor(Renderer* renderer, Vector3 eye, Vector3 direction, Vector3 sun_position, Color base)
{ {
UNUSED(base); UNUSED(base);

View file

@ -1,101 +0,0 @@
#include "private.h"
#include <cmath>
#include <cstdlib>
#include "PackStream.h"
#include "../tools.h"
#include "../renderer.h"
static int _inited = 0;
/******************** Definition ********************/
static void _validateDefinition(AtmosphereDefinition* definition)
{
if (definition->hour < 0)
{
definition->hour = 0;
}
if (definition->hour > 23)
{
definition->hour = 23;
}
if (definition->minute < 0)
{
definition->minute = 0;
}
if (definition->minute > 59)
{
definition->minute = 59;
}
definition->_daytime = (double)definition->hour / 24.0 + (double)definition->minute / 1440.0;
}
static AtmosphereDefinition* _createDefinition()
{
AtmosphereDefinition* result;
/* TODO Find a better place for this */
if (!_inited)
{
_inited = 1;
brunetonInit();
}
result = new AtmosphereDefinition;
atmosphereAutoPreset(result, ATMOSPHERE_PRESET_CLEAR_DAY);
return result;
}
static void _deleteDefinition(AtmosphereDefinition* definition)
{
delete definition;
}
static void _copyDefinition(AtmosphereDefinition* source, AtmosphereDefinition* destination)
{
destination->model = source->model;
destination->hour = source->hour;
destination->minute = source->minute;
destination->sun_color = source->sun_color;
destination->sun_radius = source->sun_radius;
destination->dome_lighting = source->dome_lighting;
destination->humidity = source->humidity;
_validateDefinition(destination);
}
static void _saveDefinition(PackStream* stream, AtmosphereDefinition* definition)
{
stream->write((int*)&definition->model);
stream->write(&definition->hour);
stream->write(&definition->minute);
colorSave(stream, &definition->sun_color);
stream->write(&definition->sun_radius);
stream->write(&definition->dome_lighting);
stream->write(&definition->humidity);
}
static void _loadDefinition(PackStream* stream, AtmosphereDefinition* definition)
{
stream->read((int*)&definition->model);
stream->read(&definition->hour);
stream->read(&definition->minute);
colorLoad(stream, &definition->sun_color);
stream->read(&definition->sun_radius);
stream->read(&definition->dome_lighting);
stream->read(&definition->humidity);
_validateDefinition(definition);
}
StandardDefinition AtmosphereDefinitionClass = {
(FuncObjectCreate)_createDefinition,
(FuncObjectDelete)_deleteDefinition,
(FuncObjectCopy)_copyDefinition,
(FuncObjectValidate)_validateDefinition,
(FuncObjectSave)_saveDefinition,
(FuncObjectLoad)_loadDefinition
};

View file

@ -1,54 +0,0 @@
#include "private.h"
/*
* Atmosphere presets.
*/
void atmosphereAutoPreset(AtmosphereDefinition* definition, AtmospherePreset preset)
{
definition->sun_color.r = 1.0;
definition->sun_color.g = 0.95;
definition->sun_color.b = 0.9;
definition->sun_color.a = 1.0;
definition->sun_radius = 1.0;
definition->humidity = 0.1;
definition->model = ATMOSPHERE_MODEL_BRUNETON;
switch (preset)
{
case ATMOSPHERE_PRESET_CLEAR_DAY:
definition->hour = 15;
definition->minute = 0;
definition->dome_lighting = 0.2;
break;
case ATMOSPHERE_PRESET_CLEAR_SUNSET:
definition->hour = 17;
definition->minute = 45;
definition->dome_lighting = 0.3;
definition->sun_radius = 0.03;
break;
case ATMOSPHERE_PRESET_HAZY_MORNING:
definition->hour = 8;
definition->minute = 30;
definition->dome_lighting = 0.25;
definition->humidity = 0.4;
break;
case ATMOSPHERE_PRESET_FOGGY:
definition->hour = 15;
definition->minute = 0;
definition->dome_lighting = 0.1;
definition->humidity = 0.7;
break;
case ATMOSPHERE_PRESET_STORMY:
definition->hour = 15;
definition->minute = 0;
definition->dome_lighting = 0.05;
definition->humidity = 0.9;
break;
default:
;
}
AtmosphereDefinitionClass.validate(definition);
}

View file

@ -1,40 +1,32 @@
#include "private.h" #include "private.h"
#include <math.h> #include <cmath>
#include <stdlib.h> #include <cstdlib>
#include <string.h> #include <cstring>
#include "../tools.h" #include "AtmosphereDefinition.h"
#include "../renderer.h" #include "../renderer.h"
/******************** Fake ********************/ /******************** Fake ********************/
static AtmosphereResult _fakeApplyAerialPerspective(Renderer* renderer, Vector3 location, Color base) static AtmosphereResult _fakeApplyAerialPerspective(Renderer*, Vector3, Color base)
{ {
AtmosphereResult result; AtmosphereResult result;
UNUSED(renderer);
UNUSED(location);
result.base = result.final = base; result.base = result.final = base;
result.inscattering = result.attenuation = COLOR_BLACK; result.inscattering = result.attenuation = COLOR_BLACK;
return result; return result;
} }
static AtmosphereResult _fakeGetSkyColor(Renderer* renderer, Vector3 direction) static AtmosphereResult _fakeGetSkyColor(Renderer*, Vector3)
{ {
AtmosphereResult result; AtmosphereResult result;
UNUSED(renderer);
UNUSED(direction);
result.base = result.final = COLOR_WHITE; result.base = result.final = COLOR_WHITE;
result.inscattering = result.attenuation = COLOR_BLACK; result.inscattering = result.attenuation = COLOR_BLACK;
return result; return result;
} }
static void _fakeGetLightingStatus(Renderer* renderer, LightStatus* status, Vector3 normal, int opaque) static void _fakeGetLightingStatus(Renderer*, LightStatus* status, Vector3, int)
{ {
LightDefinition light; LightDefinition light;
UNUSED(renderer);
UNUSED(normal);
UNUSED(opaque);
light.color.r = 1.0; light.color.r = 1.0;
light.color.g = 1.0; light.color.g = 1.0;
light.color.b = 1.0; light.color.b = 1.0;
@ -91,7 +83,7 @@ static AtmosphereRenderer* _createRenderer()
AtmosphereRenderer* result; AtmosphereRenderer* result;
result = new AtmosphereRenderer; result = new AtmosphereRenderer;
result->definition = (AtmosphereDefinition*)AtmosphereDefinitionClass.create(); result->definition = new AtmosphereDefinition(NULL);
result->getLightingStatus = _fakeGetLightingStatus; result->getLightingStatus = _fakeGetLightingStatus;
result->getSunDirection = _realGetSunDirection; result->getSunDirection = _realGetSunDirection;
@ -103,13 +95,13 @@ static AtmosphereRenderer* _createRenderer()
static void _deleteRenderer(AtmosphereRenderer* renderer) static void _deleteRenderer(AtmosphereRenderer* renderer)
{ {
AtmosphereDefinitionClass.destroy(renderer->definition); delete renderer->definition;
delete renderer; delete renderer;
} }
static void _bindRenderer(Renderer* renderer, AtmosphereDefinition* definition) static void _bindRenderer(Renderer* renderer, AtmosphereDefinition* definition)
{ {
AtmosphereDefinitionClass.copy(definition, renderer->atmosphere->definition); definition->copy(renderer->atmosphere->definition);
} }
StandardRenderer AtmosphereRendererClass = { StandardRenderer AtmosphereRendererClass = {

View file

@ -12,7 +12,6 @@
#define SUN_RADIUS 6.955e5 #define SUN_RADIUS 6.955e5
#define SUN_RADIUS_SCALED (SUN_RADIUS / WORLD_SCALING) #define SUN_RADIUS_SCALED (SUN_RADIUS / WORLD_SCALING)
void brunetonInit();
AtmosphereResult brunetonGetSkyColor(Renderer* renderer, Vector3 eye, Vector3 direction, Vector3 sun_position, Color base); AtmosphereResult brunetonGetSkyColor(Renderer* renderer, Vector3 eye, Vector3 direction, Vector3 sun_position, Color base);
AtmosphereResult brunetonApplyAerialPerspective(Renderer* renderer, Vector3 location, Color base); AtmosphereResult brunetonApplyAerialPerspective(Renderer* renderer, Vector3 location, Color base);
void brunetonGetLightingStatus(Renderer* renderer, LightStatus* status, Vector3 normal, int opaque); void brunetonGetLightingStatus(Renderer* renderer, LightStatus* status, Vector3 normal, int opaque);

View file

@ -1,44 +1,14 @@
#ifndef _PAYSAGES_ATMOSPHERE_PUBLIC_H_ #ifndef _PAYSAGES_ATMOSPHERE_PUBLIC_H_
#define _PAYSAGES_ATMOSPHERE_PUBLIC_H_ #define _PAYSAGES_ATMOSPHERE_PUBLIC_H_
#include "rendering_global.h"
#include "../rendering_global.h" #include "../rendering_global.h"
#include "../tools/lighting.h" #include "../tools/lighting.h"
#include "../tools/euclid.h" #include "../tools/euclid.h"
#include "../tools/color.h" #include "../tools/color.h"
#include "../shared/types.h" #include "../shared/types.h"
namespace paysages {
namespace system {class PackStream;}
}
typedef enum
{
ATMOSPHERE_PRESET_CLEAR_DAY = 0,
ATMOSPHERE_PRESET_CLEAR_SUNSET = 1,
ATMOSPHERE_PRESET_HAZY_MORNING = 2,
ATMOSPHERE_PRESET_FOGGY = 3,
ATMOSPHERE_PRESET_STORMY = 4
} AtmospherePreset;
typedef enum
{
ATMOSPHERE_MODEL_BRUNETON = 0
} AtmosphereModel;
class AtmosphereDefinition
{
public:
AtmosphereModel model;
int hour;
int minute;
double humidity;
Color sun_color;
double sun_radius;
double dome_lighting;
double _daytime;
};
typedef struct typedef struct
{ {
Color base; Color base;
@ -67,11 +37,8 @@ public:
/*void* _internal_data;*/ /*void* _internal_data;*/
}; };
RENDERINGSHARED_EXPORT extern StandardDefinition AtmosphereDefinitionClass;
RENDERINGSHARED_EXPORT extern StandardRenderer AtmosphereRendererClass; RENDERINGSHARED_EXPORT extern StandardRenderer AtmosphereRendererClass;
RENDERINGSHARED_EXPORT void atmosphereAutoPreset(AtmosphereDefinition* definition, AtmospherePreset preset);
RENDERINGSHARED_EXPORT void atmosphereRenderSkydome(Renderer* renderer); RENDERINGSHARED_EXPORT void atmosphereRenderSkydome(Renderer* renderer);
RENDERINGSHARED_EXPORT void atmosphereInitResult(AtmosphereResult* result); RENDERINGSHARED_EXPORT void atmosphereInitResult(AtmosphereResult* result);

View file

@ -16,8 +16,6 @@ SOURCES += main.cpp \
geoarea.cpp \ geoarea.cpp \
atmosphere/atm_render.cpp \ atmosphere/atm_render.cpp \
atmosphere/atm_raster.cpp \ atmosphere/atm_raster.cpp \
atmosphere/atm_presets.cpp \
atmosphere/atm_definition.cpp \
atmosphere/atm_bruneton.cpp \ atmosphere/atm_bruneton.cpp \
clouds/clo_walking.cpp \ clouds/clo_walking.cpp \
clouds/clo_rendering.cpp \ clouds/clo_rendering.cpp \

View file

@ -3,7 +3,8 @@
#include "tools/color.h" #include "tools/color.h"
#include "CameraDefinition.h" #include "CameraDefinition.h"
#include "SoftwareRenderer.h" #include "SoftwareRenderer.h"
#include "atmosphere/public.h" #include "AtmosphereDefinition.h"
#include "AtmosphereRenderer.h"
#include "Scenery.h" #include "Scenery.h"
#include "System.h" #include "System.h"
@ -46,7 +47,7 @@ TEST(Bruneton, AerialPerspective2)
AtmosphereDefinition* atmo = Scenery::getCurrent()->getAtmosphere(); AtmosphereDefinition* atmo = Scenery::getCurrent()->getAtmosphere();
atmo->hour = 6; atmo->hour = 6;
atmo->minute = 30; atmo->minute = 30;
AtmosphereDefinitionClass.validate(atmo); atmo->validate();
Renderer renderer; Renderer renderer;
renderer.render_width = 800; renderer.render_width = 800;