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:
parent
dd0fceb5c9
commit
b46060f3c4
80 changed files with 478 additions and 892 deletions
|
@ -30,6 +30,7 @@ Clouds :
|
|||
|
||||
Rendering :
|
||||
* Added full scene antialiasing (FSAA).
|
||||
* High Dynamic Range lighting.
|
||||
|
||||
GUI :
|
||||
* Improved curve rendering.
|
||||
|
|
1
TODO
1
TODO
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
#include <QLabel>
|
||||
#include <QHash>
|
||||
#include "previewosd.h"
|
||||
#include "../lib_paysages/pack.h"
|
||||
#include "../lib_paysages/tools/pack.h"
|
||||
|
||||
class _ContextChoice
|
||||
{
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#include <QPushButton>
|
||||
#include "widgetcurveeditor.h"
|
||||
|
||||
#include "../lib_paysages/curve.h"
|
||||
#include "../lib_paysages/tools/curve.h"
|
||||
|
||||
class DialogCurve : public QDialog
|
||||
{
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
@ -19,15 +19,15 @@ class ExplorerChunkSky:public BaseExplorerChunk
|
|||
{
|
||||
public:
|
||||
ExplorerChunkSky(Renderer* renderer, double size, SkyboxOrientation orientation);
|
||||
|
||||
|
||||
void onRenderEvent(QGLWidget* widget);
|
||||
double getDisplayedSizeHint(CameraDefinition* camera);
|
||||
Color getTextureColor(double x, double y);
|
||||
|
||||
|
||||
private:
|
||||
SkyboxOrientation _orientation;
|
||||
double _box_size;
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -3,34 +3,34 @@
|
|||
|
||||
#include "baseexplorerchunk.h"
|
||||
#include "../lib_paysages/renderer.h"
|
||||
#include "../lib_paysages/euclid.h"
|
||||
#include "../lib_paysages/tools/euclid.h"
|
||||
|
||||
class ExplorerChunkTerrain:public BaseExplorerChunk
|
||||
{
|
||||
public:
|
||||
ExplorerChunkTerrain(Renderer* renderer, double x, double z, double size, int nbchunks);
|
||||
~ExplorerChunkTerrain();
|
||||
|
||||
|
||||
void onCameraEvent(CameraDefinition* camera);
|
||||
void onResetEvent();
|
||||
bool onMaintainEvent();
|
||||
void onRenderEvent(QGLWidget* widget);
|
||||
double getDisplayedSizeHint(CameraDefinition* camera);
|
||||
Color getTextureColor(double x, double y);
|
||||
|
||||
|
||||
private:
|
||||
Vector3 getCenter();
|
||||
|
||||
|
||||
double _startx;
|
||||
double _startz;
|
||||
double _size;
|
||||
double _overall_step;
|
||||
|
||||
|
||||
double* _tessellation;
|
||||
int _tessellation_max_size;
|
||||
int _tessellation_current_size;
|
||||
double _tessellation_step;
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -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 ****************/
|
||||
|
|
|
@ -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();
|
||||
}
|
|
@ -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
|
|
@ -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;
|
||||
|
|
|
@ -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 ****************/
|
||||
|
|
|
@ -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 ****************/
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include <QWidget>
|
||||
#include "baseinput.h"
|
||||
|
||||
#include "../lib_paysages/color.h"
|
||||
#include "../lib_paysages/tools/color.h"
|
||||
|
||||
class InputColorGradation:public BaseInput
|
||||
{
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include <QWidget>
|
||||
#include "baseinput.h"
|
||||
|
||||
#include "../lib_paysages/curve.h"
|
||||
#include "../lib_paysages/tools/curve.h"
|
||||
|
||||
class InputCurve:public BaseInput
|
||||
{
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "baseinput.h"
|
||||
|
||||
#include "../lib_paysages/shared/types.h"
|
||||
#include "../lib_paysages/tools/lighting.h"
|
||||
|
||||
class InputMaterial:public BaseInput
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include <QMainWindow>
|
||||
#include "formrender.h"
|
||||
#include "../lib_paysages/pack.h"
|
||||
#include "../lib_paysages/tools/pack.h"
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
|
@ -12,7 +12,7 @@ class MainWindow : public QMainWindow
|
|||
public:
|
||||
explicit MainWindow(QWidget *parent = 0);
|
||||
virtual bool event(QEvent* event);
|
||||
|
||||
|
||||
static void guiSaveCallback(PackStream* stream, void* data);
|
||||
static void guiLoadCallback(PackStream* stream, void* data);
|
||||
|
||||
|
@ -22,16 +22,16 @@ public slots:
|
|||
void fileNew();
|
||||
void fileSave();
|
||||
void fileLoad();
|
||||
|
||||
|
||||
void showAboutDialog();
|
||||
|
||||
void quickPreview();
|
||||
void explore3D();
|
||||
|
||||
|
||||
private:
|
||||
void guiSave(PackStream* stream);
|
||||
void guiLoad(PackStream* stream);
|
||||
|
||||
|
||||
QVector<BaseForm*> _forms;
|
||||
FormRender* _form_render;
|
||||
};
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include <QWidget>
|
||||
|
||||
#include "../lib_paysages/color.h"
|
||||
#include "../lib_paysages/tools/color.h"
|
||||
|
||||
typedef enum
|
||||
{
|
||||
|
@ -20,7 +20,7 @@ public:
|
|||
PreviewColorGradation(QWidget* parent, ColorGradation* gradation, EnumColorGradationBand band);
|
||||
void paintEvent(QPaintEvent* event);
|
||||
void mouseReleaseEvent(QMouseEvent* event);
|
||||
|
||||
|
||||
signals:
|
||||
void clicked();
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
@ -18,7 +18,7 @@ class DialogWithPreview:public QDialog
|
|||
Q_OBJECT
|
||||
public:
|
||||
DialogWithPreview(QWidget* parent);
|
||||
|
||||
|
||||
protected:
|
||||
virtual bool event(QEvent* event);
|
||||
};
|
||||
|
|
|
@ -3,38 +3,38 @@
|
|||
|
||||
#include <QWidget>
|
||||
#include <QColor>
|
||||
#include "../lib_paysages/curve.h"
|
||||
#include "../lib_paysages/tools/curve.h"
|
||||
|
||||
class WidgetCurveEditor : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
||||
public:
|
||||
WidgetCurveEditor(QWidget* parent, double xmin, double xmax, double ymin, double ymax);
|
||||
~WidgetCurveEditor();
|
||||
|
||||
|
||||
void setAxisLabels(QString xlabel, QString ylabel);
|
||||
|
||||
|
||||
void setCurve(Curve* curve);
|
||||
void getCurve(Curve* curve);
|
||||
|
||||
|
||||
void setPenColor(QColor color);
|
||||
|
||||
|
||||
signals:
|
||||
void liveChanged();
|
||||
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent* event);
|
||||
void mousePressEvent(QMouseEvent* event);
|
||||
void mouseMoveEvent(QMouseEvent* event);
|
||||
void mouseReleaseEvent(QMouseEvent* event);
|
||||
void mouseDoubleClickEvent(QMouseEvent* event);
|
||||
|
||||
|
||||
private:
|
||||
void curveToScreen(double curve_x, double curve_y, int* screen_x, int* screen_y);
|
||||
void screenToCurve(int screen_x, int screen_y, double* curve_x, double* curve_y);
|
||||
int getPointAt(int x, int y);
|
||||
|
||||
|
||||
double _xmin;
|
||||
double _xmax;
|
||||
double _ymin;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
|
@ -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 */
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
|
@ -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" {
|
||||
|
@ -34,7 +34,7 @@ Vector3 cameraProject(CameraDefinition* camera, Renderer* renderer, Vector3 poin
|
|||
Vector3 cameraUnproject(CameraDefinition* camera, Renderer* renderer, Vector3 point);
|
||||
/*void cameraPushOverlay(CameraDefinition* camera, Color col, f_RenderFragmentCallback callback);*/
|
||||
int cameraIsBoxInView(CameraDefinition* camera, Vector3 center, double xsize, double ysize, double zsize);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
/* Geographic area definition */
|
||||
|
||||
#include "pack.h"
|
||||
#include "tools/pack.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -27,7 +27,7 @@ void geoareaLoad(PackStream* stream, GeoArea* geoarea);
|
|||
|
||||
void geoareaToLocal(GeoArea* geoarea, double absolute_x, double absolute_z, double* local_x, double* local_z);
|
||||
void geoareaFromLocal(GeoArea* geoarea, double local_x, double local_z, double* absolute_x, double* absolute_z);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
/* Factorized layer management (with names) */
|
||||
|
||||
#include "pack.h"
|
||||
#include "tools/pack.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -15,7 +15,7 @@ typedef void (*LayerCallbackCopy)(void* source, void* definition);
|
|||
typedef void (*LayerCallbackValidate)(void* layer);
|
||||
typedef void (*LayerCallbackSave)(PackStream* stream, void* layer);
|
||||
typedef void (*LayerCallbackLoad)(PackStream* stream, void* layer);
|
||||
|
||||
|
||||
typedef struct {
|
||||
LayerCallbackCreate callback_create;
|
||||
LayerCallbackDelete callback_delete;
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -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
|
|
@ -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"
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -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
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef _PAYSAGES_NOISE_H_
|
||||
#define _PAYSAGES_NOISE_H_
|
||||
|
||||
#include "pack.h"
|
||||
#include "tools/pack.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -19,7 +19,7 @@ typedef struct
|
|||
NoiseFunctionAlgorithm algorithm;
|
||||
double ridge_factor;
|
||||
} NoiseFunction;
|
||||
|
||||
|
||||
struct NoiseLevel
|
||||
{
|
||||
double scaling;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef _PAYSAGES_NOISENAIVE_H_
|
||||
#define _PAYSAGES_NOISENAIVE_H_
|
||||
|
||||
#include "pack.h"
|
||||
#include "tools/pack.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -15,7 +15,7 @@ double noiseNaiveGet1DValue(double x);
|
|||
double noiseNaiveGet2DValue(double x, double y);
|
||||
double noiseNaiveGet3DValue(double x, double y, double z);
|
||||
/*double noiseNaiveGet4DValue(double x, double y, double z, double w);*/
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -4,8 +4,6 @@
|
|||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "shared/types.h"
|
||||
#include "color.h"
|
||||
#include "renderer.h"
|
||||
#include "system.h"
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
/* Library dependent features */
|
||||
|
||||
#include "color.h"
|
||||
#include "tools/color.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "public.h"
|
||||
#include "private.h"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
/*
|
||||
* Terrain presets.
|
||||
*/
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
#ifndef _PAYSAGES_TOOLS_H_
|
||||
#define _PAYSAGES_TOOLS_H_
|
||||
|
||||
#include "pack.h"
|
||||
#include "shared/types.h"
|
||||
#include "tools/euclid.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#define UNUSED(_x_) ((void)(_x_))
|
||||
|
||||
double toolsRandom();
|
||||
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
return ((x*(A*x+C*B)+D*E)/(x*(A*x+B)+D*F))-E/F;
|
||||
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);
|
|
@ -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"
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "tools.h"
|
||||
#include "../tools.h"
|
||||
|
||||
#define MAX_NB_POINTS 40
|
||||
|
||||
|
@ -16,11 +16,11 @@ struct Curve
|
|||
Curve* curveCreate()
|
||||
{
|
||||
Curve* result;
|
||||
|
||||
|
||||
result = malloc(sizeof(Curve));
|
||||
result->nbpoints = 0;
|
||||
result->default_value = 0.0;
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -37,7 +37,7 @@ void curveCopy(Curve* source, Curve* destination)
|
|||
void curveSave(PackStream* stream, Curve* curve)
|
||||
{
|
||||
int i;
|
||||
|
||||
|
||||
packWriteDouble(stream, &curve->default_value);
|
||||
packWriteInt(stream, &curve->nbpoints);
|
||||
for (i = 0; i < curve->nbpoints; i++)
|
||||
|
@ -50,7 +50,7 @@ void curveSave(PackStream* stream, Curve* curve)
|
|||
void curveLoad(PackStream* stream, Curve* curve)
|
||||
{
|
||||
int i;
|
||||
|
||||
|
||||
packReadDouble(stream, &curve->default_value);
|
||||
packReadInt(stream, &curve->nbpoints);
|
||||
for (i = 0; i < curve->nbpoints; i++)
|
||||
|
@ -86,10 +86,10 @@ int curveAddPoint(Curve* curve, CurvePoint* point)
|
|||
int curveQuickAddPoint(Curve* curve, double position, double value)
|
||||
{
|
||||
CurvePoint point;
|
||||
|
||||
|
||||
point.position = position;
|
||||
point.value = value;
|
||||
|
||||
|
||||
return curveAddPoint(curve, &point);
|
||||
}
|
||||
|
|
@ -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"
|
||||
|
|
@ -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};
|
||||
|
@ -386,17 +385,17 @@ Matrix4 m4Inverse(Matrix4 m)
|
|||
result.e = d * (m.g * (m.i * m.p - m.m * m.l) + m.k * (m.m * m.h - m.e * m.p) + m.o * (m.e * m.l - m.i * m.h));
|
||||
result.i = d * (m.h * (m.i * m.n - m.m * m.j) + m.l * (m.m * m.f - m.e * m.n) + m.p * (m.e * m.j - m.i * m.f));
|
||||
result.m = d * (m.e * (m.n * m.k - m.j * m.o) + m.i * (m.f * m.o - m.n * m.g) + m.m * (m.j * m.g - m.f * m.k));
|
||||
|
||||
|
||||
result.b = d * (m.j * (m.c * m.p - m.o * m.d) + m.n * (m.k * m.d - m.c * m.l) + m.b * (m.o * m.l - m.k * m.p));
|
||||
result.f = d * (m.k * (m.a * m.p - m.m * m.d) + m.o * (m.i * m.d - m.a * m.l) + m.c * (m.m * m.l - m.i * m.p));
|
||||
result.j = d * (m.l * (m.a * m.n - m.m * m.b) + m.p * (m.i * m.b - m.a * m.j) + m.d * (m.m * m.j - m.i * m.n));
|
||||
result.n = d * (m.i * (m.n * m.c - m.b * m.o) + m.m * (m.b * m.k - m.j * m.c) + m.a * (m.j * m.o - m.n * m.k));
|
||||
|
||||
|
||||
result.c = d * (m.n * (m.c * m.h - m.g * m.d) + m.b * (m.g * m.p - m.o * m.h) + m.f * (m.o * m.d - m.c * m.p));
|
||||
result.g = d * (m.o * (m.a * m.h - m.e * m.d) + m.c * (m.e * m.p - m.m * m.h) + m.g * (m.m * m.d - m.a * m.p));
|
||||
result.k = d * (m.p * (m.a * m.f - m.e * m.b) + m.d * (m.e * m.n - m.m * m.f) + m.h * (m.m * m.b - m.a * m.n));
|
||||
result.o = d * (m.m * (m.f * m.c - m.b * m.g) + m.a * (m.n * m.g - m.f * m.o) + m.e * (m.b * m.o - m.n * m.c));
|
||||
|
||||
|
||||
result.d = d * (m.b * (m.k * m.h - m.g * m.l) + m.f * (m.c * m.l - m.k * m.d) + m.j * (m.g * m.d - m.c * m.h));
|
||||
result.h = d * (m.c * (m.i * m.h - m.e * m.l) + m.g * (m.a * m.l - m.i * m.d) + m.k * (m.e * m.d - m.a * m.h));
|
||||
result.l = d * (m.d * (m.i * m.f - m.e * m.j) + m.h * (m.a * m.j - m.i * m.b) + m.l * (m.e * m.b - m.a * m.f));
|
|
@ -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"
|
||||
|
184
lib_paysages/tools/lighting.c
Normal file
184
lib_paysages/tools/lighting.c
Normal 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);
|
||||
}
|
51
lib_paysages/tools/lighting.h
Normal file
51
lib_paysages/tools/lighting.h
Normal 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
|
|
@ -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" {
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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" {
|
||||
|
@ -16,7 +17,7 @@ typedef enum
|
|||
WATER_PRESET_LAKE,
|
||||
WATER_PRESET_SEA
|
||||
} WaterPreset;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
double height;
|
||||
|
@ -26,15 +27,15 @@ typedef struct
|
|||
Color depth_color;
|
||||
double transparency_depth;
|
||||
double lighting_depth;
|
||||
|
||||
|
||||
double scaling;
|
||||
double turbulence;
|
||||
double waves_height;
|
||||
double detail_height;
|
||||
|
||||
|
||||
double foam_coverage;
|
||||
SurfaceMaterial foam_material;
|
||||
|
||||
|
||||
NoiseGenerator* _waves_noise;
|
||||
} WaterDefinition;
|
||||
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
#include "zone.h"
|
||||
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include "tools.h"
|
||||
|
@ -111,10 +109,10 @@ void zoneCopy(Zone* source, Zone* destination)
|
|||
{
|
||||
curveCopy(source->value_by_height, destination->value_by_height);
|
||||
curveCopy(source->value_by_slope, destination->value_by_slope);
|
||||
|
||||
|
||||
memcpy(destination->circles_included, source->circles_included, sizeof(Circle) * source->circles_included_count);
|
||||
destination->circles_included_count = source->circles_included_count;
|
||||
|
||||
|
||||
memcpy(destination->circles_excluded, source->circles_excluded, sizeof(Circle) * source->circles_excluded_count);
|
||||
destination->circles_excluded_count = source->circles_excluded_count;
|
||||
}
|
||||
|
|
|
@ -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" {
|
||||
|
|
Loading…
Reference in a new issue