From 6ff990bf8f19132c39bcde3052628d383516f5eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Tue, 5 Jun 2012 20:22:12 +0000 Subject: [PATCH] paysages : Changed lighting dispatching system (through Renderer) for future improvements. git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@336 b1fd45b6-86a6-48da-8261-f70d1f35bdcc --- gui_qt/formclouds.cpp | 19 ++++++---- gui_qt/formrender.cpp | 14 ++++---- gui_qt/formterrain.cpp | 15 ++++---- gui_qt/formtextures.cpp | 12 +++---- gui_qt/formwater.cpp | 18 ++++------ gui_qt/inputboolean.cpp | 1 + gui_qt/inputdouble.cpp | 1 + gui_qt/inputint.cpp | 1 + gui_qt/widgetwanderer.cpp | 12 +++---- i18n/paysages_fr.ts | 70 ++++++++++++++++++++----------------- lib_paysages/clouds.c | 17 +++++++-- lib_paysages/lighting.c | 17 +++------ lib_paysages/lighting.h | 8 ++--- lib_paysages/renderer.c | 17 +++++---- lib_paysages/renderer.h | 6 ++-- lib_paysages/scenery.c | 39 +++++++++++++-------- lib_paysages/shared/types.h | 3 ++ lib_paysages/textures.c | 5 ++- lib_paysages/water.c | 4 ++- 19 files changed, 153 insertions(+), 126 deletions(-) diff --git a/gui_qt/formclouds.cpp b/gui_qt/formclouds.cpp index 13f4d2c..ec568e1 100644 --- a/gui_qt/formclouds.cpp +++ b/gui_qt/formclouds.cpp @@ -18,6 +18,7 @@ public: { _renderer = rendererCreate(); _renderer.render_quality = 3; + _renderer.applyLightStatus = _applyLightStatus; _preview_layer = cloudsLayerCreateDefinition(); @@ -46,6 +47,10 @@ protected: { cloudsLayerCopyDefinition(&_layer, &_preview_layer); } + static Color _applyLightStatus(Renderer* renderer, LightStatus* status, Vector3 location, Vector3 normal, SurfaceMaterial material) + { + return COLOR_WHITE; + } private: Renderer _renderer; @@ -76,8 +81,8 @@ public: _renderer = rendererCreate(); _renderer.render_quality = 3; - _renderer.applyLightingToSurface = _applyLightingToSurface; - _renderer.maskLight = _maskLight; + _renderer.alterLight = _alterLight; + _renderer.getLightStatus = _getLightStatus; _renderer.customData[0] = &_preview_layer; _renderer.customData[1] = &_lighting; @@ -128,13 +133,15 @@ private: return 1.0 - dist / layer->ymax; } } - static Color _applyLightingToSurface(Renderer* renderer, Vector3 location, Vector3 normal, SurfaceMaterial material) + + static void _alterLight(Renderer* renderer, LightDefinition* light, Vector3 location) { - return lightingApplyToSurface((LightingDefinition*)renderer->customData[1], renderer, location, normal, material); + light->color = cloudsLayerFilterLight((CloudsLayerDefinition*)renderer->customData[0], renderer, light->color, location, v3Scale(light->direction, -1000.0), v3Scale(light->direction, -1.0)); } - static Color _maskLight(Renderer* renderer, Color light_color, Vector3 at_location, Vector3 light_location, Vector3 direction_to_light) + + static void _getLightStatus(Renderer* renderer, LightStatus* status, Vector3 location) { - return cloudsLayerFilterLight((CloudsLayerDefinition*)renderer->customData[0], renderer, light_color, at_location, light_location, direction_to_light); + lightingGetStatus((LightingDefinition*)renderer->customData[1], renderer, location, status); } }; diff --git a/gui_qt/formrender.cpp b/gui_qt/formrender.cpp index 6a96bb0..31840d9 100644 --- a/gui_qt/formrender.cpp +++ b/gui_qt/formrender.cpp @@ -17,8 +17,8 @@ public: _renderer = rendererCreate(); _renderer.applyTextures = _applyTextures; _renderer.getTerrainHeight = _getTerrainHeight; - _renderer.applyLightingToSurface = _applyLightingToSurface; - _renderer.maskLight = _maskLight; + _renderer.alterLight = _alterLight; + _renderer.getLightStatus = _getLightStatus; _renderer.camera_location.x = 0.0; _renderer.camera_location.y = 50.0; _renderer.camera_location.z = 0.0; @@ -79,14 +79,14 @@ private: return texturesGetColor((TexturesDefinition*)(renderer->customData[1]), renderer, location.x, location.z, precision); } - static Color _applyLightingToSurface(Renderer* renderer, Vector3 location, Vector3 normal, SurfaceMaterial material) + static void _alterLight(Renderer* renderer, LightDefinition* light, Vector3 location) { - return lightingApplyToSurface((LightingDefinition*)renderer->customData[2], renderer, location, normal, material); + light->color = terrainLightFilter((TerrainDefinition*)(renderer->customData[0]), renderer, light->color, location, v3Scale(light->direction, -1000.0), v3Scale(light->direction, -1.0)); } - - static Color _maskLight(Renderer* renderer, Color light_color, Vector3 at_location, Vector3 light_location, Vector3 direction_to_light) + + static void _getLightStatus(Renderer* renderer, LightStatus* status, Vector3 location) { - return terrainLightFilter((TerrainDefinition*)(renderer->customData[0]), renderer, light_color, at_location, light_location, direction_to_light); + lightingGetStatus((LightingDefinition*)renderer->customData[2], renderer, location, status); } }; diff --git a/gui_qt/formterrain.cpp b/gui_qt/formterrain.cpp index 4743162..0abbc1f 100644 --- a/gui_qt/formterrain.cpp +++ b/gui_qt/formterrain.cpp @@ -50,8 +50,8 @@ public: _renderer.render_quality = 3; _renderer.applyTextures = _applyTextures; _renderer.getTerrainHeight = _getTerrainHeight; - _renderer.applyLightingToSurface = _applyLightingToSurface; - _renderer.maskLight = _maskLight; + _renderer.alterLight = _alterLight; + _renderer.getLightStatus = _getLightStatus; _renderer.camera_location.x = 0.0; _renderer.camera_location.y = 50.0; _renderer.camera_location.z = 0.0; @@ -124,16 +124,17 @@ private: { return texturesGetColor((TexturesDefinition*)(renderer->customData[1]), renderer, location.x, location.z, precision); } - - static Color _applyLightingToSurface(Renderer* renderer, Vector3 location, Vector3 normal, SurfaceMaterial material) + + static void _alterLight(Renderer* renderer, LightDefinition* light, Vector3 location) { - return lightingApplyToSurface((LightingDefinition*)renderer->customData[2], renderer, location, normal, material); + light->color = terrainLightFilter((TerrainDefinition*)(renderer->customData[0]), renderer, light->color, location, v3Scale(light->direction, -1000.0), v3Scale(light->direction, -1.0)); } - static Color _maskLight(Renderer* renderer, Color light_color, Vector3 at_location, Vector3 light_location, Vector3 direction_to_light) + static void _getLightStatus(Renderer* renderer, LightStatus* status, Vector3 location) { - return terrainLightFilter((TerrainDefinition*)(renderer->customData[0]), renderer, light_color, at_location, light_location, direction_to_light); + lightingGetStatus((LightingDefinition*)renderer->customData[2], renderer, location, status); } + }; /**************** Form ****************/ diff --git a/gui_qt/formtextures.cpp b/gui_qt/formtextures.cpp index 1f17b50..d4215f7 100644 --- a/gui_qt/formtextures.cpp +++ b/gui_qt/formtextures.cpp @@ -89,7 +89,7 @@ public: _renderer = rendererCreate(); _renderer.render_quality = 3; - _renderer.applyLightingToSurface = _applyLightingToSurface; + _renderer.getLightStatus = _getLightStatus; _renderer.customData[0] = &_lighting; _renderer.camera_location.x = 0.0; _renderer.camera_location.y = 20.0; @@ -115,15 +115,15 @@ protected: zoneCopy(_zone, _preview_layer.zone); } private: - static Color _applyLightingToSurface(Renderer* renderer, Vector3 location, Vector3 normal, SurfaceMaterial material) - { - return lightingApplyToSurface((LightingDefinition*)renderer->customData[0], renderer, location, normal, material); - } - Zone* _zone; Renderer _renderer; TextureLayerDefinition _preview_layer; LightingDefinition _lighting; + + static void _getLightStatus(Renderer* renderer, LightStatus* status, Vector3 location) + { + lightingGetStatus((LightingDefinition*)renderer->customData[0], renderer, location, status); + } }; /**************** Form ****************/ diff --git a/gui_qt/formwater.cpp b/gui_qt/formwater.cpp index 015ddaa..30969bd 100644 --- a/gui_qt/formwater.cpp +++ b/gui_qt/formwater.cpp @@ -76,7 +76,7 @@ public: _renderer = rendererCreate(); _renderer.rayWalking = _rayWalking; - _renderer.applyLightingToSurface = _applyLightingToSurface; + _renderer.getLightStatus = _getLightStatus; _renderer.customData[0] = &_water; _renderer.customData[1] = &_lighting; @@ -140,7 +140,7 @@ private: y = location.y + direction.y * (0.0 - location.z) / direction.z; //if (((int)ceil(x * 0.2) % 2 == 0) ^ ((int)ceil(y * 0.2 - 0.5) % 2 == 0)) - if (y * 0.1 > sin(x - M_PI_2)) + if (y * 0.1 > x * 0.03 + sin(x - M_PI_2)) { result.hit_color = COLOR_WHITE; } @@ -155,16 +155,10 @@ private: return result; } - static Color _applyLightingToSurface(Renderer* renderer, Vector3 location, Vector3 normal, SurfaceMaterial material) + + static void _getLightStatus(Renderer* renderer, LightStatus* status, Vector3 location) { - if (location.x >= 0.0) - { - return lightingApplyToSurface((LightingDefinition*)renderer->customData[1], renderer, location, normal, material); - } - else - { - return material.base; - } + lightingGetStatus((LightingDefinition*)renderer->customData[1], renderer, location, status); } }; @@ -177,7 +171,7 @@ FormWater::FormWater(QWidget *parent): previewCoverage = new PreviewWaterCoverage(this); previewColor = new PreviewWaterColor(this); addPreview(previewCoverage, QString(tr("Coverage preview"))); - addPreview(previewColor, QString(tr("Rendered preview (without/with lighting)"))); + addPreview(previewColor, QString(tr("Rendered preview"))); addInputDouble(tr("Height"), &_definition.height, -10.0, 10.0, 0.1, 1.0); addInputMaterial(tr("Surface material"), &_definition.material); diff --git a/gui_qt/inputboolean.cpp b/gui_qt/inputboolean.cpp index 67a9f9b..27d8b0f 100644 --- a/gui_qt/inputboolean.cpp +++ b/gui_qt/inputboolean.cpp @@ -12,6 +12,7 @@ InputBoolean::InputBoolean(QWidget* form, QString label, int* value) : BaseInput connect(checkbox, SIGNAL(stateChanged(int)), this, SLOT(applyValue())); _preview = new QLabel(form); + ((QLabel*)_preview)->setAlignment(Qt::AlignCenter); _control = checkbox; } diff --git a/gui_qt/inputdouble.cpp b/gui_qt/inputdouble.cpp index c4ba377..60234ac 100644 --- a/gui_qt/inputdouble.cpp +++ b/gui_qt/inputdouble.cpp @@ -23,6 +23,7 @@ InputDouble::InputDouble(QWidget* form, QString label, double* value, double min connect(slider, SIGNAL(valueChanged(int)), this, SLOT(applyValue())); _preview = new QLabel(form); + ((QLabel*)_preview)->setAlignment(Qt::AlignCenter); _control = slider; } diff --git a/gui_qt/inputint.cpp b/gui_qt/inputint.cpp index c168eb1..c6c3939 100644 --- a/gui_qt/inputint.cpp +++ b/gui_qt/inputint.cpp @@ -22,6 +22,7 @@ InputInt::InputInt(QWidget* form, QString label, int* value, int min, int max, i connect(slider, SIGNAL(valueChanged(int)), this, SLOT(applyValue())); _preview = new QLabel(form); + ((QLabel*)_preview)->setAlignment(Qt::AlignCenter); _control = slider; } diff --git a/gui_qt/widgetwanderer.cpp b/gui_qt/widgetwanderer.cpp index 72dec37..5cd8dcf 100644 --- a/gui_qt/widgetwanderer.cpp +++ b/gui_qt/widgetwanderer.cpp @@ -55,14 +55,14 @@ static Color _applyTextures(Renderer* renderer, Vector3 location, double precisi return texturesGetColor((TexturesDefinition*)(renderer->customData[1]), renderer, location.x, location.z, precision); } -static Color _applyLightingToSurface(Renderer* renderer, Vector3 location, Vector3 normal, SurfaceMaterial material) +static void _alterLight(Renderer* renderer, LightDefinition* light, Vector3 location) { - return lightingApplyToSurface((LightingDefinition*)renderer->customData[2], renderer, location, normal, material); + light->color = terrainLightFilter((TerrainDefinition*)(renderer->customData[0]), renderer, light->color, location, v3Scale(light->direction, -1000.0), v3Scale(light->direction, -1.0)); } -static Color _maskLight(Renderer* renderer, Color light_color, Vector3 at_location, Vector3 light_location, Vector3 direction_to_light) +static void _getLightStatus(Renderer* renderer, LightStatus* status, Vector3 location) { - return terrainLightFilter((TerrainDefinition*)(renderer->customData[0]), renderer, light_color, at_location, light_location, direction_to_light); + lightingGetStatus((LightingDefinition*)renderer->customData[2], renderer, location, status); } WidgetWanderer::WidgetWanderer(QWidget *parent, CameraDefinition* camera): @@ -93,8 +93,8 @@ WidgetWanderer::WidgetWanderer(QWidget *parent, CameraDefinition* camera): _renderer.customData[3] = &_water; _renderer.applyTextures = _applyTextures; _renderer.getTerrainHeight = _getTerrainHeight; - _renderer.applyLightingToSurface = _applyLightingToSurface; - _renderer.maskLight = _maskLight; + _renderer.alterLight = _alterLight; + _renderer.getLightStatus = _getLightStatus; _updated = false; diff --git a/i18n/paysages_fr.ts b/i18n/paysages_fr.ts index 5fdd80f..35ac8d3 100644 --- a/i18n/paysages_fr.ts +++ b/i18n/paysages_fr.ts @@ -307,12 +307,12 @@ Maintenir Ctrl : Plus rapide FormClouds - + Layer coverage (no lighting) Couverture de la couche (sans éclairage) - + Color and lighting Echantillon éclairé @@ -329,37 +329,37 @@ Maintenir Ctrl : Plus rapide Altitude de fin - + Lower altitude - + Upper altitude - + Density by altitude - + Noise Bruit - + Coverage Couverture - + Scaling Echelle - + Material @@ -376,22 +376,22 @@ Maintenir Ctrl : Plus rapide Concentration de la réflexion de lumière - + Hardness to light - + Transparency depth Distance de transparence - + Light traversal depth Distance de traversée de la lumière - + Minimum lighting Eclairage minimal @@ -568,7 +568,7 @@ Maintenir Ctrl : Plus rapide FormTerrain - + Height preview (normalized) Aperçu de la hauteur (normalisée) @@ -577,22 +577,22 @@ Maintenir Ctrl : Plus rapide Aperçu du rendu (sans ombres) - + Lighted preview (no texture) Aperçu éclairé (sans texture) - + Noise Bruit - + Height Hauteur - + Scaling Echelle @@ -689,17 +689,16 @@ Maintenir Ctrl : Plus rapide FormWater - + Coverage preview Aperçu de la couverture - Rendered preview (without/with lighting) - Aperçu du rendu (sans/avec éclairage) + Aperçu du rendu (sans/avec éclairage) - + Height Hauteur @@ -716,47 +715,52 @@ Maintenir Ctrl : Plus rapide Concentration de la lumière réfléchie - + Surface material - + Transparency Transparence - + Reflection Reflets - + Transparency distance Distance maximale de transparence - + Depth color Couleur en profondeur - + + Rendered preview + + + + Light-through distance Distance de filtrage de la lumière - + Waves noise Bruit des vagues - + Waves height Hauteur des vagues - + Waves scaling Echelle des vagues @@ -764,12 +768,12 @@ Maintenir Ctrl : Plus rapide InputBoolean - + Yes Oui - + No Non diff --git a/lib_paysages/clouds.c b/lib_paysages/clouds.c index d7547cc..5232e30 100644 --- a/lib_paysages/clouds.c +++ b/lib_paysages/clouds.c @@ -153,9 +153,9 @@ CloudsLayerDefinition cloudsLayerCreateDefinition() result.material.base.a = 1.0; result.material.reflection = 0.3; result.material.shininess = 0.8; - result.hardness = 0.15; + result.hardness = 0.25; result.transparencydepth = 1.5; - result.lighttraversal = 3.0; + result.lighttraversal = 7.0; result.minimumlight = 0.4; result.scaling = 3.5; result.coverage = 0.45; @@ -487,6 +487,8 @@ static int _findSegments(CloudsLayerDefinition* definition, Renderer* renderer, static Color _applyLayerLighting(CloudsLayerDefinition* definition, Renderer* renderer, Vector3 position, double detail) { Vector3 normal; + Color col1, col2; + LightStatus light; normal = _getNormal(definition, position, 3.0); if (renderer->render_quality > 5) @@ -499,8 +501,17 @@ static Color _applyLayerLighting(CloudsLayerDefinition* definition, Renderer* re normal = v3Add(normal, _getNormal(definition, position, 0.5)); } 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); + + col1.r = (col1.r + col2.r) / 2.0; + col1.g = (col1.g + col2.g) / 2.0; + col1.b = (col1.b + col2.b) / 2.0; + col1.a = (col1.a + col2.a) / 2.0; - return renderer->applyLightingToSurface(renderer, position, normal, definition->material); + return col1; } Color cloudsGetLayerColor(CloudsLayerDefinition* definition, Renderer* renderer, Vector3 start, Vector3 end) diff --git a/lib_paysages/lighting.c b/lib_paysages/lighting.c index f4e59a3..5396cfb 100644 --- a/lib_paysages/lighting.c +++ b/lib_paysages/lighting.c @@ -150,24 +150,15 @@ void lightingDeleteLight(LightingDefinition* definition, int light) static int _getLightStatus(LightDefinition* definition, Renderer* renderer, Vector3 location, LightDefinition* result) { - Color light; - Vector3 direction_inv; + *result = *definition; - light = definition->color; - direction_inv = v3Scale(definition->direction, -1.0); - if (definition->masked) + if (definition->masked || definition->filtered) { - light = renderer->maskLight(renderer, light, location, v3Add(location, v3Scale(direction_inv, 1000.0)), direction_inv); - } - if (definition->filtered) - { - light = renderer->filterLight(renderer, light, location, v3Add(location, v3Scale(direction_inv, 1000.0)), direction_inv); + renderer->alterLight(renderer, result, location); } - if (light.r > 0.0 || light.g > 0.0 || light.b > 0.0) + if (result->color.r > 0.0 || result->color.g > 0.0 || result->color.b > 0.0) { - *result = *definition; - result->color = light; return 1; } else diff --git a/lib_paysages/lighting.h b/lib_paysages/lighting.h index a56e7b8..cb5cae7 100644 --- a/lib_paysages/lighting.h +++ b/lib_paysages/lighting.h @@ -11,7 +11,7 @@ extern "C" { #define LIGHTING_MAX_LIGHTS 10 -typedef struct +struct LightDefinition { Vector3 direction; /* Global direction of the light */ Color color; /* Main color of the light */ @@ -19,7 +19,7 @@ typedef struct int filtered; /* Should the light be filtered (by atmosphere, water...) */ int masked; /* Should the light be masked (cast shadows..) */ double amplitude; /* Angle amplitude of the light source (for multi-sampling, pi / 2.0 for skydome) */ -} LightDefinition; +}; typedef struct { @@ -30,11 +30,11 @@ typedef struct LightDefinition _autolights[LIGHTING_MAX_LIGHTS]; } LightingDefinition; -typedef struct +struct LightStatus { int nblights; LightDefinition lights[LIGHTING_MAX_LIGHTS * 2]; -} LightStatus; +}; void lightingInit(); void lightingQuit(); diff --git a/lib_paysages/renderer.c b/lib_paysages/renderer.c index dba8b81..1a776df 100644 --- a/lib_paysages/renderer.c +++ b/lib_paysages/renderer.c @@ -54,19 +54,18 @@ static void _pushQuad(Renderer* renderer, Vertex* v1, Vertex* v2, Vertex* v3, Ve renderer->pushTriangle(renderer, v4, v1, v3); } -static Color _filterLight(Renderer* renderer, Color light_color, Vector3 at_location, Vector3 light_location, Vector3 direction_to_light) +static void _alterLight(Renderer* renderer, LightDefinition* light, Vector3 location) { - return light_color; } -static Color _maskLight(Renderer* renderer, Color light_color, Vector3 at_location, Vector3 light_location, Vector3 direction_to_light) +static void _getLightStatus(Renderer* renderer, LightStatus* status, Vector3 location) { - return light_color; + status->nblights = 0; } -static Color _applyLightingToSurface(Renderer* renderer, Vector3 location, Vector3 normal, SurfaceMaterial material) +static Color _applyLightStatus(Renderer* renderer, LightStatus* status, Vector3 location, Vector3 normal, SurfaceMaterial material) { - return material.base; + return lightingApplyStatusToSurface(renderer, status, location, normal, material); } static RayCastingResult _rayWalking(Renderer* renderer, Vector3 location, Vector3 direction, int terrain, int water, int sky, int clouds) @@ -128,9 +127,9 @@ Renderer rendererCreate() result.applyAtmosphere = _applyAtmosphere; result.applyClouds = _applyClouds; - result.filterLight = _filterLight; - result.maskLight = _maskLight; - result.applyLightingToSurface = _applyLightingToSurface; + result.alterLight = _alterLight; + result.getLightStatus = _getLightStatus; + result.applyLightStatus = _applyLightStatus; return result; } diff --git a/lib_paysages/renderer.h b/lib_paysages/renderer.h index c1fa463..5e91b97 100644 --- a/lib_paysages/renderer.h +++ b/lib_paysages/renderer.h @@ -39,9 +39,9 @@ struct Renderer Color (*applyClouds)(Renderer* renderer, Color base, Vector3 start, Vector3 end); /* Lighting related */ - Color (*filterLight)(Renderer* renderer, Color light_color, Vector3 at_location, Vector3 light_location, Vector3 direction_to_light); - Color (*maskLight)(Renderer* renderer, Color light_color, Vector3 at_location, Vector3 light_location, Vector3 direction_to_light); - Color (*applyLightingToSurface)(Renderer* renderer, Vector3 location, Vector3 normal, SurfaceMaterial material); + 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); /* Custom data */ void* customData[10]; diff --git a/lib_paysages/scenery.c b/lib_paysages/scenery.c index 1ae6107..37b7314 100644 --- a/lib_paysages/scenery.c +++ b/lib_paysages/scenery.c @@ -236,25 +236,34 @@ void sceneryRenderFirstPass(Renderer* renderer) /******* Standard renderer *********/ -static Color _filterLight(Renderer* renderer, Color light_color, Vector3 at_location, Vector3 light_location, Vector3 direction_to_light) +static void _alterLight(Renderer* renderer, LightDefinition* light, Vector3 location) { - // TODO atmosphere filter - light_color = waterLightFilter(&_water, renderer, light_color, at_location, light_location, direction_to_light); - - return light_color; + 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->color = terrainLightFilter(&_terrain, renderer, light->color, location, light_location, direction_to_light); + light->color = cloudsFilterLight(&_clouds, renderer, light->color, location, light_location, direction_to_light); + } } -static Color _maskLight(Renderer* renderer, Color light_color, Vector3 at_location, Vector3 light_location, Vector3 direction_to_light) +static void _getLightStatus(Renderer* renderer, LightStatus* status, Vector3 location) { - light_color = terrainLightFilter(&_terrain, renderer, light_color, at_location, light_location, direction_to_light); - light_color = cloudsFilterLight(&_clouds, renderer, light_color, at_location, light_location, direction_to_light); - - return light_color; + lightingGetStatus(&_lighting, renderer, location, status); } -static Color _applyLightingToSurface(Renderer* renderer, Vector3 location, Vector3 normal, SurfaceMaterial material) +static Color _applyLightStatus(Renderer* renderer, LightStatus* status, Vector3 location, Vector3 normal, SurfaceMaterial material) { - return lightingApplyToSurface(&_lighting, renderer, location, normal, 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) @@ -333,9 +342,9 @@ Renderer sceneryCreateStandardRenderer() cameraCopyDefinition(&_camera, &result.render_camera); result.camera_location = _camera.location; - result.filterLight = _filterLight; - result.maskLight = _maskLight; - result.applyLightingToSurface = _applyLightingToSurface; + result.alterLight = _alterLight; + result.getLightStatus = _getLightStatus; + result.applyLightStatus = _applyLightStatus; result.rayWalking = _rayWalking; result.getTerrainHeight = _getTerrainHeight; result.getWaterHeightInfo = _getWaterHeightInfo; diff --git a/lib_paysages/shared/types.h b/lib_paysages/shared/types.h index db910f8..bcaae20 100644 --- a/lib_paysages/shared/types.h +++ b/lib_paysages/shared/types.h @@ -11,6 +11,9 @@ extern "C" { struct RenderFragment; struct Renderer; +typedef struct LightDefinition LightDefinition; +typedef struct LightStatus LightStatus; + typedef int(*f_RenderFragmentCallback)(struct RenderFragment*, struct Renderer* renderer, void* data); typedef struct diff --git a/lib_paysages/textures.c b/lib_paysages/textures.c index 8572a63..4a7522b 100644 --- a/lib_paysages/textures.c +++ b/lib_paysages/textures.c @@ -338,7 +338,10 @@ double texturesGetLayerCoverage(TextureLayerDefinition* definition, Renderer* re static inline Color _getLayerColor(Renderer* renderer, TextureResult result) { - return renderer->applyLightingToSurface(renderer, result.location, result.normal, result.definition->material); + LightStatus light; + + renderer->getLightStatus(renderer, &light, result.location); + return renderer->applyLightStatus(renderer, &light, result.location, result.normal, result.definition->material); } Color texturesGetLayerColor(TextureLayerDefinition* definition, Renderer* renderer, Vector3 location, double detail) diff --git a/lib_paysages/water.c b/lib_paysages/water.c index 006da1b..54e27ce 100644 --- a/lib_paysages/water.c +++ b/lib_paysages/water.c @@ -187,6 +187,7 @@ WaterResult waterGetColorDetail(WaterDefinition* definition, Renderer* renderer, RayCastingResult refracted; Vector3 normal; Color color; + LightStatus light; SurfaceMaterial material; double detail, depth; @@ -220,7 +221,8 @@ WaterResult waterGetColorDetail(WaterDefinition* definition, Renderer* renderer, material = definition->material; material.base = color; - color = renderer->applyLightingToSurface(renderer, location, normal, material); + renderer->getLightStatus(renderer, &light, location); + color = renderer->applyLightStatus(renderer, &light, location, normal, material); color = renderer->applyAtmosphere(renderer, location, color); color = renderer->applyClouds(renderer, color, renderer->camera_location, location);