diff --git a/src/render/software/AtmosphereModelBruneton.cpp b/src/render/software/AtmosphereModelBruneton.cpp index ccaed98..1a21ad5 100644 --- a/src/render/software/AtmosphereModelBruneton.cpp +++ b/src/render/software/AtmosphereModelBruneton.cpp @@ -1154,7 +1154,7 @@ AtmosphereModelBruneton::AtmosphereModelBruneton(SoftwareRenderer *parent): { } -AtmosphereResult AtmosphereModelBruneton::getSkyColor(Vector3 eye, const Vector3 &direction, const Vector3 &sun_position, const Color &) +AtmosphereResult AtmosphereModelBruneton::getSkyColor(Vector3 eye, const Vector3 &direction, const Vector3 &sun_position, const Color &base) { double yoffset = GROUND_OFFSET - parent->getWaterRenderer()->getHeightInfo().base_height; eye.y += yoffset; @@ -1177,7 +1177,7 @@ AtmosphereResult AtmosphereModelBruneton::getSkyColor(Vector3 eye, const Vector3 /*result.base.r = base.r + sunColor.r; result.base.g = base.g + sunColor.g; result.base.b = base.b + sunColor.b;*/ - result.base = sunColor; + result.base = base.add(sunColor); result.inscattering = _getInscatterColor(&x, &t, v, s, &r, &mu, &attenuation); /* S[L]-T(x,xs)S[l]|xs */ /* TODO Use atmosphere attenuation */ result.distance = SPHERE_SIZE; diff --git a/src/render/software/AtmosphereRenderer.cpp b/src/render/software/AtmosphereRenderer.cpp index 5b79eba..7ce14ad 100644 --- a/src/render/software/AtmosphereRenderer.cpp +++ b/src/render/software/AtmosphereRenderer.cpp @@ -8,6 +8,7 @@ #include "LightComponent.h" #include "LightStatus.h" #include "Scenery.h" +#include "NightSky.h" /* Factor to convert software units to kilometers */ #define WORLD_SCALING 0.05 @@ -207,8 +208,12 @@ AtmosphereResult SoftwareBrunetonAtmosphereRenderer::getSkyColor(Vector3 directi direction = direction.normalize(); sun_position = sun_direction.scale(SUN_DISTANCE_SCALED); - /* Get sun shape */ base = COLOR_BLACK; + + /* Get night sky */ + base = base.add(parent->getNightSky()->getColor(camera_location.y, direction)); + + /* Get sun shape */ /*if (v3Dot(sun_direction, direction) >= 0) { double sun_radius = definition->sun_radius * SUN_RADIUS_SCALED * 5.0; // FIXME Why should we multiply by 5 ? @@ -233,8 +238,6 @@ AtmosphereResult SoftwareBrunetonAtmosphereRenderer::getSkyColor(Vector3 directi } }*/ - /* TODO Get stars */ - /* Get scattering */ AtmosphereResult result; Vector3 location = camera_location.add(direction.scale(6421.0)); diff --git a/src/render/software/NightSky.cpp b/src/render/software/NightSky.cpp new file mode 100644 index 0000000..a8bfa72 --- /dev/null +++ b/src/render/software/NightSky.cpp @@ -0,0 +1,53 @@ +#include "NightSky.h" + +#include "Color.h" +#include "Vector3.h" +#include "Geometry.h" + +NightSky::NightSky(SoftwareRenderer* renderer): + renderer(renderer) +{ +} + +NightSky::~NightSky() +{ +} + +void NightSky::update() +{ +} + +const Color NightSky::getColor(double altitude, const Vector3 &direction) +{ + Color result(0.01, 0.012, 0.03); + + Vector3 location(0.0, altitude, 0.0); + + // Get stars + + // Get moon + Vector3 moon_direction(0.3, 0.4, -0.3); + moon_direction.normalize(); + if (moon_direction.dotProduct(direction) >= 0) + { + Vector3 moon_position = moon_direction.scale(100.0); + double moon_radius = 1.0; + Vector3 hit1, hit2; + int hits = Geometry::rayIntersectSphere(location, direction, moon_position, moon_radius, &hit1, &hit2); + if (hits > 1) + { + double dist = hit2.sub(hit1).getNorm() / moon_radius; // distance between intersection points (relative to radius) + + Color moon_color(0.3, 0.3, 0.3); + if (dist <= 0.05) + { + moon_color.a *= 1.0 - dist / 0.05; + } + result.mask(moon_color); + } + } + + + return result; + +} diff --git a/src/render/software/NightSky.h b/src/render/software/NightSky.h new file mode 100644 index 0000000..428f033 --- /dev/null +++ b/src/render/software/NightSky.h @@ -0,0 +1,36 @@ +#ifndef NIGHTSKY_H +#define NIGHTSKY_H + +#include "software_global.h" + +namespace paysages { +namespace software { + +/*! + * \brief Night sky renderer. + */ +class SOFTWARESHARED_EXPORT NightSky +{ +public: + NightSky(SoftwareRenderer* renderer); + virtual ~NightSky(); + + /*! + * \brief Update the night sky renderer, when the scenery or parent renderer changed. + */ + void update(); + + /*! + * \brief Get the color of the night sky at a given direction. + * \param altitude Altitude above water level, in coordinate units (not kilometers). + */ + virtual const Color getColor(double altitude, const Vector3 &direction); + +private: + SoftwareRenderer* renderer; +}; + +} +} + +#endif // NIGHTSKY_H diff --git a/src/render/software/SoftwareRenderer.cpp b/src/render/software/SoftwareRenderer.cpp index c0d8882..a876c83 100644 --- a/src/render/software/SoftwareRenderer.cpp +++ b/src/render/software/SoftwareRenderer.cpp @@ -14,6 +14,7 @@ #include "SkyRasterizer.h" #include "TerrainRasterizer.h" #include "WaterRasterizer.h" +#include "NightSky.h" #include "LightStatus.h" #include "LightingManager.h" #include "System.h" @@ -39,6 +40,8 @@ SoftwareRenderer::SoftwareRenderer(Scenery* scenery) textures_renderer = new TexturesRenderer(this); water_renderer = new WaterRenderer(this); + nightsky_renderer = new NightSky(this); + fluid_medium = new FluidMediumManager(this); lighting = new LightingManager(); @@ -61,6 +64,8 @@ SoftwareRenderer::~SoftwareRenderer() delete fluid_medium; delete lighting; + delete nightsky_renderer; + delete atmosphere_renderer; delete clouds_renderer; delete terrain_renderer; @@ -96,6 +101,8 @@ void SoftwareRenderer::prepare() water_renderer->update(); textures_renderer->update(); + nightsky_renderer->update(); + // Prepare global tools fluid_medium->clearMedia(); //fluid_medium->registerMedium(water_renderer); diff --git a/src/render/software/SoftwareRenderer.h b/src/render/software/SoftwareRenderer.h index 4894949..9f269f3 100644 --- a/src/render/software/SoftwareRenderer.h +++ b/src/render/software/SoftwareRenderer.h @@ -90,6 +90,8 @@ public: inline TexturesRenderer* getTexturesRenderer() const {return textures_renderer;} inline WaterRenderer* getWaterRenderer() const {return water_renderer;} + inline NightSky* getNightSky() const {return nightsky_renderer;} + inline FluidMediumManager* getFluidMediumManager() const {return fluid_medium;} inline LightingManager* getLightingManager() const {return lighting;} @@ -108,6 +110,7 @@ private: TerrainRenderer* terrain_renderer; TexturesRenderer* textures_renderer; WaterRenderer* water_renderer; + NightSky* nightsky_renderer; }; } diff --git a/src/render/software/software.pro b/src/render/software/software.pro index 070ad32..f00ec48 100644 --- a/src/render/software/software.pro +++ b/src/render/software/software.pro @@ -35,7 +35,8 @@ SOURCES += SoftwareRenderer.cpp \ TexturesRenderer.cpp \ WaterRenderer.cpp \ RenderArea.cpp \ - RayCastingManager.cpp + RayCastingManager.cpp \ + NightSky.cpp HEADERS += SoftwareRenderer.h\ software_global.h \ @@ -60,7 +61,8 @@ HEADERS += SoftwareRenderer.h\ TexturesRenderer.h \ WaterRenderer.h \ RenderArea.h \ - RayCastingManager.h + RayCastingManager.h \ + NightSky.h unix:!symbian { maemo5 { diff --git a/src/render/software/software_global.h b/src/render/software/software_global.h index f14bf27..a7f2c68 100644 --- a/src/render/software/software_global.h +++ b/src/render/software/software_global.h @@ -40,6 +40,8 @@ namespace software { class LightStatus; class LightFilter; class LightComponent; + + class NightSky; } }