2012-12-24 15:15:40 +00:00
|
|
|
#include "private.h"
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include "../renderer.h"
|
|
|
|
|
|
|
|
Color basicApplyAerialPerspective(Renderer* renderer, Vector3 location, Color base)
|
|
|
|
{
|
|
|
|
Vector3 direction = v3Sub(location, renderer->camera_location);
|
|
|
|
double distance = v3Norm(direction);
|
|
|
|
AtmosphereDefinition* definition = renderer->atmosphere->definition;
|
|
|
|
double near = 10.0 - definition->humidity * 10.0;
|
2013-01-20 21:17:03 +00:00
|
|
|
double far = 500.0 - definition->humidity * 480.0;
|
2012-12-30 16:06:11 +00:00
|
|
|
double max = 0.75 + definition->humidity * 0.22;
|
2012-12-24 15:15:40 +00:00
|
|
|
|
|
|
|
assert(near < far);
|
|
|
|
|
|
|
|
if (distance < near)
|
|
|
|
{
|
|
|
|
return base;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (distance > far)
|
|
|
|
{
|
|
|
|
distance = far;
|
|
|
|
}
|
|
|
|
double factor = (distance - near) / (far - near);
|
|
|
|
|
|
|
|
/* TODO Get sky color without celestial objects (sun, stars...) */
|
|
|
|
double angle = (1.0 - factor) * (1.0 - factor) * (1.0 - factor) * (1.0 - factor) * M_PI_4;
|
|
|
|
direction = v3Normalize(direction);
|
|
|
|
direction.y = sin(angle);
|
|
|
|
Color sky = renderer->atmosphere->getSkyColor(renderer, v3Normalize(direction));
|
|
|
|
|
|
|
|
sky.a = max * factor;
|
|
|
|
colorMask(&base, &sky);
|
|
|
|
|
|
|
|
return base;
|
|
|
|
}
|
|
|
|
}
|
2013-01-19 22:42:50 +00:00
|
|
|
|
|
|
|
void basicGetLightingStatus(Renderer* renderer, LightStatus* status, Vector3 normal, int opaque)
|
|
|
|
{
|
|
|
|
/* Direct light from the sun */
|
|
|
|
LightDefinition light;
|
|
|
|
|
|
|
|
light.direction = v3Scale(renderer->atmosphere->getSunDirection(renderer), -1.0);
|
|
|
|
light.color = renderer->atmosphere->definition->sun_color;
|
2013-01-20 15:07:45 +00:00
|
|
|
/*light.color.r *= 100.0;
|
|
|
|
light.color.g *= 100.0;
|
|
|
|
light.color.b *= 100.0;*/
|
2013-01-19 22:42:50 +00:00
|
|
|
light.reflection = 1.0;
|
2013-01-20 15:07:45 +00:00
|
|
|
light.altered = 1;
|
2013-01-19 22:42:50 +00:00
|
|
|
lightingPushLight(status, &light);
|
|
|
|
|
|
|
|
/* TODO Sample other directions */
|
|
|
|
}
|