paysages: Fog has been refactored in an 'atmosphere' module.
git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@235 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
parent
932693a24d
commit
1e922ccbce
10 changed files with 178 additions and 65 deletions
2
TODO
2
TODO
|
@ -1,6 +1,6 @@
|
||||||
- Refactor fog in a new 'atmosphere' module.
|
- Refactor fog in a new 'atmosphere' module.
|
||||||
|
- Make multi-lights work, to restore lighting from skydome.
|
||||||
- In GUI, revertConfig should lock the previews while reverting.
|
- In GUI, revertConfig should lock the previews while reverting.
|
||||||
- All Save and Load methods should have same signature : void ...Save(FILE*, ...*)
|
- All Save and Load methods should have same signature : void ...Save(FILE*, ...*)
|
||||||
- All noises should use the same entropy pool (saved separately), and avoid reallocs.
|
- All noises should use the same entropy pool (saved separately), and avoid reallocs.
|
||||||
- Remove all global variables (render_quality, render_width...), it should all be set in Renderer.
|
- Remove all global variables (render_quality, render_width...), it should all be set in Renderer.
|
||||||
- Make multi-lights work, to restore lighting from skydome.
|
|
||||||
|
|
100
lib_paysages/atmosphere.c
Normal file
100
lib_paysages/atmosphere.c
Normal file
|
@ -0,0 +1,100 @@
|
||||||
|
#include "atmosphere.h"
|
||||||
|
#include "shared/functions.h"
|
||||||
|
#include "shared/constants.h"
|
||||||
|
#include "scenery.h"
|
||||||
|
|
||||||
|
void atmosphereInit()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void atmosphereSave(FILE* f, AtmosphereDefinition* definition)
|
||||||
|
{
|
||||||
|
toolsSaveDouble(f, definition->distance_near);
|
||||||
|
toolsSaveDouble(f, definition->distance_far);
|
||||||
|
toolsSaveDouble(f, definition->full_mask);
|
||||||
|
toolsSaveInt(f, definition->auto_lock_on_haze);
|
||||||
|
colorSave(definition->color, f);
|
||||||
|
}
|
||||||
|
|
||||||
|
void atmosphereLoad(FILE* f, AtmosphereDefinition* definition)
|
||||||
|
{
|
||||||
|
definition->distance_near = toolsLoadDouble(f);
|
||||||
|
definition->distance_far = toolsLoadDouble(f);
|
||||||
|
definition->full_mask = toolsLoadDouble(f);
|
||||||
|
definition->auto_lock_on_haze = toolsLoadInt(f);
|
||||||
|
definition->color = colorLoad(f);
|
||||||
|
|
||||||
|
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);
|
||||||
|
definition->color = colorGradationGet(&sky.haze_color, sky.daytime);
|
||||||
|
skyDeleteDefinition(&sky);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Color atmosphereApply(AtmosphereDefinition* definition, Renderer* renderer, Vector3 location, Color base)
|
||||||
|
{
|
||||||
|
Color mask = definition->color;
|
||||||
|
double distance = v3Norm(v3Sub(renderer->camera_location, location));
|
||||||
|
double value;
|
||||||
|
|
||||||
|
if (distance < definition->distance_near)
|
||||||
|
{
|
||||||
|
return base;
|
||||||
|
}
|
||||||
|
else if (distance > definition->distance_far)
|
||||||
|
{
|
||||||
|
distance = definition->distance_far;
|
||||||
|
}
|
||||||
|
|
||||||
|
value = definition->full_mask * (distance - definition->distance_near) / (definition->distance_far - definition->distance_near);
|
||||||
|
mask.a = value;
|
||||||
|
|
||||||
|
colorMask(&base, &mask);
|
||||||
|
|
||||||
|
return base;
|
||||||
|
}
|
36
lib_paysages/atmosphere.h
Normal file
36
lib_paysages/atmosphere.h
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
#ifndef _PAYSAGES_ATMOSPHERE_H_
|
||||||
|
#define _PAYSAGES_ATMOSPHERE_H_
|
||||||
|
|
||||||
|
#include "shared/types.h"
|
||||||
|
#include "lighting.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
double distance_near;
|
||||||
|
double distance_far;
|
||||||
|
double full_mask;
|
||||||
|
int auto_lock_on_haze;
|
||||||
|
Color color;
|
||||||
|
} AtmosphereDefinition;
|
||||||
|
|
||||||
|
void atmosphereInit();
|
||||||
|
void atmosphereSave(FILE* f, AtmosphereDefinition* definition);
|
||||||
|
void atmosphereLoad(FILE* f, AtmosphereDefinition* definition);
|
||||||
|
|
||||||
|
AtmosphereDefinition atmosphereCreateDefinition();
|
||||||
|
void atmosphereDeleteDefinition(AtmosphereDefinition* definition);
|
||||||
|
void atmosphereCopyDefinition(AtmosphereDefinition* source, AtmosphereDefinition* destination);
|
||||||
|
void atmosphereValidateDefinition(AtmosphereDefinition* definition);
|
||||||
|
|
||||||
|
Color atmosphereApply(AtmosphereDefinition* definition, Renderer* renderer, Vector3 location, Color base);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
|
@ -57,12 +57,11 @@ void autoSetDaytimeFraction(double daytime)
|
||||||
sky.daytime = daytime;
|
sky.daytime = daytime;
|
||||||
scenerySetSky(&sky);
|
scenerySetSky(&sky);
|
||||||
skyDeleteDefinition(&sky);
|
skyDeleteDefinition(&sky);
|
||||||
|
|
||||||
fogSetColor(colorGradationGet(&sky.haze_color, daytime));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void autoGenRealisticLandscape(int seed)
|
void autoGenRealisticLandscape(int seed)
|
||||||
{
|
{
|
||||||
|
AtmosphereDefinition atmosphere;
|
||||||
TerrainDefinition terrain;
|
TerrainDefinition terrain;
|
||||||
WaterDefinition water;
|
WaterDefinition water;
|
||||||
CloudsDefinition clouds;
|
CloudsDefinition clouds;
|
||||||
|
@ -217,8 +216,14 @@ void autoGenRealisticLandscape(int seed)
|
||||||
scenerySetTextures(&textures);
|
scenerySetTextures(&textures);
|
||||||
texturesDeleteDefinition(&textures);
|
texturesDeleteDefinition(&textures);
|
||||||
|
|
||||||
/* Fog */
|
/* Atmosphere */
|
||||||
fogSetDistance(20.0, 100.0);
|
atmosphere = atmosphereCreateDefinition();
|
||||||
|
atmosphere.distance_near = 20.0;
|
||||||
|
atmosphere.distance_far = 100.0;
|
||||||
|
atmosphere.full_mask = 0.6;
|
||||||
|
atmosphere.auto_lock_on_haze = 1;
|
||||||
|
scenerySetAtmosphere(&atmosphere);
|
||||||
|
atmosphereDeleteDefinition(&atmosphere);
|
||||||
}
|
}
|
||||||
|
|
||||||
void* _renderFirstPass(void* data)
|
void* _renderFirstPass(void* data)
|
||||||
|
|
|
@ -454,6 +454,9 @@ Color cloudsGetLayerColor(CloudsLayerDefinition* definition, Renderer* renderer,
|
||||||
col.a = (segments[i].length >= 50.0) ? 1.0 : (segments[i].length / 50.0);
|
col.a = (segments[i].length >= 50.0) ? 1.0 : (segments[i].length / 50.0);
|
||||||
colorMask(&result, &col);
|
colorMask(&result, &col);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
result = renderer->applyAtmosphere(renderer, start, result);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,51 +0,0 @@
|
||||||
#include "shared/types.h"
|
|
||||||
#include "shared/functions.h"
|
|
||||||
#include "shared/globals.h"
|
|
||||||
#include "shared/constants.h"
|
|
||||||
|
|
||||||
static double _near = 0.0, _far = 1.0;
|
|
||||||
static Color _col = {0.0, 0.0, 0.0, 0.0};
|
|
||||||
|
|
||||||
void fogSave(FILE* f)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void fogLoad(FILE* f)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void fogSetColor(Color col)
|
|
||||||
{
|
|
||||||
_col = col;
|
|
||||||
}
|
|
||||||
|
|
||||||
void fogSetDistance(double near, double far)
|
|
||||||
{
|
|
||||||
_near = near;
|
|
||||||
_far = far;
|
|
||||||
}
|
|
||||||
|
|
||||||
Color fogApplyToLocation(Vector3 location, Color base)
|
|
||||||
{
|
|
||||||
return base;
|
|
||||||
// TODO Don't use camera_location
|
|
||||||
/*Color mask = _col;
|
|
||||||
double distance = v3Norm(v3Sub(camera_location, location));
|
|
||||||
double value;
|
|
||||||
|
|
||||||
if (distance < _near)
|
|
||||||
{
|
|
||||||
return base;
|
|
||||||
}
|
|
||||||
else if (distance > _far)
|
|
||||||
{
|
|
||||||
distance = _far;
|
|
||||||
}
|
|
||||||
|
|
||||||
value = 0.8 * (distance - _near) / (_far - _near);
|
|
||||||
|
|
||||||
mask.a *= value;
|
|
||||||
colorMask(&base, &mask);
|
|
||||||
return base;*/
|
|
||||||
}
|
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include "system.h"
|
#include "system.h"
|
||||||
#include "render.h"
|
#include "render.h"
|
||||||
|
|
||||||
|
AtmosphereDefinition _atmosphere;
|
||||||
CameraDefinition _camera;
|
CameraDefinition _camera;
|
||||||
CloudsDefinition _clouds;
|
CloudsDefinition _clouds;
|
||||||
LightingDefinition _lighting;
|
LightingDefinition _lighting;
|
||||||
|
@ -15,6 +16,7 @@ WaterDefinition _water;
|
||||||
|
|
||||||
void sceneryInit()
|
void sceneryInit()
|
||||||
{
|
{
|
||||||
|
atmosphereInit();
|
||||||
cameraInit();
|
cameraInit();
|
||||||
cloudsInit();
|
cloudsInit();
|
||||||
lightingInit();
|
lightingInit();
|
||||||
|
@ -23,6 +25,7 @@ void sceneryInit()
|
||||||
texturesInit();
|
texturesInit();
|
||||||
waterInit();
|
waterInit();
|
||||||
|
|
||||||
|
_atmosphere = atmosphereCreateDefinition();
|
||||||
_camera = cameraCreateDefinition();
|
_camera = cameraCreateDefinition();
|
||||||
_clouds = cloudsCreateDefinition();
|
_clouds = cloudsCreateDefinition();
|
||||||
_lighting = lightingCreateDefinition();
|
_lighting = lightingCreateDefinition();
|
||||||
|
@ -36,6 +39,7 @@ void scenerySaveToFile(char* filepath)
|
||||||
{
|
{
|
||||||
FILE* f = fopen(filepath, "wb");
|
FILE* f = fopen(filepath, "wb");
|
||||||
|
|
||||||
|
atmosphereSave(f, &_atmosphere);
|
||||||
cameraSave(f, &_camera);
|
cameraSave(f, &_camera);
|
||||||
cloudsSave(f, &_clouds);
|
cloudsSave(f, &_clouds);
|
||||||
lightingSave(f, &_lighting);
|
lightingSave(f, &_lighting);
|
||||||
|
@ -53,6 +57,9 @@ void sceneryLoadFromFile(char* filepath)
|
||||||
|
|
||||||
/* TODO Use intermediary definitions ? */
|
/* TODO Use intermediary definitions ? */
|
||||||
|
|
||||||
|
atmosphereLoad(f, &_atmosphere);
|
||||||
|
atmosphereValidateDefinition(&_atmosphere);
|
||||||
|
|
||||||
cameraLoad(f, &_camera);
|
cameraLoad(f, &_camera);
|
||||||
cameraValidateDefinition(&_camera);
|
cameraValidateDefinition(&_camera);
|
||||||
|
|
||||||
|
@ -77,6 +84,17 @@ void sceneryLoadFromFile(char* filepath)
|
||||||
fclose(f);
|
fclose(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void scenerySetAtmosphere(AtmosphereDefinition* atmosphere)
|
||||||
|
{
|
||||||
|
atmosphereCopyDefinition(atmosphere, &_atmosphere);
|
||||||
|
atmosphereValidateDefinition(&_atmosphere);
|
||||||
|
}
|
||||||
|
|
||||||
|
void sceneryGetAtmosphere(AtmosphereDefinition* atmosphere)
|
||||||
|
{
|
||||||
|
atmosphereCopyDefinition(&_atmosphere, atmosphere);
|
||||||
|
}
|
||||||
|
|
||||||
void scenerySetCamera(CameraDefinition* camera)
|
void scenerySetCamera(CameraDefinition* camera)
|
||||||
{
|
{
|
||||||
cameraCopyDefinition(camera, &_camera);
|
cameraCopyDefinition(camera, &_camera);
|
||||||
|
@ -115,6 +133,7 @@ void scenerySetSky(SkyDefinition* sky)
|
||||||
skyCopyDefinition(sky, &_sky);
|
skyCopyDefinition(sky, &_sky);
|
||||||
skyValidateDefinition(&_sky);
|
skyValidateDefinition(&_sky);
|
||||||
|
|
||||||
|
atmosphereValidateDefinition(&_atmosphere);
|
||||||
lightingValidateDefinition(&_lighting);
|
lightingValidateDefinition(&_lighting);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -230,7 +249,7 @@ static Color _applyTextures(Renderer* renderer, Vector3 location, double precisi
|
||||||
|
|
||||||
static Color _applyAtmosphere(Renderer* renderer, Vector3 location, Color base)
|
static Color _applyAtmosphere(Renderer* renderer, Vector3 location, Color base)
|
||||||
{
|
{
|
||||||
return fogApplyToLocation(location, base);
|
return atmosphereApply(&_atmosphere, renderer, location, base);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Color _applyClouds(Renderer* renderer, Color base, Vector3 start, Vector3 end)
|
static Color _applyClouds(Renderer* renderer, Color base, Vector3 start, Vector3 end)
|
||||||
|
@ -268,6 +287,9 @@ Renderer sceneryGetStandardRenderer(int quality)
|
||||||
{
|
{
|
||||||
Renderer result;
|
Renderer result;
|
||||||
|
|
||||||
|
quality = (quality > 10) ? 10 : quality;
|
||||||
|
quality = (quality < 1) ? 1 : quality;
|
||||||
|
|
||||||
result.camera_location = _camera.location;
|
result.camera_location = _camera.location;
|
||||||
result.render_quality = quality;
|
result.render_quality = quality;
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
* a standard renderer.
|
* a standard renderer.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "atmosphere.h"
|
||||||
#include "camera.h"
|
#include "camera.h"
|
||||||
#include "clouds.h"
|
#include "clouds.h"
|
||||||
#include "lighting.h"
|
#include "lighting.h"
|
||||||
|
@ -26,6 +27,9 @@ void sceneryInit();
|
||||||
void scenerySaveToFile(char* filepath);
|
void scenerySaveToFile(char* filepath);
|
||||||
void sceneryLoadFromFile(char* filepath);
|
void sceneryLoadFromFile(char* filepath);
|
||||||
|
|
||||||
|
void scenerySetAtmosphere(AtmosphereDefinition* atmosphere);
|
||||||
|
void sceneryGetAtmosphere(AtmosphereDefinition* atmosphere);
|
||||||
|
|
||||||
void scenerySetCamera(CameraDefinition* camera);
|
void scenerySetCamera(CameraDefinition* camera);
|
||||||
void sceneryGetCamera(CameraDefinition* camera);
|
void sceneryGetCamera(CameraDefinition* camera);
|
||||||
|
|
||||||
|
|
|
@ -70,13 +70,6 @@ Matrix4 m4NewPerspective(double fov_y, double aspect, double near, double far);
|
||||||
double m4Determinant(Matrix4 m);
|
double m4Determinant(Matrix4 m);
|
||||||
Matrix4 m4Inverse(Matrix4 m);
|
Matrix4 m4Inverse(Matrix4 m);
|
||||||
|
|
||||||
/* fog.c */
|
|
||||||
void fogSave(FILE* f);
|
|
||||||
void fogLoad(FILE* f);
|
|
||||||
void fogSetColor(Color col);
|
|
||||||
void fogSetDistance(double near, double far);
|
|
||||||
Color fogApplyToLocation(Vector3 location, Color base);
|
|
||||||
|
|
||||||
/* tools.c */
|
/* tools.c */
|
||||||
double toolsRandom();
|
double toolsRandom();
|
||||||
double toolsBicubicInterpolate(double stencil[16], double x, double y);
|
double toolsBicubicInterpolate(double stencil[16], double x, double y);
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
#include "sky.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
|
@ -7,7 +9,6 @@
|
||||||
#include "shared/constants.h"
|
#include "shared/constants.h"
|
||||||
#include "render.h"
|
#include "render.h"
|
||||||
#include "clouds.h"
|
#include "clouds.h"
|
||||||
#include "sky.h"
|
|
||||||
#include "lighting.h"
|
#include "lighting.h"
|
||||||
|
|
||||||
#define SPHERE_SIZE 1000.0
|
#define SPHERE_SIZE 1000.0
|
||||||
|
|
Loading…
Reference in a new issue