2012-01-24 15:47:49 +00:00
|
|
|
#include "atmosphere.h"
|
2012-01-29 17:39:56 +00:00
|
|
|
|
2012-01-24 15:47:49 +00:00
|
|
|
#include "scenery.h"
|
2012-01-29 17:39:56 +00:00
|
|
|
#include "euclid.h"
|
|
|
|
#include "color.h"
|
|
|
|
#include "tools.h"
|
2012-01-24 15:47:49 +00:00
|
|
|
|
|
|
|
void atmosphereInit()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-02-12 16:57:29 +00:00
|
|
|
void atmosphereQuit()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-04-22 17:12:39 +00:00
|
|
|
void atmosphereSave(PackStream* stream, AtmosphereDefinition* definition)
|
2012-01-24 15:47:49 +00:00
|
|
|
{
|
2012-06-17 09:40:40 +00:00
|
|
|
packWriteDouble(stream, &definition->distance_near);
|
|
|
|
packWriteDouble(stream, &definition->distance_far);
|
|
|
|
packWriteDouble(stream, &definition->full_mask);
|
2012-04-22 17:12:39 +00:00
|
|
|
packWriteInt(stream, &definition->auto_lock_on_haze);
|
|
|
|
colorSave(stream, &definition->color);
|
2012-01-24 15:47:49 +00:00
|
|
|
}
|
|
|
|
|
2012-04-22 17:12:39 +00:00
|
|
|
void atmosphereLoad(PackStream* stream, AtmosphereDefinition* definition)
|
2012-01-24 15:47:49 +00:00
|
|
|
{
|
2012-06-17 09:40:40 +00:00
|
|
|
packReadDouble(stream, &definition->distance_near);
|
|
|
|
packReadDouble(stream, &definition->distance_far);
|
|
|
|
packReadDouble(stream, &definition->full_mask);
|
2012-04-22 17:12:39 +00:00
|
|
|
packReadInt(stream, &definition->auto_lock_on_haze);
|
|
|
|
colorLoad(stream, &definition->color);
|
2012-01-24 15:47:49 +00:00
|
|
|
|
|
|
|
atmosphereValidateDefinition(definition);
|
|
|
|
}
|
|
|
|
|
|
|
|
AtmosphereDefinition atmosphereCreateDefinition()
|
|
|
|
{
|
|
|
|
AtmosphereDefinition definition;
|
|
|
|
|
|
|
|
definition.distance_near = 0.0;
|
|
|
|
definition.distance_far = 1.0;
|
|
|
|
definition.full_mask = 0.0;
|
|
|
|
definition.auto_lock_on_haze = 0;
|
|
|
|
definition.color = COLOR_BLACK;
|
|
|
|
|
|
|
|
atmosphereValidateDefinition(&definition);
|
|
|
|
|
|
|
|
return definition;
|
|
|
|
}
|
|
|
|
|
|
|
|
void atmosphereDeleteDefinition(AtmosphereDefinition* definition)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void atmosphereCopyDefinition(AtmosphereDefinition* source, AtmosphereDefinition* destination)
|
|
|
|
{
|
|
|
|
*destination = *source;
|
|
|
|
}
|
|
|
|
|
|
|
|
void atmosphereValidateDefinition(AtmosphereDefinition* definition)
|
|
|
|
{
|
|
|
|
SkyDefinition sky;
|
|
|
|
|
|
|
|
if (definition->distance_far <= definition->distance_near)
|
|
|
|
{
|
|
|
|
definition->distance_far = definition->distance_near + 1.0;
|
|
|
|
}
|
|
|
|
if (definition->full_mask < 0.0)
|
|
|
|
{
|
|
|
|
definition->full_mask = 0.0;
|
|
|
|
}
|
|
|
|
if (definition->full_mask > 1.0)
|
|
|
|
{
|
|
|
|
definition->full_mask = 1.0;
|
|
|
|
}
|
|
|
|
if (definition->auto_lock_on_haze)
|
|
|
|
{
|
|
|
|
sky = skyCreateDefinition();
|
|
|
|
sceneryGetSky(&sky);
|
2012-06-24 12:33:59 +00:00
|
|
|
definition->color = skyGetHorizonColor(&sky);
|
2012-01-24 15:47:49 +00:00
|
|
|
skyDeleteDefinition(&sky);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Color atmosphereApply(AtmosphereDefinition* definition, Renderer* renderer, Vector3 location, Color base)
|
|
|
|
{
|
|
|
|
Color mask = definition->color;
|
2012-06-17 09:40:40 +00:00
|
|
|
double distance = v3Norm(v3Sub(renderer->camera_location, location));
|
|
|
|
double value;
|
2012-06-17 16:27:01 +00:00
|
|
|
double alpha;
|
2012-01-24 15:47:49 +00:00
|
|
|
|
|
|
|
if (distance < definition->distance_near)
|
|
|
|
{
|
|
|
|
return base;
|
|
|
|
}
|
|
|
|
else if (distance > definition->distance_far)
|
|
|
|
{
|
|
|
|
distance = definition->distance_far;
|
|
|
|
}
|
|
|
|
|
2012-06-17 16:27:01 +00:00
|
|
|
alpha = base.a;
|
|
|
|
base.a = 1.0;
|
|
|
|
|
2012-01-24 15:47:49 +00:00
|
|
|
value = definition->full_mask * (distance - definition->distance_near) / (definition->distance_far - definition->distance_near);
|
2012-06-17 16:27:01 +00:00
|
|
|
|
2012-01-24 15:47:49 +00:00
|
|
|
mask.a = value;
|
|
|
|
colorMask(&base, &mask);
|
2012-06-17 16:27:01 +00:00
|
|
|
|
|
|
|
base.a = alpha;
|
2012-01-24 15:47:49 +00:00
|
|
|
|
|
|
|
return base;
|
|
|
|
}
|