Added moon basic lighting

This commit is contained in:
Michaël Lemaire 2013-12-26 16:35:29 +01:00 committed by Michael Lemaire
parent 6589589ad4
commit d2f49a124f
3 changed files with 30 additions and 6 deletions

View file

@ -1254,7 +1254,14 @@ void AtmosphereModelBruneton::fillLightingStatus(LightStatus *status, const Vect
Vector3 s = sun_position.sub(x).normalize(); Vector3 s = sun_position.sub(x).normalize();
muS = up.dotProduct(s); muS = up.dotProduct(s);
if (altitude * WORLD_SCALING > RL)
{
sun.color = parent->getScenery()->getAtmosphere()->sun_color;
}
else
{
sun.color = _transmittanceWithShadow(r0, muS); sun.color = _transmittanceWithShadow(r0, muS);
}
sun.direction = s.scale(-1.0); sun.direction = s.scale(-1.0);
sun.reflection = ISun; sun.reflection = ISun;
sun.altered = 1; sun.altered = 1;

View file

@ -3,6 +3,14 @@
#include "Color.h" #include "Color.h"
#include "Vector3.h" #include "Vector3.h"
#include "Geometry.h" #include "Geometry.h"
#include "SoftwareRenderer.h"
#include "SurfaceMaterial.h"
#define WORLD_SCALING 0.05
#define MOON_DISTANCE 384403.0
#define MOON_DISTANCE_SCALED (MOON_DISTANCE / WORLD_SCALING)
#define MOON_RADIUS 1737.4
#define MOON_RADIUS_SCALED (MOON_RADIUS / WORLD_SCALING)
NightSky::NightSky(SoftwareRenderer* renderer): NightSky::NightSky(SoftwareRenderer* renderer):
renderer(renderer) renderer(renderer)
@ -26,19 +34,22 @@ const Color NightSky::getColor(double altitude, const Vector3 &direction)
// Get stars // Get stars
// Get moon // Get moon
Vector3 moon_direction(0.3, 0.4, -0.3); Vector3 moon_direction = Vector3(0.9, 0.5, -0.6).normalize();
moon_direction.normalize();
if (moon_direction.dotProduct(direction) >= 0) if (moon_direction.dotProduct(direction) >= 0)
{ {
Vector3 moon_position = moon_direction.scale(100.0); Vector3 moon_position = moon_direction.scale(MOON_DISTANCE_SCALED);
double moon_radius = 1.0; double moon_radius = MOON_RADIUS_SCALED * 5.0;
Vector3 hit1, hit2; Vector3 hit1, hit2;
int hits = Geometry::rayIntersectSphere(location, direction, moon_position, moon_radius, &hit1, &hit2); int hits = Geometry::rayIntersectSphere(location, direction, moon_position, moon_radius, &hit1, &hit2);
if (hits > 1) if (hits > 1)
{ {
double dist = hit2.sub(hit1).getNorm() / moon_radius; // distance between intersection points (relative to radius) double dist = hit2.sub(hit1).getNorm() / moon_radius; // distance between intersection points (relative to radius)
Color moon_color(0.3, 0.3, 0.3); Vector3 nearest = (hit1.sub(location).getNorm() > hit2.sub(location).getNorm()) ? hit2 : hit1;
SurfaceMaterial moon_material(Color(3.0, 3.0, 3.0, 1.0));
moon_material.validate();
Color moon_color = renderer->applyLightingToSurface(nearest, nearest.sub(moon_position).normalize(), moon_material);
if (dist <= 0.05) if (dist <= 0.05)
{ {
moon_color.a *= 1.0 - dist / 0.05; moon_color.a *= 1.0 - dist / 0.05;

View file

@ -192,6 +192,12 @@ bool TerrainRenderer::applyLightFilter(LightComponent &light, const Vector3 &at)
Vector3 inc_vector, direction_to_light, cursor; Vector3 inc_vector, direction_to_light, cursor;
double inc_value, inc_base, inc_factor, height, diff, light_factor, smoothing, length; double inc_value, inc_base, inc_factor, height, diff, light_factor, smoothing, length;
if (at.y > definition->getHeightInfo().max_height)
{
// Location is above terrain, don't bother
return true;
}
direction_to_light = light.direction.scale(-1.0); direction_to_light = light.direction.scale(-1.0);
if (direction_to_light.y < -0.05) if (direction_to_light.y < -0.05)
{ {