paysages : Configurable and improve terrain shadows.

git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@351 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
Michaël Lemaire 2012-06-17 15:59:20 +00:00 committed by ThunderK
parent 203dd0ab12
commit 1fecbf414e
8 changed files with 27 additions and 9 deletions

View file

@ -13,6 +13,7 @@ Scenery :
* Added clouds hardness to light. * Added clouds hardness to light.
* Added sun halo control. * Added sun halo control.
* New cloud model with 2 noises : one for the global shape and one for edges. * 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 : Rendering :
* New texture model (perpendicular displacement and thickness). * New texture model (perpendicular displacement and thickness).

4
TODO
View file

@ -1,9 +1,5 @@
Technology Preview 2 : Technology Preview 2 :
- InputInt doesn't honor small_step. - 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. - Fix the fog impression when cloud layer overlaps with ground range.
- Remove color gradations (replace with automatic boolean and simple colors). - Remove color gradations (replace with automatic boolean and simple colors).
- Replace zone ranges with curves (with curve input and curve dialog). - Replace zone ranges with curves (with curve input and curve dialog).

View file

@ -151,6 +151,7 @@ FormTerrain::FormTerrain(QWidget *parent):
addInputNoise(tr("Noise"), _definition.height_noise); addInputNoise(tr("Noise"), _definition.height_noise);
addInputDouble(tr("Height"), &_definition.height_factor, 0.0, 20.0, 0.1, 1.0); 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("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(); revertConfig();
} }

View file

@ -678,6 +678,11 @@ Maintenir Ctrl : Plus rapide</translation>
<source>Scaling</source> <source>Scaling</source>
<translation>Echelle</translation> <translation>Echelle</translation>
</message> </message>
<message>
<location filename="../gui_qt/formterrain.cpp" line="154"/>
<source>Shadow smoothing</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>FormTextures</name> <name>FormTextures</name>

View file

@ -148,6 +148,7 @@ void autoGenRealisticLandscape(int seed)
noiseAddLevelsSimple(terrain.height_noise, 10, 1.0, 1.0); noiseAddLevelsSimple(terrain.height_noise, 10, 1.0, 1.0);
terrain.height_factor = 12.0 / noiseGetMaxValue(terrain.height_noise); terrain.height_factor = 12.0 / noiseGetMaxValue(terrain.height_noise);
terrain.scaling = 20.0; terrain.scaling = 20.0;
terrain.shadow_smoothing = 0.03;
scenerySetTerrain(&terrain); scenerySetTerrain(&terrain);
terrainDeleteDefinition(&terrain); terrainDeleteDefinition(&terrain);

View file

@ -251,11 +251,11 @@ static inline Color _getFinalPixel(RenderArea* area, int x, int y)
{ {
if (pixel_data->flags.edge) if (pixel_data->flags.edge)
{ {
col = COLOR_RED; col = COLOR_GREY;
} }
else else
{ {
col = COLOR_GREY; col = COLOR_WHITE;
} }
} }
else else
@ -602,8 +602,10 @@ void* _renderPostProcessChunk(void* data)
fragment->data.color.g = col.g; fragment->data.color.g = col.g;
fragment->data.color.b = col.b; fragment->data.color.b = col.b;
mutexAcquire(chunk->area->lock);
fragment->flags.dirty = 0; fragment->flags.dirty = 0;
_setDirtyPixel(chunk->area, x, y); _setDirtyPixel(chunk->area, x, y);
mutexRelease(chunk->area->lock);
} }
/* chunk->area->progress_pixels++; */ /* chunk->area->progress_pixels++; */
} }

View file

@ -27,6 +27,7 @@ void terrainSave(PackStream* stream, TerrainDefinition* definition)
noiseSaveGenerator(stream, definition->height_noise); noiseSaveGenerator(stream, definition->height_noise);
packWriteDouble(stream, &definition->height_factor); packWriteDouble(stream, &definition->height_factor);
packWriteDouble(stream, &definition->scaling); packWriteDouble(stream, &definition->scaling);
packWriteDouble(stream, &definition->shadow_smoothing);
packWriteInt(stream, &definition->height_modifiers_count); packWriteInt(stream, &definition->height_modifiers_count);
for (i = 0; i < definition->height_modifiers_count; i++) for (i = 0; i < definition->height_modifiers_count; i++)
@ -43,6 +44,7 @@ void terrainLoad(PackStream* stream, TerrainDefinition* definition)
noiseLoadGenerator(stream, definition->height_noise); noiseLoadGenerator(stream, definition->height_noise);
packReadDouble(stream, &definition->height_factor); packReadDouble(stream, &definition->height_factor);
packReadDouble(stream, &definition->scaling); packReadDouble(stream, &definition->scaling);
packReadDouble(stream, &definition->shadow_smoothing);
while (definition->height_modifiers_count > 0) while (definition->height_modifiers_count > 0)
{ {
@ -68,6 +70,7 @@ TerrainDefinition terrainCreateDefinition()
definition.height_factor = 0.0; definition.height_factor = 0.0;
definition.scaling = 1.0; definition.scaling = 1.0;
definition.height_modifiers_count = 0; definition.height_modifiers_count = 0;
definition.shadow_smoothing = 0.0;
terrainValidateDefinition(&definition); terrainValidateDefinition(&definition);
@ -92,6 +95,7 @@ void terrainCopyDefinition(TerrainDefinition* source, TerrainDefinition* destina
noiseCopy(source->height_noise, destination->height_noise); noiseCopy(source->height_noise, destination->height_noise);
destination->height_factor = source->height_factor; destination->height_factor = source->height_factor;
destination->scaling = source->scaling; destination->scaling = source->scaling;
destination->shadow_smoothing = source->shadow_smoothing;
for (i = 0; i < destination->height_modifiers_count; i++) 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_factor = (double)renderer->render_quality;
inc_base = 1.0; inc_base = definition->height_factor / definition->scaling;
inc_value = inc_base / inc_factor; inc_value = inc_base / inc_factor;
smoothing = 0.03 * inc_factor; smoothing = definition->shadow_smoothing;
light_factor = 1.0; light_factor = 1.0;
length = 0.0; length = 0.0;
@ -222,7 +226,14 @@ Color terrainLightFilter(TerrainDefinition* definition, Renderer* renderer, Colo
diff = location.y - height; diff = location.y - height;
if (diff < 0.0) 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) if (diff < inc_base / inc_factor)

View file

@ -20,6 +20,7 @@ typedef struct
double scaling; double scaling;
int height_modifiers_count; int height_modifiers_count;
HeightModifier* height_modifiers[TERRAIN_MAX_MODIFIERS]; HeightModifier* height_modifiers[TERRAIN_MAX_MODIFIERS];
double shadow_smoothing;
double _max_height; double _max_height;
} TerrainDefinition; } TerrainDefinition;