paysages : Lighting refactoring (WIP).

git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@500 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
Michaël Lemaire 2013-01-19 22:42:50 +00:00 committed by ThunderK
parent dd0fceb5c9
commit b46060f3c4
80 changed files with 478 additions and 892 deletions

View file

@ -30,6 +30,7 @@ Clouds :
Rendering :
* Added full scene antialiasing (FSAA).
* High Dynamic Range lighting.
GUI :
* Improved curve rendering.

1
TODO
View file

@ -5,6 +5,7 @@ Technology Preview 2 :
=> Add map preview with editor area.
=> Allow camera move and zoom.
- Get rid of noise dialogs, for simpler settings.
- Apply HDR to 3D explorer.
- Apply Preetham's model usage
=> Convert to HDR rendering.
=> Apply model's aerial perspective.

View file

@ -9,11 +9,11 @@
#include "baseinput.h"
#include "dialoglayers.h"
#include "../lib_paysages/shared/types.h"
#include "../lib_paysages/tools/curve.h"
#include "../lib_paysages/tools/color.h"
#include "../lib_paysages/tools/pack.h"
#include "../lib_paysages/noise.h"
#include "../lib_paysages/curve.h"
#include "../lib_paysages/color.h"
#include "../lib_paysages/layers.h"
#include "../lib_paysages/pack.h"
class BaseForm:public QWidget
{

View file

@ -10,7 +10,7 @@
#include <QLabel>
#include <QHash>
#include "previewosd.h"
#include "../lib_paysages/pack.h"
#include "../lib_paysages/tools/pack.h"
class _ContextChoice
{

View file

@ -6,8 +6,8 @@
#include "widgetcurveeditor.h"
#include "previewcolorgradation.h"
#include "../lib_paysages/color.h"
#include "../lib_paysages/curve.h"
#include "../lib_paysages/tools/color.h"
#include "../lib_paysages/tools/curve.h"
class DialogColorGradation : public QDialog
{

View file

@ -5,7 +5,7 @@
#include <QPushButton>
#include "widgetcurveeditor.h"
#include "../lib_paysages/curve.h"
#include "../lib_paysages/tools/curve.h"
class DialogCurve : public QDialog
{

View file

@ -10,7 +10,7 @@
#include <QScrollArea>
#include <QPushButton>
#include <math.h>
#include "../lib_paysages/color.h"
#include "../lib_paysages/tools/color.h"
/**************** Previews ****************/
class PreviewLevel:public BasePreview

View file

@ -9,7 +9,7 @@
#include <QLabel>
#include <QMutex>
#include "../lib_paysages/renderer.h"
#include "../lib_paysages/color.h"
#include "../lib_paysages/tools/color.h"
class DialogRender : public QDialog
{

View file

@ -3,7 +3,7 @@
#include "baseexplorerchunk.h"
#include "../lib_paysages/renderer.h"
#include "../lib_paysages/euclid.h"
#include "../lib_paysages/tools/euclid.h"
enum SkyboxOrientation
{

View file

@ -3,7 +3,7 @@
#include "baseexplorerchunk.h"
#include "../lib_paysages/renderer.h"
#include "../lib_paysages/euclid.h"
#include "../lib_paysages/tools/euclid.h"
class ExplorerChunkTerrain:public BaseExplorerChunk
{

View file

@ -1,8 +1,8 @@
#include "formclouds.h"
#include "../lib_paysages/clouds.h"
#include "../lib_paysages/color.h"
#include "../lib_paysages/euclid.h"
#include "../lib_paysages/tools/color.h"
#include "../lib_paysages/tools/euclid.h"
#include "../lib_paysages/scenery.h"
#include "tools.h"
@ -15,7 +15,7 @@ public:
{
_renderer = rendererCreate();
_renderer.render_quality = 5;
_renderer.applyLightStatus = _applyLightStatus;
//_renderer.applyLightStatus = _applyLightStatus;
_original_layer = layer;
_preview_layer = cloudsLayerCreateDefinition();
@ -66,7 +66,7 @@ public:
_original_layer = layer;
_preview_layer = cloudsLayerCreateDefinition();
_lighting = lightingCreateDefinition();
/*_lighting = lightingCreateDefinition();
light.color = COLOR_WHITE;
light.direction.x = -1.0;
light.direction.y = -1.0;
@ -76,14 +76,14 @@ public:
light.masked = 1;
light.reflection = 1.0;
lightingAddLight(&_lighting, light);
lightingValidateDefinition(&_lighting);
lightingValidateDefinition(&_lighting);*/
_renderer = rendererCreate();
_renderer.render_quality = 8;
_renderer.alterLight = _alterLight;
_renderer.getLightStatus = _getLightStatus;
/*_renderer.alterLight = _alterLight;
_renderer.getLightStatus = _getLightStatus;*/
_renderer.customData[0] = _preview_layer;
_renderer.customData[1] = &_lighting;
//_renderer.customData[1] = &_lighting;
configScaling(0.5, 2.0, 0.1, 2.0);
}
@ -115,7 +115,7 @@ private:
Renderer _renderer;
CloudsLayerDefinition* _original_layer;
CloudsLayerDefinition* _preview_layer;
LightingDefinition _lighting;
//LightingDefinition _lighting;
static double _coverageFunc(CloudsLayerDefinition* layer, Vector3 position)
{
@ -138,7 +138,7 @@ private:
}
}
static void _alterLight(Renderer* renderer, LightDefinition* light, Vector3 location)
/*static void _alterLight(Renderer* renderer, LightDefinition* light, Vector3 location)
{
light->color = cloudsLayerFilterLight((CloudsLayerDefinition*)renderer->customData[0], renderer, light->color, location, v3Scale(light->direction, -1000.0), v3Scale(light->direction, -1.0));
}
@ -146,7 +146,7 @@ private:
static void _getLightStatus(Renderer* renderer, LightStatus* status, Vector3 location)
{
lightingGetStatus((LightingDefinition*)renderer->customData[1], renderer, location, status);
}
}*/
};
/**************** Form ****************/

View file

@ -1,44 +0,0 @@
#include "formlighting.h"
#include "../lib_paysages/lighting.h"
#include "../lib_paysages/scenery.h"
static LightingDefinition _definition;
/**************** Previews ****************/
/**************** Form ****************/
FormLighting::FormLighting(QWidget *parent):
BaseForm(parent)
{
_definition = lightingCreateDefinition();
/*previewHeight = new PreviewTerrainHeight(this);
previewColor = new PreviewTerrainColor(this);
addPreview(previewHeight, QString("Height preview (normalized)"));
addPreview(previewColor, QString("Textured preview (no shadow)"));*/
/*addInputNoise("Noise", _definition.height_noise);
addInputDouble("Height", &_definition.height_factor, 0.0, 20.0, 0.1, 1.0);
addInputDouble("Scaling", &_definition.scaling, 1.0, 20.0, 0.1, 1.0);*/
revertConfig();
}
void FormLighting::revertConfig()
{
sceneryGetLighting(&_definition);
BaseForm::revertConfig();
}
void FormLighting::applyConfig()
{
scenerySetLighting(&_definition);
BaseForm::applyConfig();
}
void FormLighting::configChangeEvent()
{
lightingValidateDefinition(&_definition);
BaseForm::configChangeEvent();
}

View file

@ -1,26 +0,0 @@
#ifndef _PAYSAGES_QT_FORMLIGHTING_H_
#define _PAYSAGES_QT_FORMLIGHTING_H_
#include <QWidget>
#include "basepreview.h"
#include "baseform.h"
class FormLighting : public BaseForm
{
Q_OBJECT
public:
explicit FormLighting(QWidget *parent = 0);
public slots:
virtual void revertConfig();
virtual void applyConfig();
protected slots:
virtual void configChangeEvent();
private:
BasePreview* previewColor;
};
#endif

View file

@ -16,13 +16,11 @@ public:
{
_renderer = rendererCreate();
_renderer.applyTextures = _applyTextures;
_renderer.getLightStatus = _getLightStatus;
_renderer.camera_location.x = 0.0;
_renderer.camera_location.y = 50.0;
_renderer.camera_location.z = 0.0;
_textures = texturesCreateDefinition();
_lighting = lightingCreateDefinition();
_water = waterCreateDefinition();
_atmosphere = (AtmosphereDefinition*)AtmosphereDefinitionClass.create();
@ -30,7 +28,6 @@ public:
_renderer.customData[0] = &_terrain;
_renderer.customData[1] = &_textures;
_renderer.customData[2] = &_lighting;
_renderer.customData[3] = &_water;
addOsd(QString("geolocation"));
@ -62,7 +59,6 @@ protected:
}
void updateData()
{
sceneryGetLighting(&_lighting);
sceneryGetTextures(&_textures);
sceneryGetWater(&_water);
@ -78,7 +74,6 @@ private:
TerrainDefinition* _terrain;
WaterDefinition _water;
TexturesDefinition _textures;
LightingDefinition _lighting;
AtmosphereDefinition* _atmosphere;
static Color _applyTextures(Renderer* renderer, Vector3 location, double precision)
@ -86,11 +81,6 @@ private:
return texturesGetColor((TexturesDefinition*)(renderer->customData[1]), renderer, location.x, location.z, precision);
}
static void _getLightStatus(Renderer* renderer, LightStatus* status, Vector3 location)
{
lightingGetStatus((LightingDefinition*)renderer->customData[2], renderer, location, status);
}
static Color _applyAerialPerspective(Renderer*, Vector3, Color base)
{
return base;

View file

@ -70,7 +70,7 @@ public:
_original_layer = layer;
_preview_layer = texturesLayerCreateDefinition();
_lighting = lightingCreateDefinition();
/*_lighting = lightingCreateDefinition();
light.color = COLOR_WHITE;
light.direction.x = 0.0;
light.direction.y = -0.4794;
@ -79,12 +79,12 @@ public:
light.masked = 0;
light.reflection = 1.0;
lightingAddLight(&_lighting, light);
lightingValidateDefinition(&_lighting);
lightingValidateDefinition(&_lighting);*/
_renderer = rendererCreate();
_renderer.render_quality = 3;
_renderer.getLightStatus = _getLightStatus;
_renderer.customData[0] = &_lighting;
/*_renderer.getLightStatus = _getLightStatus;
_renderer.customData[0] = &_lighting;*/
_renderer.camera_location.x = 0.0;
_renderer.camera_location.y = 20.0;
_renderer.camera_location.z = 0.0;
@ -117,12 +117,12 @@ private:
Renderer _renderer;
TextureLayerDefinition* _original_layer;
TextureLayerDefinition* _preview_layer;
LightingDefinition _lighting;
//LightingDefinition _lighting;
static void _getLightStatus(Renderer* renderer, LightStatus* status, Vector3 location)
/*static void _getLightStatus(Renderer* renderer, LightStatus* status, Vector3 location)
{
lightingGetStatus((LightingDefinition*)renderer->customData[0], renderer, location, status);
}
}*/
};
/**************** Form ****************/

View file

@ -5,8 +5,8 @@
#include <QSlider>
#include <math.h>
#include "../lib_paysages/euclid.h"
#include "../lib_paysages/lighting.h"
#include "../lib_paysages/tools/euclid.h"
#include "../lib_paysages/tools/lighting.h"
#include "../lib_paysages/renderer.h"
#include "../lib_paysages/scenery.h"
#include "../lib_paysages/water.h"
@ -100,7 +100,7 @@ public:
_water = waterCreateDefinition();
_lighting = lightingCreateDefinition();
/*_lighting = lightingCreateDefinition();
light.color = COLOR_WHITE;
light.direction.x = 0.0;
light.direction.y = -0.4794;
@ -109,14 +109,14 @@ public:
light.masked = 0;
light.reflection = 1.0;
lightingAddLight(&_lighting, light);
lightingValidateDefinition(&_lighting);
lightingValidateDefinition(&_lighting);*/
_renderer = rendererCreate();
_renderer.rayWalking = _rayWalking;
_renderer.getLightStatus = _getLightStatus;
_renderer.applyLightStatus = _applyLightStatus;
/*_renderer.getLightStatus = _getLightStatus;
_renderer.applyLightStatus = _applyLightStatus;*/
_renderer.customData[0] = &_water;
_renderer.customData[1] = &_lighting;
//_renderer.customData[1] = &_lighting;
_renderer.customData[2] = this;
configScaling(10.0, 1000.0, 10.0, 250.0);
@ -180,7 +180,7 @@ protected:
private:
Renderer _renderer;
WaterDefinition _water;
LightingDefinition _lighting;
//LightingDefinition _lighting;
bool _lighting_enabled;
static RayCastingResult _rayWalking(Renderer* renderer, Vector3 location, Vector3 direction, int, int, int, int)
@ -218,7 +218,7 @@ private:
return result;
}
static Color _applyLightStatus(Renderer* renderer, LightStatus* status, Vector3 location, Vector3 normal, SurfaceMaterial material)
/*static Color _applyLightStatus(Renderer* renderer, LightStatus* status, Vector3 location, Vector3 normal, SurfaceMaterial material)
{
if (((PreviewWaterColor*)renderer->customData[2])->_lighting_enabled)
{
@ -232,7 +232,7 @@ private:
static void _getLightStatus(Renderer* renderer, LightStatus* status, Vector3 location)
{
lightingGetStatus((LightingDefinition*)renderer->customData[1], renderer, location, status);
}
}*/
};
/**************** Form ****************/

View file

@ -4,7 +4,7 @@
#include <QWidget>
#include "baseinput.h"
#include "../lib_paysages/color.h"
#include "../lib_paysages/tools/color.h"
class InputColorGradation:public BaseInput
{

View file

@ -4,7 +4,7 @@
#include <QWidget>
#include "baseinput.h"
#include "../lib_paysages/curve.h"
#include "../lib_paysages/tools/curve.h"
class InputCurve:public BaseInput
{

View file

@ -5,6 +5,7 @@
#include "baseinput.h"
#include "../lib_paysages/shared/types.h"
#include "../lib_paysages/tools/lighting.h"
class InputMaterial:public BaseInput
{

View file

@ -14,7 +14,6 @@
#include "basepreview.h"
#include "formclouds.h"
#include "formlighting.h"
#include "formatmosphere.h"
#include "formterrain.h"
#include "formtextures.h"
@ -112,11 +111,6 @@ QMainWindow(parent)
QObject::connect(form, SIGNAL(configApplied()), this, SLOT(refreshAll()), Qt::QueuedConnection);
_forms.append(form);
/*form = new FormLighting(tabs);
tabs->addTab(form, tr("Lighting"));
QObject::connect(form, SIGNAL(configApplied()), this, SLOT(refreshAll()), Qt::QueuedConnection);
_forms.append(form);*/
_form_render = new FormRender(tabs);
tabs->addTab(_form_render, tr("Render"));
_forms.append(_form_render);

View file

@ -3,7 +3,7 @@
#include <QMainWindow>
#include "formrender.h"
#include "../lib_paysages/pack.h"
#include "../lib_paysages/tools/pack.h"
class MainWindow : public QMainWindow
{

View file

@ -3,7 +3,7 @@
#include <QWidget>
#include "../lib_paysages/color.h"
#include "../lib_paysages/tools/color.h"
typedef enum
{

View file

@ -4,8 +4,8 @@
#include <QPainter>
#include "tools.h"
#include "../lib_paysages/lighting.h"
#include "../lib_paysages/color.h"
#include "../lib_paysages/tools/lighting.h"
#include "../lib_paysages/tools/color.h"
/***** Small static preview *****/
@ -13,7 +13,7 @@ SmallMaterialPreview::SmallMaterialPreview(QWidget* parent, SurfaceMaterial* mat
{
LightDefinition light;
_lighting = lightingCreateDefinition();
/*_lighting = lightingCreateDefinition();
light.color = COLOR_WHITE;
light.direction.x = -0.5;
light.direction.y = -0.5;
@ -23,7 +23,7 @@ SmallMaterialPreview::SmallMaterialPreview(QWidget* parent, SurfaceMaterial* mat
light.masked = 0;
light.reflection = 1.0;
lightingAddLight(&_lighting, light);
lightingValidateDefinition(&_lighting);
lightingValidateDefinition(&_lighting);*/
_material = material;
@ -62,7 +62,8 @@ Color SmallMaterialPreview::getColor(double x, double y)
}
point = v3Normalize(point);
color = lightingApplyToSurface(&_lighting, &_renderer, point, point, *_material);
//color = lightingApplyToSurface(&_lighting, &_renderer, point, point, *_material);
color = COLOR_RED;
if (dist > 0.95)
{
color.a = (1.0 - dist) / 0.05;

View file

@ -3,7 +3,7 @@
#include "basepreview.h"
#include "../lib_paysages/lighting.h"
#include "../lib_paysages/tools/lighting.h"
#include "../lib_paysages/renderer.h"
class SmallMaterialPreview:public QWidget
@ -19,7 +19,7 @@ protected:
private:
SurfaceMaterial* _material;
LightingDefinition _lighting;
LightStatus* _light;
Renderer _renderer;
};

View file

@ -5,7 +5,7 @@
#include <QDialog>
#include "../lib_paysages/shared/types.h"
#include "../lib_paysages/color.h"
#include "../lib_paysages/tools/color.h"
static inline QColor colorToQColor(Color color)
{

View file

@ -3,7 +3,7 @@
#include <QWidget>
#include <QColor>
#include "../lib_paysages/curve.h"
#include "../lib_paysages/tools/curve.h"
class WidgetCurveEditor : public QWidget
{

View file

@ -7,7 +7,7 @@
#include <GL/glu.h>
#include <QThread>
#include "../lib_paysages/scenery.h"
#include "../lib_paysages/euclid.h"
#include "../lib_paysages/tools/euclid.h"
#include "explorerchunkterrain.h"
#include "explorerchunksky.h"
#include "tools.h"
@ -53,11 +53,6 @@ static Color _applyTextures(Renderer* renderer, Vector3 location, double precisi
return texturesGetColor((TexturesDefinition*)(renderer->customData[1]), renderer, location.x, location.z, precision);
}
static void _getLightStatus(Renderer* renderer, LightStatus* status, Vector3 location)
{
lightingGetStatus((LightingDefinition*)renderer->customData[2], renderer, location, status);
}
WidgetExplorer::WidgetExplorer(QWidget *parent, CameraDefinition* camera):
QGLWidget(parent)
{
@ -71,16 +66,12 @@ WidgetExplorer::WidgetExplorer(QWidget *parent, CameraDefinition* camera):
sceneryGetWater(&_water);
_textures = texturesCreateDefinition();
sceneryGetTextures(&_textures);
_lighting = lightingCreateDefinition();
sceneryGetLighting(&_lighting);
_renderer = sceneryCreateStandardRenderer();
_renderer.render_quality = 3;
_renderer.customData[1] = &_textures;
_renderer.customData[2] = &_lighting;
_renderer.customData[3] = &_water;
_renderer.applyTextures = _applyTextures;
_renderer.getLightStatus = _getLightStatus;
_updated = false;

View file

@ -7,7 +7,6 @@
#include "../lib_paysages/water.h"
#include "../lib_paysages/renderer.h"
#include "../lib_paysages/textures.h"
#include "../lib_paysages/lighting.h"
class WidgetExplorer : public QGLWidget
{
@ -50,7 +49,6 @@ private:
WaterDefinition _water;
TexturesDefinition _textures;
LightingDefinition _lighting;
double _average_frame_time;
int _quality;

View file

@ -3,7 +3,7 @@
#include <QGLWidget>
#include <QDateTime>
#include "../lib_paysages/euclid.h"
#include "../lib_paysages/tools/euclid.h"
#include "../lib_paysages/renderer.h"
#include "../lib_paysages/terrain/public.h"

View file

@ -39,3 +39,18 @@ Color basicApplyAerialPerspective(Renderer* renderer, Vector3 location, Color ba
return base;
}
}
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;
light.reflection = 1.0;
light.filtered = 1;
light.masked = 1;
lightingPushLight(status, &light);
/* TODO Sample other directions */
}

View file

@ -18,6 +18,7 @@
/*********************** Constants ***********************/
#define WORLD_SCALING 0.05
static const double Rg = 6360.0;
static const double Rt = 6420.0;
static const double RL = 6421.0;
@ -1188,7 +1189,7 @@ void brunetonInit()
Color brunetonGetSkyColor(AtmosphereDefinition* definition, Vector3 eye, Vector3 direction, Vector3 sun_position)
{
Vector3 x = {0.0, Rg + (eye.y + 10.0) * 0.01, 0.0};
Vector3 x = {0.0, Rg + (eye.y + WORLD_SCALING) * 0.01, 0.0};
Vector3 v = v3Normalize(direction);
Vector3 s = v3Normalize(v3Sub(sun_position, x));
@ -1210,10 +1211,10 @@ Color brunetonGetSkyColor(AtmosphereDefinition* definition, Vector3 eye, Vector3
Color brunetonApplyAerialPerspective(Renderer* renderer, Vector3 location, Color base)
{
Vector3 eye = renderer->camera_location;
Vector3 direction = v3Scale(v3Sub(location, eye), 0.01);
Vector3 direction = v3Scale(v3Sub(location, eye), WORLD_SCALING);
Vector3 sun_position = v3Scale(renderer->atmosphere->getSunDirection(renderer), 149597870.0);
Vector3 x = {0.0, Rg + (eye.y + 10.0) * 0.01, 0.0};
Vector3 x = {0.0, Rg + (eye.y + 10.0) * WORLD_SCALING, 0.0};
Vector3 v = v3Normalize(direction);
Vector3 s = v3Normalize(v3Sub(sun_position, x));

View file

@ -1,4 +1,3 @@
#include "public.h"
#include "private.h"
#include <math.h>
@ -6,7 +5,6 @@
#include <string.h>
#include "../tools.h"
#include "../renderer.h"
#include "../lighting.h"
#include "../system.h"
#define MAX_SKYDOME_LIGHTS 100
@ -195,6 +193,7 @@ static Vector3 _getSunDirection(Renderer* renderer)
return result;
}
#if 0
static inline void _addDomeLight(Renderer* renderer, LightDefinition* light, Vector3 direction, double factor)
{
light->direction = v3Scale(direction, -1.0);
@ -290,6 +289,15 @@ static int _getSkydomeLights(Renderer* renderer, LightDefinition* lights, int ma
memcpy(lights, cache->lights, sizeof(LightDefinition) * cache->nblights);
return cache->nblights;
}
#endif
static void _fakeGetLightingStatus(Renderer* renderer, LightStatus* status, Vector3 normal, int opaque)
{
UNUSED(renderer);
UNUSED(status);
UNUSED(normal);
UNUSED(opaque);
}
/******************** Renderer ********************/
static AtmosphereRenderer* _createRenderer()
@ -300,9 +308,9 @@ static AtmosphereRenderer* _createRenderer()
result = malloc(sizeof(AtmosphereRenderer));
result->definition = AtmosphereDefinitionClass.create();
result->getLightingStatus = _fakeGetLightingStatus;
result->getSunDirection = _getSunDirection;
result->applyAerialPerspective = _fakeApplyAerialPerspective;
result->getSkydomeLights = _fakeGetSkydomeLights;
result->getSkyColor = _fakeGetSkyColor;
cache = malloc(sizeof(AtmosphereRendererCache));
@ -330,7 +338,7 @@ static void _bindRenderer(AtmosphereRenderer* renderer, AtmosphereDefinition* de
AtmosphereDefinitionClass.copy(definition, renderer->definition);
renderer->getSkyColor = _getSkyColor;
renderer->getSkydomeLights = _getSkydomeLights;
renderer->getLightingStatus = basicGetLightingStatus;
switch (definition->model)
{

View file

@ -1,7 +1,6 @@
#include "public.h"
#include "../renderer.h"
#include "../lighting.h"
/*
* Atmosphere previews.
@ -130,13 +129,15 @@ Color atmosphereGetPreview(Renderer* renderer, double x, double y, double headin
if (_checkHit(eye, direction, &hit, &normal))
{
Color color;
LightStatus light;
LightStatus* light;
normal = m4Transform(rotation, normal);
hit = m4Transform(rotation, hit);
renderer->getLightStatus(renderer, &light, hit);
color = renderer->applyLightStatus(renderer, &light, hit, normal, MOUNT_MATERIAL);
light = lightingCreateStatus(renderer->lighting, hit, renderer->camera_location);
renderer->atmosphere->getLightingStatus(renderer, light, normal, 1);
lightingApplyStatus(light, normal, &MOUNT_MATERIAL);
lightingDeleteStatus(light);
return renderer->atmosphere->applyAerialPerspective(renderer, hit, color);
}
@ -148,20 +149,6 @@ Color atmosphereGetPreview(Renderer* renderer, double x, double y, double headin
}
}
static void _getLightStatus(Renderer* renderer, LightStatus* status, Vector3 location)
{
LightingDefinition def;
def = lightingCreateDefinition();
lightingGetStatus(&def, renderer, location, status);
lightingDeleteDefinition(&def);
}
static Color _applyLightStatus(Renderer* renderer, LightStatus* status, Vector3 location, Vector3 normal, SurfaceMaterial material)
{
return lightingApplyStatusToSurface(renderer, status, location, normal, material);
}
Renderer atmosphereCreatePreviewRenderer()
{
Renderer result = rendererCreate();
@ -170,8 +157,5 @@ Renderer atmosphereCreatePreviewRenderer()
result.camera_location.y = 7.0;
result.camera_location.z = 0.0;
result.getLightStatus = _getLightStatus;
result.applyLightStatus = _applyLightStatus;
return result;
}

View file

@ -6,6 +6,7 @@
#define SPHERE_SIZE 10000.0
Color basicApplyAerialPerspective(Renderer* renderer, Vector3 location, Color base);
void basicGetLightingStatus(Renderer* renderer, LightStatus* status, Vector3 normal, int opaque);
void brunetonInit();
Color brunetonGetSkyColor(AtmosphereDefinition* definition, Vector3 eye, Vector3 direction, Vector3 sun_position);

View file

@ -1,11 +1,12 @@
#ifndef _PAYSAGES_ATMOSPHERE_PUBLIC_H_
#define _PAYSAGES_ATMOSPHERE_PUBLIC_H_
#include "../shared/types.h"
#include "../euclid.h"
#include "../color.h"
#include "../pack.h"
#include "../tools/lighting.h"
#include "../tools/euclid.h"
#include "../tools/color.h"
#include "../tools/pack.h"
#include "../layers.h"
#include "../shared/types.h"
#ifdef __cplusplus
extern "C" {
@ -39,7 +40,7 @@ typedef struct
double _daytime;
} AtmosphereDefinition;
typedef int (*FuncAtmosphereGetSkydomeLights)(Renderer* renderer, LightDefinition* array, int max_lights);
typedef void (*FuncAtmosphereGetLightingStatus)(Renderer* renderer, LightStatus* status, Vector3 normal, int opaque);
typedef Color (*FuncAtmosphereApplyAerialPerspective)(Renderer* renderer, Vector3 location, Color base);
typedef Color (*FuncAtmosphereGetSkyColor)(Renderer* renderer, Vector3 direction);
typedef Vector3 (*FuncAtmosphereGetSunDirection)(Renderer* renderer);
@ -48,7 +49,7 @@ typedef struct
{
AtmosphereDefinition* definition;
FuncAtmosphereGetSkydomeLights getSkydomeLights;
FuncAtmosphereGetLightingStatus getLightingStatus;
FuncAtmosphereApplyAerialPerspective applyAerialPerspective;
FuncAtmosphereGetSkyColor getSkyColor;
FuncAtmosphereGetSunDirection getSunDirection;

View file

@ -4,11 +4,7 @@
#include <stdlib.h>
#include <time.h>
#include "shared/types.h"
#include "clouds.h"
#include "color.h"
#include "lighting.h"
#include "modifiers.h"
#include "render.h"
#include "textures.h"
#include "scenery.h"

View file

@ -2,9 +2,7 @@
#include <stdlib.h>
#include <math.h>
#include "euclid.h"
#include "render.h"
#include "shared/types.h"
#include "scenery.h"
#include "tools.h"

View file

@ -1,9 +1,9 @@
#ifndef _PAYSAGES_CAMERA_H_
#define _PAYSAGES_CAMERA_H_
#include "shared/types.h"
#include "tools/pack.h"
#include "tools/euclid.h"
#include "renderer.h"
#include "pack.h"
#ifdef __cplusplus
extern "C" {

View file

@ -3,11 +3,9 @@
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include "color.h"
#include "euclid.h"
#include "lighting.h"
#include "tools/color.h"
#include "tools/euclid.h"
#include "tools.h"
#include "shared/types.h"
#define CLOUDS_MAX_LAYERS 6
#define MAX_SEGMENT_COUNT 30
@ -554,7 +552,7 @@ static Color _applyLayerLighting(CloudsLayerDefinition* definition, Renderer* re
{
Vector3 normal;
Color col1, col2;
LightStatus light;
LightStatus* lighting;
normal = _getNormal(definition, position, 3.0);
if (renderer->render_quality > 5)
@ -568,9 +566,11 @@ static Color _applyLayerLighting(CloudsLayerDefinition* definition, Renderer* re
}
normal = v3Scale(v3Normalize(normal), definition->hardness);
renderer->getLightStatus(renderer, &light, position);
col1 = renderer->applyLightStatus(renderer, &light, position, normal, definition->material);
col2 = renderer->applyLightStatus(renderer, &light, position, v3Scale(normal, -1.0), definition->material);
lighting = lightingCreateStatus(renderer->lighting, position, renderer->camera_location);
renderer->atmosphere->getLightingStatus(renderer, lighting, normal, 0);
col1 = lightingApplyStatus(lighting, normal, &definition->material);
col2 = lightingApplyStatus(lighting, v3Scale(normal, -1.0), &definition->material);
lightingDeleteStatus(lighting);
col1.r = (col1.r + col2.r) / 2.0;
col1.g = (col1.g + col2.g) / 2.0;

View file

@ -3,7 +3,7 @@
/* Geographic area definition */
#include "pack.h"
#include "tools/pack.h"
#ifdef __cplusplus
extern "C" {

View file

@ -3,7 +3,7 @@
/* Factorized layer management (with names) */
#include "pack.h"
#include "tools/pack.h"
#ifdef __cplusplus
extern "C" {

View file

@ -1,257 +0,0 @@
#include "lighting.h"
#include <stdlib.h>
#include <math.h>
#include <unistd.h>
#include <string.h>
#include "shared/types.h"
#include "color.h"
#include "euclid.h"
#include "renderer.h"
#include "scenery.h"
#include "tools.h"
#include "water.h"
static LightDefinition _LIGHT_NULL;
void lightingInit()
{
_LIGHT_NULL.direction.x = 0.0;
_LIGHT_NULL.direction.y = 1.0;
_LIGHT_NULL.direction.z = 0.0;
_LIGHT_NULL.color = COLOR_BLACK;
_LIGHT_NULL.reflection = 0.0;
_LIGHT_NULL.filtered = 0;
_LIGHT_NULL.masked = 0;
}
void lightingQuit()
{
}
void lightingSave(PackStream* stream, LightingDefinition* definition)
{
int i;
packWriteInt(stream, &definition->nblights);
for (i = 0; i < definition->nblights; i++)
{
v3Save(stream, &definition->lights[i].direction);
colorSave(stream, &definition->lights[i].color);
packWriteDouble(stream, &definition->lights[i].reflection);
packWriteInt(stream, &definition->lights[i].filtered);
packWriteInt(stream, &definition->lights[i].masked);
}
}
void lightingLoad(PackStream* stream, LightingDefinition* definition)
{
int i;
packReadInt(stream, &definition->nblights);
for (i = 0; i < definition->nblights; i++)
{
v3Load(stream, &definition->lights[i].direction);
colorLoad(stream, &definition->lights[i].color);
packReadDouble(stream, &definition->lights[i].reflection);
packReadInt(stream, &definition->lights[i].filtered);
packReadInt(stream, &definition->lights[i].masked);
}
lightingValidateDefinition(definition);
}
LightingDefinition lightingCreateDefinition()
{
LightingDefinition definition;
definition.nblights = 0;
return definition;
}
void lightingDeleteDefinition(LightingDefinition* definition)
{
}
void lightingCopyDefinition(LightingDefinition* source, LightingDefinition* destination)
{
*destination = *source;
}
void lightingValidateDefinition(LightingDefinition* definition)
{
}
int lightingGetLightCount(LightingDefinition* definition)
{
return definition->nblights;
}
LightDefinition lightingGetLight(LightingDefinition* definition, int light)
{
if (light >= 0 && light < definition->nblights)
{
return definition->lights[light];
}
else
{
return _LIGHT_NULL;
}
}
int lightingAddLight(LightingDefinition* definition, LightDefinition light)
{
if (definition->nblights < LIGHTING_MAX_LIGHTS)
{
definition->lights[definition->nblights] = light;
return definition->nblights++;
}
else
{
return -1;
}
}
void lightingDeleteLight(LightingDefinition* definition, int light)
{
if (light >= 0 && light < definition->nblights)
{
if (definition->nblights > 1 && light < definition->nblights - 1)
{
memmove(definition->lights + light, definition->lights + light + 1, sizeof(LightDefinition) * definition->nblights - light - 1);
}
definition->nblights--;
}
}
static int _getLightStatus(LightDefinition* definition, Renderer* renderer, Vector3 location, LightDefinition* result)
{
*result = *definition;
if (definition->masked || definition->filtered)
{
renderer->alterLight(renderer, result, location);
}
if (result->color.r > 0.0 || result->color.g > 0.0 || result->color.b > 0.0)
{
return 1;
}
else
{
return 0;
}
}
static Color _applyDirectLight(LightDefinition* definition, Renderer* renderer, Vector3 location, Vector3 normal, SurfaceMaterial material)
{
Color result, light;
double diffuse, specular, normal_norm;
Vector3 view, reflect, direction_inv;
light = definition->color;
direction_inv = v3Scale(definition->direction, -1.0);
normal_norm = v3Norm(normal);
if (normal_norm > 1.0)
{
normal_norm = 1.0;
}
normal = v3Normalize(normal);
diffuse = v3Dot(direction_inv, normal);
if (diffuse > 0.0)
{
if (material.shininess > 0.0 && definition->reflection > 0.0)
{
view = v3Normalize(v3Sub(location, renderer->camera_location));
reflect = v3Sub(direction_inv, v3Scale(normal, 2.0 * v3Dot(direction_inv, normal)));
specular = v3Dot(reflect, view);
if (specular > 0.0)
{
specular = pow(specular, material.shininess) * material.reflection;
}
else
{
specular = 0.0;
}
}
else
{
specular = 0.0;
}
}
else
{
diffuse = 0.0;
specular = 0.0;
}
specular *= normal_norm * definition->reflection;
diffuse = 1.0 - normal_norm + diffuse * normal_norm;
result.r = material.base.r * diffuse * light.r + specular * light.r;
result.g = material.base.g * diffuse * light.g + specular * light.g;
result.b = material.base.b * diffuse * light.b + specular * light.b;
result.a = material.base.a;
return result;
}
void lightingGetStatus(LightingDefinition* definition, Renderer* renderer, Vector3 location, LightStatus* result)
{
int i, skydome_lights_count;
LightDefinition skydome_lights[LIGHTING_MAX_LIGHTS];
result->nblights = 0;
/* Apply static lights */
for (i = 0; i < definition->nblights; i++)
{
if (_getLightStatus(definition->lights + i, renderer, location, result->lights + result->nblights))
{
result->nblights++;
}
}
/* Apply skydome lights */
/* TODO Cache skydome lights for same render */
skydome_lights_count = renderer->atmosphere->getSkydomeLights(renderer, skydome_lights, LIGHTING_MAX_LIGHTS);
for (i = 0; i < skydome_lights_count; i++)
{
if (_getLightStatus(skydome_lights + i, renderer, location, result->lights + result->nblights))
{
result->nblights++;
}
}
}
Color lightingApplyStatusToSurface(Renderer* renderer, LightStatus* status, Vector3 location, Vector3 normal, SurfaceMaterial material)
{
Color result, lighted;
int i;
result = COLOR_BLACK;
result.a = material.base.a;
for (i = 0; i < status->nblights; i++)
{
lighted = _applyDirectLight(status->lights + i, renderer, location, normal, material);
result.r += lighted.r;
result.g += lighted.g;
result.b += lighted.b;
}
return result;
}
Color lightingApplyToSurface(LightingDefinition* definition, Renderer* renderer, Vector3 location, Vector3 normal, SurfaceMaterial material)
{
LightStatus status;
lightingGetStatus(definition, renderer, location, &status);
return lightingApplyStatusToSurface(renderer, &status, location, normal, material);
}

View file

@ -1,59 +0,0 @@
#ifndef _PAYSAGES_LIGHTING_H_
#define _PAYSAGES_LIGHTING_H_
#include "shared/types.h"
#include "pack.h"
#ifdef __cplusplus
extern "C" {
#endif
#define LIGHTING_MAX_LIGHTS 30
struct LightDefinition
{
Vector3 direction; /* Global direction of the light */
Color color; /* Main color of the light */
double reflection; /* Reflected factor of the light (for specular lighting) */
int filtered; /* Should the light be filtered (by atmosphere, water...) */
int masked; /* Should the light be masked (cast shadows..) */
};
typedef struct
{
int nblights;
LightDefinition lights[LIGHTING_MAX_LIGHTS];
} LightingDefinition;
struct LightStatus
{
int nblights;
LightDefinition lights[LIGHTING_MAX_LIGHTS * 2];
};
typedef LightDefinition (*FuncLightingAlterLight)(Renderer* renderer, LightDefinition* light, Vector3 at);
void lightingInit();
void lightingQuit();
void lightingSave(PackStream* stream, LightingDefinition* definition);
void lightingLoad(PackStream* stream, LightingDefinition* definition);
LightingDefinition lightingCreateDefinition();
void lightingDeleteDefinition(LightingDefinition* definition);
void lightingCopyDefinition(LightingDefinition* source, LightingDefinition* destination);
void lightingValidateDefinition(LightingDefinition* definition);
int lightingGetLightCount(LightingDefinition* definition);
LightDefinition lightingGetLight(LightingDefinition* definition, int light);
int lightingAddLight(LightingDefinition* definition, LightDefinition light);
void lightingDeleteLight(LightingDefinition* definition, int light);
void lightingGetStatus(LightingDefinition* definition, Renderer* renderer, Vector3 location, LightStatus* result);
Color lightingApplyStatusToSurface(Renderer* renderer, LightStatus* status, Vector3 location, Vector3 normal, SurfaceMaterial material);
Color lightingApplyToSurface(LightingDefinition* definition, Renderer* renderer, Vector3 location, Vector3 normal, SurfaceMaterial material);
#ifdef __cplusplus
}
#endif
#endif

View file

@ -1,10 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
#include "shared/types.h"
#include "auto.h"
#include "color.h"
#include "system.h"
#include "camera.h"
#include "scenery.h"

View file

@ -1,101 +0,0 @@
#include "modifiers.h"
#include <stdlib.h>
#include "shared/types.h"
#include "tools.h"
#define MODE_NULL 0
#define MODE_ADD_VALUE 1
#define MODE_FIX_VALUE 2
struct HeightModifier
{
Zone* zone;
int mode;
double value;
};
HeightModifier* modifierCreate()
{
HeightModifier* modifier;
modifier = (HeightModifier*)malloc(sizeof(HeightModifier));
modifier->zone = zoneCreate();
modifier->mode = MODE_NULL;
return modifier;
}
HeightModifier* modifierCreateCopy(HeightModifier* source)
{
HeightModifier* result;
result = (HeightModifier*)malloc(sizeof(HeightModifier));
result->zone = zoneCreate();
zoneCopy(source->zone, result->zone);
result->mode = source->mode;
result->value = source->value;
return result;
}
void modifierDelete(HeightModifier* modifier)
{
zoneDelete(modifier->zone);
free(modifier);
}
void modifierSave(PackStream* stream, HeightModifier* modifier)
{
packWriteInt(stream, &modifier->mode);
packWriteDouble(stream, &modifier->value);
zoneSave(stream, modifier->zone);
}
void modifierLoad(PackStream* stream, HeightModifier* modifier)
{
packReadInt(stream, &modifier->mode);
packReadDouble(stream, &modifier->value);
zoneLoad(stream, modifier->zone);
}
Zone* modifierGetZone(HeightModifier* modifier)
{
return modifier->zone;
}
void modifierActionAddValue(HeightModifier* modifier, double value)
{
modifier->mode = MODE_ADD_VALUE;
modifier->value = value;
}
void modifierActionFixValue(HeightModifier* modifier, double value)
{
modifier->mode = MODE_FIX_VALUE;
modifier->value = value;
}
Vector3 modifierApply(HeightModifier* modifier, Vector3 location)
{
double influence, diff;
Vector3 normal;
switch (modifier->mode)
{
case MODE_ADD_VALUE:
influence = zoneGetValue(modifier->zone, location, normal);
location.y += modifier->value * influence;
break;
case MODE_FIX_VALUE:
influence = zoneGetValue(modifier->zone, location, normal);
diff = modifier->value - location.y;
location.y += diff * influence;
break;
case MODE_NULL:
break;
}
return location;
}

View file

@ -1,27 +0,0 @@
#ifndef _PAYSAGES_MODIFIERS_H_
#define _PAYSAGES_MODIFIERS_H_
#include "pack.h"
#include "zone.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct HeightModifier HeightModifier;
HeightModifier* modifierCreate();
HeightModifier* modifierCreateCopy(HeightModifier* source);
void modifierDelete(HeightModifier* modifier);
void modifierSave(PackStream* stream, HeightModifier* modifier);
void modifierLoad(PackStream* stream, HeightModifier* modifier);
Zone* modifierGetZone(HeightModifier* modifier);
void modifierActionAddValue(HeightModifier* modifier, double value);
void modifierActionFixValue(HeightModifier* modifier, double value);
Vector3 modifierApply(HeightModifier* modifier, Vector3 location);
#ifdef __cplusplus
}
#endif
#endif

View file

@ -1,7 +1,7 @@
#ifndef _PAYSAGES_NOISE_H_
#define _PAYSAGES_NOISE_H_
#include "pack.h"
#include "tools/pack.h"
#ifdef __cplusplus
extern "C" {

View file

@ -1,7 +1,7 @@
#ifndef _PAYSAGES_NOISENAIVE_H_
#define _PAYSAGES_NOISENAIVE_H_
#include "pack.h"
#include "tools/pack.h"
#ifdef __cplusplus
extern "C" {

View file

@ -4,8 +4,6 @@
#include <stdio.h>
#include <math.h>
#include "shared/types.h"
#include "color.h"
#include "renderer.h"
#include "system.h"

View file

@ -1,13 +1,16 @@
#ifndef _PAYSAGES_RENDER_H_
#define _PAYSAGES_RENDER_H_
#include <stdio.h>
#include "shared/types.h"
#include "tools/color.h"
#include "tools/euclid.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef Color (*f_RenderFragmentCallback)(struct Renderer* renderer, Vector3 location, void* data);
typedef void (*RenderCallbackStart)(int width, int height, Color background);
typedef void (*RenderCallbackDraw)(int x, int y, Color col);
typedef void (*RenderCallbackUpdate)(double progress);

View file

@ -1,6 +1,6 @@
#include "renderer.h"
#include "lighting.h"
#include "tools/lighting.h"
#include "system.h"
#include "render.h"
#include "scenery.h"
@ -54,20 +54,6 @@ static void _pushQuad(Renderer* renderer, Vector3 v1, Vector3 v2, Vector3 v3, Ve
renderer->pushTriangle(renderer, v4, v1, v3, callback, callback_data);
}
static void _alterLight(Renderer* renderer, LightDefinition* light, Vector3 location)
{
}
static void _getLightStatus(Renderer* renderer, LightStatus* status, Vector3 location)
{
status->nblights = 0;
}
static Color _applyLightStatus(Renderer* renderer, LightStatus* status, Vector3 location, Vector3 normal, SurfaceMaterial material)
{
return lightingApplyStatusToSurface(renderer, status, location, normal, material);
}
static RayCastingResult _rayWalking(Renderer* renderer, Vector3 location, Vector3 direction, int terrain, int water, int sky, int clouds)
{
return _RAYCASTING_NULL;
@ -117,9 +103,7 @@ Renderer rendererCreate()
result.applyTextures = _applyTextures;
result.applyClouds = _applyClouds;
result.alterLight = _alterLight;
result.getLightStatus = _getLightStatus;
result.applyLightStatus = _applyLightStatus;
result.lighting = lightingManagerCreate();
result.atmosphere = AtmosphereRendererClass.create();
result.terrain = TerrainRendererClass.create();
@ -129,6 +113,8 @@ Renderer rendererCreate()
void rendererDelete(Renderer* renderer)
{
lightingManagerDelete(renderer->lighting);
AtmosphereRendererClass.destroy(renderer->atmosphere);
TerrainRendererClass.destroy(renderer->terrain);

View file

@ -37,10 +37,8 @@ struct Renderer
Color (*applyTextures)(Renderer* renderer, Vector3 location, double precision);
Color (*applyClouds)(Renderer* renderer, Color base, Vector3 start, Vector3 end);
/* Lighting related */
void (*alterLight)(Renderer* renderer, LightDefinition* light, Vector3 location);
void (*getLightStatus)(Renderer* renderer, LightStatus* status, Vector3 location);
Color (*applyLightStatus)(Renderer* renderer, LightStatus* status, Vector3 location, Vector3 normal, SurfaceMaterial material);
/* Autonomous tools */
LightingManager* lighting;
/* Autonomous sub-renderers */
AtmosphereRenderer* atmosphere;

View file

@ -1,15 +1,13 @@
#include "scenery.h"
#include <stdio.h>
#include "color.h"
#include "euclid.h"
#include "tools/color.h"
#include "tools/euclid.h"
#include "render.h"
#include "system.h"
static AtmosphereDefinition* _atmosphere;
static CameraDefinition _camera;
static CloudsDefinition _clouds;
static LightingDefinition _lighting;
static TerrainDefinition* _terrain;
static TexturesDefinition _textures;
static WaterDefinition _water;
@ -21,12 +19,10 @@ static void* _custom_data = NULL;
void sceneryInit()
{
noiseInit();
lightingInit();
_atmosphere = AtmosphereDefinitionClass.create();
_camera = cameraCreateDefinition();
_clouds = cloudsCreateDefinition();
_lighting = lightingCreateDefinition();
_terrain = TerrainDefinitionClass.create();
_textures = texturesCreateDefinition();
_water = waterCreateDefinition();
@ -40,12 +36,10 @@ void sceneryQuit()
AtmosphereDefinitionClass.destroy(_atmosphere);
cameraDeleteDefinition(&_camera);
cloudsDeleteDefinition(&_clouds);
lightingDeleteDefinition(&_lighting);
TerrainDefinitionClass.destroy(_terrain);
texturesDeleteDefinition(&_textures);
waterDeleteDefinition(&_water);
lightingQuit();
noiseQuit();
}
@ -62,7 +56,6 @@ void scenerySave(PackStream* stream)
AtmosphereDefinitionClass.save(stream, _atmosphere);
cameraSave(stream, &_camera);
cloudsSave(stream, &_clouds);
lightingSave(stream, &_lighting);
TerrainDefinitionClass.save(stream, _terrain);
texturesSave(stream, &_textures);
waterSave(stream, &_water);
@ -81,14 +74,12 @@ void sceneryLoad(PackStream* stream)
AtmosphereDefinitionClass.load(stream, _atmosphere);
cameraLoad(stream, &_camera);
cloudsLoad(stream, &_clouds);
lightingLoad(stream, &_lighting);
TerrainDefinitionClass.load(stream, _terrain);
texturesLoad(stream, &_textures);
waterLoad(stream, &_water);
cameraValidateDefinition(&_camera, 0);
cloudsValidateDefinition(&_clouds);
lightingValidateDefinition(&_lighting);
texturesValidateDefinition(&_textures);
waterValidateDefinition(&_water);
@ -130,17 +121,6 @@ void sceneryGetClouds(CloudsDefinition* clouds)
cloudsCopyDefinition(&_clouds, clouds);
}
void scenerySetLighting(LightingDefinition* lighting)
{
lightingCopyDefinition(lighting, &_lighting);
lightingValidateDefinition(&_lighting);
}
void sceneryGetLighting(LightingDefinition* lighting)
{
lightingCopyDefinition(&_lighting, lighting);
}
void scenerySetTerrain(TerrainDefinition* terrain)
{
TerrainDefinitionClass.copy(terrain, _terrain);
@ -190,36 +170,6 @@ void sceneryRenderFirstPass(Renderer* renderer)
/******* Standard renderer *********/
static void _alterLight(Renderer* renderer, LightDefinition* light, Vector3 location)
{
Vector3 light_location;
Vector3 direction_to_light;
direction_to_light = v3Normalize(v3Scale(light->direction, -1.0));
light_location = v3Add(location, v3Scale(direction_to_light, 1000.0));
if (light->filtered)
{
// TODO atmosphere filter
light->color = waterLightFilter(&_water, renderer, light->color, location, light_location, direction_to_light);
}
if (light->masked)
{
*light = renderer->terrain->alterLight(renderer, light, location);
light->color = cloudsFilterLight(&_clouds, renderer, light->color, location, light_location, direction_to_light);
}
}
static void _getLightStatus(Renderer* renderer, LightStatus* status, Vector3 location)
{
lightingGetStatus(&_lighting, renderer, location, status);
}
static Color _applyLightStatus(Renderer* renderer, LightStatus* status, Vector3 location, Vector3 normal, SurfaceMaterial material)
{
return lightingApplyStatusToSurface(renderer, status, location, normal, material);
}
static RayCastingResult _rayWalking(Renderer* renderer, Vector3 location, Vector3 direction, int terrain, int water, int sky, int clouds)
{
RayCastingResult result;
@ -283,9 +233,6 @@ Renderer sceneryCreateStandardRenderer()
cameraCopyDefinition(&_camera, &result.render_camera);
result.camera_location = _camera.location;
result.alterLight = _alterLight;
result.getLightStatus = _getLightStatus;
result.applyLightStatus = _applyLightStatus;
result.rayWalking = _rayWalking;
result.getWaterHeightInfo = _getWaterHeightInfo;
result.applyTextures = _applyTextures;

View file

@ -8,14 +8,13 @@
* a standard renderer.
*/
#include "tools/pack.h"
#include "atmosphere/public.h"
#include "terrain/public.h"
#include "camera.h"
#include "clouds.h"
#include "lighting.h"
#include "textures.h"
#include "water.h"
#include "pack.h"
#include "renderer.h"
#ifdef __cplusplus
@ -41,9 +40,6 @@ void sceneryGetCamera(CameraDefinition* camera);
void scenerySetClouds(CloudsDefinition* clouds);
void sceneryGetClouds(CloudsDefinition* clouds);
void scenerySetLighting(LightingDefinition* lighting);
void sceneryGetLighting(LightingDefinition* lighting);
void scenerySetTerrain(TerrainDefinition* terrain);
void sceneryGetTerrain(TerrainDefinition* terrain);

View file

@ -1,8 +1,8 @@
#ifndef _PAYSAGES_TYPES_H_
#define _PAYSAGES_TYPES_H_
#include "../euclid.h"
#include "../color.h"
#include "../tools/euclid.h"
#include "../tools/color.h"
#ifdef __cplusplus
extern "C" {
@ -10,11 +10,6 @@ extern "C" {
typedef struct Renderer Renderer;
typedef struct LightDefinition LightDefinition;
typedef struct LightStatus LightStatus;
typedef Color (*f_RenderFragmentCallback)(struct Renderer* renderer, Vector3 location, void* data);
typedef struct
{
int length;
@ -24,13 +19,6 @@ typedef struct
void* data;
} Array;
typedef struct
{
Color base;
double reflection;
double shininess;
} SurfaceMaterial;
typedef struct
{
int hit;

View file

@ -3,7 +3,7 @@
/* Library dependent features */
#include "color.h"
#include "tools/color.h"
#include <stdlib.h>
#ifdef __cplusplus

View file

@ -1,10 +1,8 @@
#include "public.h"
#include "private.h"
#include <stdlib.h>
#include <math.h>
#include "../tools.h"
#include "../lighting.h"
#include "../renderer.h"
/******************** Definition ********************/
@ -305,7 +303,6 @@ static TerrainRenderer* _createRenderer()
result->definition = TerrainDefinitionClass.create();
result->castRay = _fakeCastRay;
result->alterLight = _fakeAlterLight;
result->getHeight = _fakeGetHeight;
result->getFinalColor = _fakeGetFinalColor;
@ -323,7 +320,6 @@ static void _bindRenderer(TerrainRenderer* renderer, TerrainDefinition* definiti
TerrainDefinitionClass.copy(definition, renderer->definition);
renderer->castRay = _castRay;
renderer->alterLight = _alterLight;
renderer->getHeight = _getHeight;
renderer->getFinalColor = _getFinalColor;
}

View file

@ -1,6 +1,7 @@
#include "public.h"
#include "private.h"
#include <math.h>
/*
* Terrain presets.
*/

View file

@ -1,8 +1,8 @@
#include "public.h"
#include <stdlib.h>
#include "../tools/lighting.h"
#include "../renderer.h"
#include "../lighting.h"
#include "../textures.h"
/*
@ -10,7 +10,7 @@
*/
static TexturesDefinition _textures;
static LightingDefinition _lighting;
/*static LightingDefinition _lighting;*/
static int _inited = 0;
static Color _applyTextures(Renderer* renderer, Vector3 location, double precision)
@ -18,36 +18,24 @@ static Color _applyTextures(Renderer* renderer, Vector3 location, double precisi
return texturesGetColor(&_textures, renderer, location.x, location.z, precision);
}
static void _getLightStatus(Renderer* renderer, LightStatus* status, Vector3 location)
{
lightingGetStatus(&_lighting, renderer, location, status);
}
static void _alterLight(Renderer* renderer, LightDefinition* light, Vector3 location)
{
*light = renderer->terrain->alterLight(renderer, light, location);
}
Renderer terrainCreatePreviewRenderer()
{
Renderer result = rendererCreate();
result.render_quality = 3;
result.applyTextures = _applyTextures;
result.getLightStatus = _getLightStatus;
result.alterLight = _alterLight;
result.camera_location.x = 0.0;
result.camera_location.y = 50.0;
result.camera_location.z = 0.0;
if (!_inited)
{
LightDefinition light;
/*LightDefinition light;*/
TextureLayerDefinition* texture;
_inited = 1;
_lighting = lightingCreateDefinition();
/*_lighting = lightingCreateDefinition();
light.color.r = 0.6;
light.color.g = 0.6;
light.color.b = 0.6;
@ -69,7 +57,7 @@ Renderer terrainCreatePreviewRenderer()
light.masked = 0;
light.reflection = 0.0;
lightingAddLight(&_lighting, light);
lightingValidateDefinition(&_lighting);
lightingValidateDefinition(&_lighting);*/
_textures = texturesCreateDefinition();
texture = (TextureLayerDefinition*)layersGetLayer(_textures.layers, layersAddLayer(_textures.layers, NULL));

View file

@ -2,8 +2,9 @@
#define _PAYSAGES_TERRAIN_PUBLIC_H_
#include "../shared/types.h"
#include "../tools/color.h"
#include "../tools/euclid.h"
#include "../noise.h"
#include "../lighting.h"
#ifdef __cplusplus
extern "C" {
@ -38,7 +39,6 @@ typedef struct
TerrainDefinition* definition;
FuncGeneralCastRay castRay;
FuncLightingAlterLight alterLight;
FuncTerrainGetHeight getHeight;
FuncTerrainGetFinalColor getFinalColor;

View file

@ -56,6 +56,11 @@ void terrainRenderSurface(Renderer* renderer)
min_chunk_size = 0.1 / (double)renderer->render_quality;
visible_chunk_size = 0.05 / (double)renderer->render_quality;
if (renderer->render_quality > 7)
{
min_chunk_size *= 0.5;
visible_chunk_size *= 0.5;
}
chunk_factor = 1;
chunk_count = 2;

View file

@ -5,11 +5,8 @@
#include <string.h>
#include <assert.h>
#include "shared/types.h"
#include "terrain/public.h"
#include "color.h"
#include "euclid.h"
#include "lighting.h"
#include "tools/lighting.h"
#include "renderer.h"
#include "tools.h"
@ -269,17 +266,21 @@ double texturesGetLayerCoverage(TextureLayerDefinition* definition, Renderer* re
return zoneGetValue(definition->zone, base.location, base.normal);
}
static inline Color _getLayerColor(Renderer* renderer, TextureResult result, LightStatus* light)
static inline Color _getLayerColor(Renderer* renderer, TextureResult texture)
{
return renderer->applyLightStatus(renderer, light, result.location, result.normal, result.definition->material);
LightStatus* light;
Color result;
light = lightingCreateStatus(renderer->lighting, texture.location, renderer->camera_location);
renderer->atmosphere->getLightingStatus(renderer, light, texture.normal, 1);
result = lightingApplyStatus(light, texture.normal, &texture.definition->material);
lightingDeleteStatus(light);
return result;
}
Color texturesGetLayerColor(TextureLayerDefinition* definition, Renderer* renderer, Vector3 location, double detail)
{
LightStatus light;
TextureResult result = _getLayerResult(definition, renderer, location.x, location.z, detail);
renderer->getLightStatus(renderer, &light, result.location);
return _getLayerColor(renderer, result, &light);
return _getLayerColor(renderer, result);
}
Color texturesGetColor(TexturesDefinition* definition, Renderer* renderer, double x, double z, double detail)
@ -333,11 +334,9 @@ Color texturesGetColor(TexturesDefinition* definition, Renderer* renderer, doubl
}
/* Apply colors and alphas */
LightStatus light;
renderer->getLightStatus(renderer, &light, results[start].location);
if (results[start].definition)
{
result = _getLayerColor(renderer, results[start], &light);
result = _getLayerColor(renderer, results[start]);
}
else
{
@ -349,7 +348,7 @@ Color texturesGetColor(TexturesDefinition* definition, Renderer* renderer, doubl
{
if (results[i].definition)
{
color = _getLayerColor(renderer, results[i], &light);
color = _getLayerColor(renderer, results[i]);
color.a = results[i].thickness;
}
else

View file

@ -1,11 +1,13 @@
#ifndef _PAYSAGES_TEXTURES_H_
#define _PAYSAGES_TEXTURES_H_
#include "tools/lighting.h"
#include "tools/color.h"
#include "tools/euclid.h"
#include "tools/pack.h"
#include "shared/types.h"
#include "layers.h"
#include "noise.h"
#include "lighting.h"
#include "pack.h"
#include "zone.h"
#ifdef __cplusplus

View file

@ -5,9 +5,6 @@
#include <inttypes.h>
#include <math.h>
#include "color.h"
#include "euclid.h"
double toolsRandom()
{
return ((double)rand()) / (double)RAND_MAX;
@ -71,17 +68,3 @@ double toolsGetDistance2D(double x1, double y1, double x2, double y2)
double dy = y2 - y1;
return sqrt(dx * dx + dy * dy);
}
void materialSave(PackStream* stream, SurfaceMaterial* material)
{
colorSave(stream, &material->base);
packWriteDouble(stream, &material->reflection);
packWriteDouble(stream, &material->shininess);
}
void materialLoad(PackStream* stream, SurfaceMaterial* material)
{
colorLoad(stream, &material->base);
packReadDouble(stream, &material->reflection);
packReadDouble(stream, &material->shininess);
}

View file

@ -1,8 +1,8 @@
#ifndef _PAYSAGES_TOOLS_H_
#define _PAYSAGES_TOOLS_H_
#include "pack.h"
#include "shared/types.h"
#include "tools/euclid.h"
#ifdef __cplusplus
extern "C" {
@ -16,8 +16,6 @@ double toolsBicubicInterpolate(double stencil[16], double x, double y);
void toolsFloat2DMapCopy(double* src, double* dest, int src_xstart, int src_ystart, int dest_xstart, int dest_ystart, int xsize, int ysize, int src_xstep, int src_ystep, int dest_xstep, int dest_ystep);
Vector3 toolsGetNormalFromTriangle(Vector3 center, Vector3 bottom, Vector3 right);
double toolsGetDistance2D(double x1, double y1, double x2, double y2);
void materialSave(PackStream* stream, SurfaceMaterial* material);
void materialLoad(PackStream* stream, SurfaceMaterial* material);
#ifdef __cplusplus
}

View file

@ -4,8 +4,7 @@
#include <assert.h>
#include <string.h>
#include <math.h>
#include "tools.h"
#include "curve.h"
#include "../tools.h"
/******************************** Color ********************************/
@ -224,22 +223,22 @@ int colorProfileCollect(ColorProfile* profile, Color pixel)
return changed;
}
float A = 0.15;
float B = 0.50;
float C = 0.10;
float D = 0.20;
float E = 0.02;
float F = 0.30;
float W = 11.2;
static double _uncharted2Tonemap(double x)
{
double A = 0.15;
double B = 0.50;
double C = 0.10;
double D = 0.20;
double E = 0.02;
double F = 0.30;
return ((x*(A*x+C*B)+D*E)/(x*(A*x+B)+D*F))-E/F;
}
Color colorProfileApply(ColorProfile* profile, Color pixel)
{
double exposure_bias = 2.0;
double W = 11.2;
double white_scale = 1.0 / _uncharted2Tonemap(W);
pixel.r = pow(_uncharted2Tonemap(pixel.r * exposure_bias) * white_scale, 1.0 / 2.2);

View file

@ -1,5 +1,5 @@
#ifndef _PAYSAGES_COLOR_H_
#define _PAYSAGES_COLOR_H_
#ifndef _PAYSAGES_TOOLS_COLOR_H_
#define _PAYSAGES_TOOLS_COLOR_H_
#include "curve.h"
#include "pack.h"

View file

@ -2,7 +2,7 @@
#include <stdlib.h>
#include <string.h>
#include "tools.h"
#include "../tools.h"
#define MAX_NB_POINTS 40

View file

@ -1,5 +1,5 @@
#ifndef _PAYSAGES_CURVE_H_
#define _PAYSAGES_CURVE_H_
#ifndef _PAYSAGES_TOOLS_CURVE_H_
#define _PAYSAGES_TOOLS_CURVE_H_
#include "pack.h"

View file

@ -1,8 +1,7 @@
#include "euclid.h"
#include <math.h>
#include "tools.h"
#include "../tools.h"
Vector3 VECTOR_ZERO = {0.0, 0.0, 0.0};
Vector3 VECTOR_DOWN = {0.0, -1.0, 0.0};

View file

@ -1,5 +1,5 @@
#ifndef _PAYSAGES_EUCLID_H_
#define _PAYSAGES_EUCLID_H_
#ifndef _PAYSAGES_TOOLS_EUCLID_H_
#define _PAYSAGES_TOOLS_EUCLID_H_
#include "pack.h"

View file

@ -0,0 +1,184 @@
#include "lighting.h"
#include <stdlib.h>
#include <math.h>
#include <unistd.h>
#include <string.h>
#define MAX_CALLBACK_COUNT 10
#define MAX_LIGHT_COUNT 30
typedef struct
{
FuncLightingAlterLight filter;
void* data;
} LightFilterCallback;
struct LightingManager
{
int callbacks_count;
LightFilterCallback callbacks[MAX_CALLBACK_COUNT];
};
struct LightStatus
{
LightingManager* manager;
Vector3 location;
Vector3 eye;
int light_count;
LightDefinition lights[MAX_LIGHT_COUNT];
};
LightingManager* lightingManagerCreate()
{
LightingManager* result;
result = malloc(sizeof(LightingManager));
result->callbacks_count = 0;
return result;
}
void lightingManagerDelete(LightingManager* filter)
{
free(filter);
}
void lightingManagerRegisterFilter(LightingManager* filter, FuncLightingAlterLight callback, void* data)
{
if (filter->callbacks_count < MAX_CALLBACK_COUNT)
{
filter->callbacks[filter->callbacks_count].filter = callback;
filter->callbacks[filter->callbacks_count].data = data;
filter->callbacks_count++;
}
}
LightStatus* lightingCreateStatus(LightingManager* manager, Vector3 location, Vector3 eye)
{
LightStatus* result;
result = malloc(sizeof(LightStatus));
result->manager = manager;
result->location = location;
result->eye = eye;
result->light_count = 0;
return result;
}
void lightingDeleteStatus(LightStatus* status)
{
free(status);
}
void lightingPushLight(LightStatus* status, LightDefinition* light)
{
if (status->light_count < MAX_LIGHT_COUNT)
{
int i;
LightingManager* manager = status->manager;
LightDefinition final = *light;
for (i = 0; i < manager->callbacks_count; i++)
{
LightFilterCallback callback = manager->callbacks[i];
LightDefinition temp = final;
if (callback.filter(&temp, status->location, callback.data))
{
final = temp;
}
}
status->lights[status->light_count++] = final;
}
}
Color lightingApplyStatus(LightStatus* status, Vector3 normal, SurfaceMaterial* material)
{
int i;
Color final, result;
final.r = final.g = final.b = 0.0;
final.a = material->base.a;
for (i = 0; i < status->light_count; i++)
{
result = lightingApplyOneLight(status->lights + i, status->eye, status->location, normal, material);
final.r += result.r;
final.g += result.g;
final.b += result.b;
}
return result;
}
Color lightingApplyOneLight(LightDefinition* light, Vector3 eye, Vector3 location, Vector3 normal, SurfaceMaterial* material)
{
Color result, light_color;
double diffuse, specular, normal_norm;
Vector3 view, reflect, direction_inv;
light_color = light->color;
direction_inv = v3Scale(light->direction, -1.0);
normal_norm = v3Norm(normal);
if (normal_norm > 1.0)
{
normal_norm = 1.0;
}
normal = v3Normalize(normal);
diffuse = v3Dot(direction_inv, normal);
if (diffuse > 0.0)
{
if (material->shininess > 0.0 && light->reflection > 0.0)
{
view = v3Normalize(v3Sub(location, eye));
reflect = v3Sub(direction_inv, v3Scale(normal, 2.0 * v3Dot(direction_inv, normal)));
specular = v3Dot(reflect, view);
if (specular > 0.0)
{
specular = pow(specular, material->shininess) * material->reflection;
}
else
{
specular = 0.0;
}
}
else
{
specular = 0.0;
}
}
else
{
diffuse = 0.0;
specular = 0.0;
}
specular *= normal_norm * light->reflection;
diffuse = 1.0 - normal_norm + diffuse * normal_norm;
result.r = material->base.r * diffuse * light_color.r + specular * light_color.r;
result.g = material->base.g * diffuse * light_color.g + specular * light_color.g;
result.b = material->base.b * diffuse * light_color.b + specular * light_color.b;
result.a = material->base.a;
return result;
}
void materialSave(PackStream* stream, SurfaceMaterial* material)
{
colorSave(stream, &material->base);
packWriteDouble(stream, &material->reflection);
packWriteDouble(stream, &material->shininess);
}
void materialLoad(PackStream* stream, SurfaceMaterial* material)
{
colorLoad(stream, &material->base);
packReadDouble(stream, &material->reflection);
packReadDouble(stream, &material->shininess);
}

View file

@ -0,0 +1,51 @@
#ifndef _PAYSAGES_TOOLS_LIGHTING_H_
#define _PAYSAGES_TOOLS_LIGHTING_H_
#include "euclid.h"
#include "color.h"
#include "pack.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct
{
Color base;
double reflection;
double shininess;
} SurfaceMaterial;
typedef struct
{
Vector3 direction; /* Global direction of the light */
Color color; /* Main color of the light */
double reflection; /* Reflected factor of the light (for specular lighting) */
int filtered; /* Should the light be filtered (by atmosphere, water...) */
int masked; /* Should the light be masked (cast shadows..) */
} LightDefinition;
typedef int (*FuncLightingAlterLight)(LightDefinition* light, Vector3 at, void* data);
typedef struct LightingManager LightingManager;
typedef struct LightStatus LightStatus;
LightingManager* lightingManagerCreate();
void lightingManagerDelete(LightingManager* filter);
void lightingManagerRegisterFilter(LightingManager* filter, FuncLightingAlterLight callback, void* data);
LightStatus* lightingCreateStatus(LightingManager* manager, Vector3 location, Vector3 eye);
void lightingDeleteStatus(LightStatus* status);
void lightingPushLight(LightStatus* status, LightDefinition* light);
Color lightingApplyStatus(LightStatus* status, Vector3 normal, SurfaceMaterial* material);
Color lightingApplyOneLight(LightDefinition* light, Vector3 eye, Vector3 location, Vector3 normal, SurfaceMaterial* material);
void materialSave(PackStream* stream, SurfaceMaterial* material);
void materialLoad(PackStream* stream, SurfaceMaterial* material);
#ifdef __cplusplus
}
#endif
#endif

View file

@ -1,5 +1,5 @@
#ifndef _PAYSAGES_PACK_H_
#define _PAYSAGES_PACK_H_
#ifndef _PAYSAGES_TOOLS_PACK_H_
#define _PAYSAGES_TOOLS_PACK_H_
#ifdef __cplusplus
extern "C" {

View file

@ -9,8 +9,8 @@
extern "C" {
#endif
#include "../color.h"
#include "../pack.h"
#include "color.h"
#include "pack.h"
typedef struct Texture2D Texture2D;
typedef struct Texture3D Texture3D;

View file

@ -1,10 +1,7 @@
#include "water.h"
#include "shared/types.h"
#include "color.h"
#include "euclid.h"
#include "render.h"
#include "lighting.h"
#include "tools.h"
#include <math.h>
@ -313,7 +310,7 @@ WaterResult waterGetColorDetail(WaterDefinition* definition, Renderer* renderer,
RayCastingResult refracted;
Vector3 normal;
Color color;
LightStatus light;
LightStatus* light;
SurfaceMaterial material;
double detail, depth;
@ -354,8 +351,9 @@ WaterResult waterGetColorDetail(WaterDefinition* definition, Renderer* renderer,
_applyFoam(definition, location, normal, detail, &material);
renderer->getLightStatus(renderer, &light, location);
color = renderer->applyLightStatus(renderer, &light, location, normal, material);
light = lightingCreateStatus(renderer->lighting, location, renderer->camera_location);
renderer->atmosphere->getLightingStatus(renderer, light, normal, 0);
color = lightingApplyStatus(light, normal, &material);
color = renderer->atmosphere->applyAerialPerspective(renderer, location, color);
color = renderer->applyClouds(renderer, color, renderer->camera_location, location);
@ -406,6 +404,10 @@ void waterRender(WaterDefinition* definition, Renderer* renderer)
double radius_int, radius_ext, base_chunk_size, chunk_size;
base_chunk_size = 2.0 / (double)renderer->render_quality;
if (renderer->render_quality > 7)
{
base_chunk_size *= 0.5;
}
chunk_factor = 1;
chunk_count = 2;

View file

@ -1,11 +1,12 @@
#ifndef _PAYSAGES_WATER_H_
#define _PAYSAGES_WATER_H_
#include "shared/types.h"
#include "tools/color.h"
#include "tools/euclid.h"
#include "tools/lighting.h"
#include "tools/pack.h"
#include "renderer.h"
#include "lighting.h"
#include "noise.h"
#include "pack.h"
#ifdef __cplusplus
extern "C" {

View file

@ -1,8 +1,6 @@
#include "zone.h"
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include "tools.h"

View file

@ -1,9 +1,9 @@
#ifndef _PAYSAGES_ZONE_H_
#define _PAYSAGES_ZONE_H_
#include "shared/types.h"
#include "curve.h"
#include "pack.h"
#include "tools/euclid.h"
#include "tools/curve.h"
#include "tools/pack.h"
#ifdef __cplusplus
extern "C" {