Added basic night sky with a plain moon

This commit is contained in:
Michaël Lemaire 2013-12-26 15:36:15 +01:00 committed by Michael Lemaire
parent 0ebdff628b
commit 6589589ad4
8 changed files with 113 additions and 7 deletions

View file

@ -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; double yoffset = GROUND_OFFSET - parent->getWaterRenderer()->getHeightInfo().base_height;
eye.y += yoffset; eye.y += yoffset;
@ -1177,7 +1177,7 @@ AtmosphereResult AtmosphereModelBruneton::getSkyColor(Vector3 eye, const Vector3
/*result.base.r = base.r + sunColor.r; /*result.base.r = base.r + sunColor.r;
result.base.g = base.g + sunColor.g; result.base.g = base.g + sunColor.g;
result.base.b = base.b + sunColor.b;*/ 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 */ result.inscattering = _getInscatterColor(&x, &t, v, s, &r, &mu, &attenuation); /* S[L]-T(x,xs)S[l]|xs */
/* TODO Use atmosphere attenuation */ /* TODO Use atmosphere attenuation */
result.distance = SPHERE_SIZE; result.distance = SPHERE_SIZE;

View file

@ -8,6 +8,7 @@
#include "LightComponent.h" #include "LightComponent.h"
#include "LightStatus.h" #include "LightStatus.h"
#include "Scenery.h" #include "Scenery.h"
#include "NightSky.h"
/* Factor to convert software units to kilometers */ /* Factor to convert software units to kilometers */
#define WORLD_SCALING 0.05 #define WORLD_SCALING 0.05
@ -207,8 +208,12 @@ AtmosphereResult SoftwareBrunetonAtmosphereRenderer::getSkyColor(Vector3 directi
direction = direction.normalize(); direction = direction.normalize();
sun_position = sun_direction.scale(SUN_DISTANCE_SCALED); sun_position = sun_direction.scale(SUN_DISTANCE_SCALED);
/* Get sun shape */
base = COLOR_BLACK; 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) /*if (v3Dot(sun_direction, direction) >= 0)
{ {
double sun_radius = definition->sun_radius * SUN_RADIUS_SCALED * 5.0; // FIXME Why should we multiply by 5 ? 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 */ /* Get scattering */
AtmosphereResult result; AtmosphereResult result;
Vector3 location = camera_location.add(direction.scale(6421.0)); Vector3 location = camera_location.add(direction.scale(6421.0));

View file

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

View file

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

View file

@ -14,6 +14,7 @@
#include "SkyRasterizer.h" #include "SkyRasterizer.h"
#include "TerrainRasterizer.h" #include "TerrainRasterizer.h"
#include "WaterRasterizer.h" #include "WaterRasterizer.h"
#include "NightSky.h"
#include "LightStatus.h" #include "LightStatus.h"
#include "LightingManager.h" #include "LightingManager.h"
#include "System.h" #include "System.h"
@ -39,6 +40,8 @@ SoftwareRenderer::SoftwareRenderer(Scenery* scenery)
textures_renderer = new TexturesRenderer(this); textures_renderer = new TexturesRenderer(this);
water_renderer = new WaterRenderer(this); water_renderer = new WaterRenderer(this);
nightsky_renderer = new NightSky(this);
fluid_medium = new FluidMediumManager(this); fluid_medium = new FluidMediumManager(this);
lighting = new LightingManager(); lighting = new LightingManager();
@ -61,6 +64,8 @@ SoftwareRenderer::~SoftwareRenderer()
delete fluid_medium; delete fluid_medium;
delete lighting; delete lighting;
delete nightsky_renderer;
delete atmosphere_renderer; delete atmosphere_renderer;
delete clouds_renderer; delete clouds_renderer;
delete terrain_renderer; delete terrain_renderer;
@ -96,6 +101,8 @@ void SoftwareRenderer::prepare()
water_renderer->update(); water_renderer->update();
textures_renderer->update(); textures_renderer->update();
nightsky_renderer->update();
// Prepare global tools // Prepare global tools
fluid_medium->clearMedia(); fluid_medium->clearMedia();
//fluid_medium->registerMedium(water_renderer); //fluid_medium->registerMedium(water_renderer);

View file

@ -90,6 +90,8 @@ public:
inline TexturesRenderer* getTexturesRenderer() const {return textures_renderer;} inline TexturesRenderer* getTexturesRenderer() const {return textures_renderer;}
inline WaterRenderer* getWaterRenderer() const {return water_renderer;} inline WaterRenderer* getWaterRenderer() const {return water_renderer;}
inline NightSky* getNightSky() const {return nightsky_renderer;}
inline FluidMediumManager* getFluidMediumManager() const {return fluid_medium;} inline FluidMediumManager* getFluidMediumManager() const {return fluid_medium;}
inline LightingManager* getLightingManager() const {return lighting;} inline LightingManager* getLightingManager() const {return lighting;}
@ -108,6 +110,7 @@ private:
TerrainRenderer* terrain_renderer; TerrainRenderer* terrain_renderer;
TexturesRenderer* textures_renderer; TexturesRenderer* textures_renderer;
WaterRenderer* water_renderer; WaterRenderer* water_renderer;
NightSky* nightsky_renderer;
}; };
} }

View file

@ -35,7 +35,8 @@ SOURCES += SoftwareRenderer.cpp \
TexturesRenderer.cpp \ TexturesRenderer.cpp \
WaterRenderer.cpp \ WaterRenderer.cpp \
RenderArea.cpp \ RenderArea.cpp \
RayCastingManager.cpp RayCastingManager.cpp \
NightSky.cpp
HEADERS += SoftwareRenderer.h\ HEADERS += SoftwareRenderer.h\
software_global.h \ software_global.h \
@ -60,7 +61,8 @@ HEADERS += SoftwareRenderer.h\
TexturesRenderer.h \ TexturesRenderer.h \
WaterRenderer.h \ WaterRenderer.h \
RenderArea.h \ RenderArea.h \
RayCastingManager.h RayCastingManager.h \
NightSky.h
unix:!symbian { unix:!symbian {
maemo5 { maemo5 {

View file

@ -40,6 +40,8 @@ namespace software {
class LightStatus; class LightStatus;
class LightFilter; class LightFilter;
class LightComponent; class LightComponent;
class NightSky;
} }
} }