From 1fecbf414ec9a0ab0da6f031d1c835bef67f68f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Sun, 17 Jun 2012 15:59:20 +0000 Subject: [PATCH] paysages : Configurable and improve terrain shadows. git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@351 b1fd45b6-86a6-48da-8261-f70d1f35bdcc --- ChangeLog | 1 + TODO | 4 ---- gui_qt/formterrain.cpp | 1 + i18n/paysages_fr.ts | 5 +++++ lib_paysages/auto.c | 1 + lib_paysages/render.c | 6 ++++-- lib_paysages/terrain.c | 17 ++++++++++++++--- lib_paysages/terrain.h | 1 + 8 files changed, 27 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index fb993f9..f9f1d64 100644 --- a/ChangeLog +++ b/ChangeLog @@ -13,6 +13,7 @@ Scenery : * Added clouds hardness to light. * Added sun halo control. * New cloud model with 2 noises : one for the global shape and one for edges. + * Terrain shadows have been improved and are now configurable. Rendering : * New texture model (perpendicular displacement and thickness). diff --git a/TODO b/TODO index f76e5e0..1395bb5 100644 --- a/TODO +++ b/TODO @@ -1,9 +1,5 @@ Technology Preview 2 : - InputInt doesn't honor small_step. -- Improve shadow smoothness - => Configurable smoothness factor - => Smoothness depends on distance to hit - => Smoothness stays the same when quality changes, but has better resolution - Fix the fog impression when cloud layer overlaps with ground range. - Remove color gradations (replace with automatic boolean and simple colors). - Replace zone ranges with curves (with curve input and curve dialog). diff --git a/gui_qt/formterrain.cpp b/gui_qt/formterrain.cpp index 0abbc1f..d3cb653 100644 --- a/gui_qt/formterrain.cpp +++ b/gui_qt/formterrain.cpp @@ -151,6 +151,7 @@ FormTerrain::FormTerrain(QWidget *parent): addInputNoise(tr("Noise"), _definition.height_noise); addInputDouble(tr("Height"), &_definition.height_factor, 0.0, 20.0, 0.1, 1.0); addInputDouble(tr("Scaling"), &_definition.scaling, 1.0, 20.0, 0.1, 1.0); + addInputDouble(tr("Shadow smoothing"), &_definition.shadow_smoothing, 0.0, 0.3, 0.003, 0.03); revertConfig(); } diff --git a/i18n/paysages_fr.ts b/i18n/paysages_fr.ts index d0544d1..7d3c0bf 100644 --- a/i18n/paysages_fr.ts +++ b/i18n/paysages_fr.ts @@ -678,6 +678,11 @@ Maintenir Ctrl : Plus rapide Scaling Echelle + + + Shadow smoothing + + FormTextures diff --git a/lib_paysages/auto.c b/lib_paysages/auto.c index 7e07973..4bffe7f 100644 --- a/lib_paysages/auto.c +++ b/lib_paysages/auto.c @@ -148,6 +148,7 @@ void autoGenRealisticLandscape(int seed) noiseAddLevelsSimple(terrain.height_noise, 10, 1.0, 1.0); terrain.height_factor = 12.0 / noiseGetMaxValue(terrain.height_noise); terrain.scaling = 20.0; + terrain.shadow_smoothing = 0.03; scenerySetTerrain(&terrain); terrainDeleteDefinition(&terrain); diff --git a/lib_paysages/render.c b/lib_paysages/render.c index bba8fa9..53fd2ae 100644 --- a/lib_paysages/render.c +++ b/lib_paysages/render.c @@ -251,11 +251,11 @@ static inline Color _getFinalPixel(RenderArea* area, int x, int y) { if (pixel_data->flags.edge) { - col = COLOR_RED; + col = COLOR_GREY; } else { - col = COLOR_GREY; + col = COLOR_WHITE; } } else @@ -602,8 +602,10 @@ void* _renderPostProcessChunk(void* data) fragment->data.color.g = col.g; fragment->data.color.b = col.b; + mutexAcquire(chunk->area->lock); fragment->flags.dirty = 0; _setDirtyPixel(chunk->area, x, y); + mutexRelease(chunk->area->lock); } /* chunk->area->progress_pixels++; */ } diff --git a/lib_paysages/terrain.c b/lib_paysages/terrain.c index b184efc..6184d82 100644 --- a/lib_paysages/terrain.c +++ b/lib_paysages/terrain.c @@ -27,6 +27,7 @@ void terrainSave(PackStream* stream, TerrainDefinition* definition) noiseSaveGenerator(stream, definition->height_noise); packWriteDouble(stream, &definition->height_factor); packWriteDouble(stream, &definition->scaling); + packWriteDouble(stream, &definition->shadow_smoothing); packWriteInt(stream, &definition->height_modifiers_count); for (i = 0; i < definition->height_modifiers_count; i++) @@ -43,6 +44,7 @@ void terrainLoad(PackStream* stream, TerrainDefinition* definition) noiseLoadGenerator(stream, definition->height_noise); packReadDouble(stream, &definition->height_factor); packReadDouble(stream, &definition->scaling); + packReadDouble(stream, &definition->shadow_smoothing); while (definition->height_modifiers_count > 0) { @@ -68,6 +70,7 @@ TerrainDefinition terrainCreateDefinition() definition.height_factor = 0.0; definition.scaling = 1.0; definition.height_modifiers_count = 0; + definition.shadow_smoothing = 0.0; terrainValidateDefinition(&definition); @@ -92,6 +95,7 @@ void terrainCopyDefinition(TerrainDefinition* source, TerrainDefinition* destina noiseCopy(source->height_noise, destination->height_noise); destination->height_factor = source->height_factor; destination->scaling = source->scaling; + destination->shadow_smoothing = source->shadow_smoothing; for (i = 0; i < destination->height_modifiers_count; i++) { @@ -206,9 +210,9 @@ Color terrainLightFilter(TerrainDefinition* definition, Renderer* renderer, Colo } inc_factor = (double)renderer->render_quality; - inc_base = 1.0; + inc_base = definition->height_factor / definition->scaling; inc_value = inc_base / inc_factor; - smoothing = 0.03 * inc_factor; + smoothing = definition->shadow_smoothing; light_factor = 1.0; length = 0.0; @@ -222,7 +226,14 @@ Color terrainLightFilter(TerrainDefinition* definition, Renderer* renderer, Colo diff = location.y - height; if (diff < 0.0) { - light_factor += diff / smoothing; + if (length * smoothing > 0.000001) + { + light_factor += diff * v3Norm(inc_vector) / (length * smoothing); + } + else + { + light_factor = 0.0; + } } if (diff < inc_base / inc_factor) diff --git a/lib_paysages/terrain.h b/lib_paysages/terrain.h index 04cca63..9ef08e6 100644 --- a/lib_paysages/terrain.h +++ b/lib_paysages/terrain.h @@ -20,6 +20,7 @@ typedef struct double scaling; int height_modifiers_count; HeightModifier* height_modifiers[TERRAIN_MAX_MODIFIERS]; + double shadow_smoothing; double _max_height; } TerrainDefinition;