paysages : Simplified water waves settings.

git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@463 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
Michaël Lemaire 2012-11-11 10:52:03 +00:00 committed by ThunderK
parent 1f58b866e6
commit 55f606bd85
6 changed files with 101 additions and 59 deletions

View file

@ -220,9 +220,10 @@ FormWater::FormWater(QWidget *parent):
addInputDouble(tr("Reflection"), &_definition.reflection, 0.0, 1.0, 0.001, 0.1); addInputDouble(tr("Reflection"), &_definition.reflection, 0.0, 1.0, 0.001, 0.1);
addInputDouble(tr("Transparency distance"), &_definition.transparency_depth, 0.0, 20.0, 0.1, 1.0); addInputDouble(tr("Transparency distance"), &_definition.transparency_depth, 0.0, 20.0, 0.1, 1.0);
addInputDouble(tr("Light-through distance"), &_definition.lighting_depth, 0.0, 20.0, 0.1, 1.0); addInputDouble(tr("Light-through distance"), &_definition.lighting_depth, 0.0, 20.0, 0.1, 1.0);
addInputNoise(tr("Waves noise"), _definition.waves_noise); addInputDouble(tr("Waves scaling"), &_definition.scaling, 0.02, 2.0, 0.02, 0.2);
addInputDouble(tr("Waves height"), &_definition.waves_noise_height, 0.0, 0.1, 0.001, 0.01); addInputDouble(tr("Waves height"), &_definition.waves_height, 0.0, 2.0, 0.02, 0.2);
addInputDouble(tr("Waves scaling"), &_definition.waves_noise_scale, 0.03, 3.0, 0.03, 0.3); addInputDouble(tr("Waves detail"), &_definition.detail_height, 0.0, 0.3, 0.003, 0.03);
addInputDouble(tr("Waves turbulence"), &_definition.turbulence, 0.0, 0.5, 0.005, 0.05);
revertConfig(); revertConfig();
} }
@ -238,3 +239,9 @@ void FormWater::applyConfig()
scenerySetWater(&_definition); scenerySetWater(&_definition);
BaseForm::applyConfig(); BaseForm::applyConfig();
} }
void FormWater::configChangeEvent()
{
waterValidateDefinition(&_definition);
BaseForm::configChangeEvent();
}

View file

@ -16,6 +16,9 @@ public slots:
virtual void revertConfig(); virtual void revertConfig();
virtual void applyConfig(); virtual void applyConfig();
protected slots:
virtual void configChangeEvent();
private: private:
BasePreview* previewCoverage; BasePreview* previewCoverage;
BasePreview* previewColor; BasePreview* previewColor;

View file

@ -80,27 +80,7 @@ void autoGenRealisticLandscape(int seed)
/* Water */ /* Water */
water = waterCreateDefinition(); water = waterCreateDefinition();
water.height = -4.0; waterAutoPreset(&water, WATER_PRESET_STD);
water.transparency = 0.5;
water.reflection = 0.4;
water.transparency_depth = 6.0;
water.material.base.r = 0.05;
water.material.base.g = 0.15;
water.material.base.b = 0.2;
water.material.base.a = 1.0;
water.material.reflection = 1.0;
water.material.shininess = 16.0;
water.depth_color.r = 0.0;
water.depth_color.g = 0.1;
water.depth_color.b = 0.1;
water.depth_color.a = 1.0;
water.lighting_depth = 3.0;
water.waves_noise_height = 0.005;
water.waves_noise_scale = 0.21;
noiseClearLevels(water.waves_noise);
noiseAddLevelsSimple(water.waves_noise, 2, 1.0, 1.0);
noiseAddLevelsSimple(water.waves_noise, 3, 0.15, 0.1);
noiseSetFunctionParams(water.waves_noise, NOISE_FUNCTION_SIMPLEX, -0.3);
scenerySetWater(&water); scenerySetWater(&water);
waterDeleteDefinition(&water); waterDeleteDefinition(&water);

View file

@ -24,7 +24,7 @@ static int _addRenderProgress(Renderer* renderer, double progress)
static double _getPrecision(Renderer* renderer, Vector3 location) static double _getPrecision(Renderer* renderer, Vector3 location)
{ {
return 0.001; return 0.0;
} }
static Vector3 _projectPoint(Renderer* renderer, Vector3 point) static Vector3 _projectPoint(Renderer* renderer, Vector3 point)

View file

@ -19,9 +19,13 @@ void waterSave(PackStream* stream, WaterDefinition* definition)
packWriteDouble(stream, &definition->transparency); packWriteDouble(stream, &definition->transparency);
packWriteDouble(stream, &definition->reflection); packWriteDouble(stream, &definition->reflection);
packWriteDouble(stream, &definition->lighting_depth); packWriteDouble(stream, &definition->lighting_depth);
noiseSaveGenerator(stream, definition->waves_noise);
packWriteDouble(stream, &definition->waves_noise_height); packWriteDouble(stream, &definition->scaling);
packWriteDouble(stream, &definition->waves_noise_scale); packWriteDouble(stream, &definition->waves_height);
packWriteDouble(stream, &definition->detail_height);
packWriteDouble(stream, &definition->turbulence);
noiseSaveGenerator(stream, definition->_waves_noise);
} }
void waterLoad(PackStream* stream, WaterDefinition* definition) void waterLoad(PackStream* stream, WaterDefinition* definition)
@ -33,9 +37,13 @@ void waterLoad(PackStream* stream, WaterDefinition* definition)
packReadDouble(stream, &definition->transparency); packReadDouble(stream, &definition->transparency);
packReadDouble(stream, &definition->reflection); packReadDouble(stream, &definition->reflection);
packReadDouble(stream, &definition->lighting_depth); packReadDouble(stream, &definition->lighting_depth);
noiseLoadGenerator(stream, definition->waves_noise);
packReadDouble(stream, &definition->waves_noise_height); packReadDouble(stream, &definition->scaling);
packReadDouble(stream, &definition->waves_noise_scale); packReadDouble(stream, &definition->waves_height);
packReadDouble(stream, &definition->detail_height);
packReadDouble(stream, &definition->turbulence);
noiseLoadGenerator(stream, definition->_waves_noise);
waterValidateDefinition(definition); waterValidateDefinition(definition);
} }
@ -44,44 +52,73 @@ WaterDefinition waterCreateDefinition()
{ {
WaterDefinition result; WaterDefinition result;
result.material.base = COLOR_BLACK; result.height = -4.0;
result.material.reflection = 0.0; result._waves_noise = noiseCreateGenerator();
result.material.shininess = 0.0;
result.depth_color = COLOR_BLACK;
result.height = -1000.0;
result.reflection = 0.0;
result.transparency = 0.0;
result.transparency_depth = 0.0;
result.lighting_depth = 0.0;
result.waves_noise = noiseCreateGenerator();
result.waves_noise_height = 0.02;
result.waves_noise_scale = 0.2;
return result; return result;
} }
void waterDeleteDefinition(WaterDefinition* definition) void waterDeleteDefinition(WaterDefinition* definition)
{ {
noiseDeleteGenerator(definition->waves_noise); noiseDeleteGenerator(definition->_waves_noise);
}
void waterAutoPreset(WaterDefinition* definition, WaterPreset preset)
{
if (preset == WATER_PRESET_STD)
{
definition->transparency = 0.5;
definition->reflection = 0.4;
definition->transparency_depth = 6.0;
definition->material.base.r = 0.05;
definition->material.base.g = 0.15;
definition->material.base.b = 0.2;
definition->material.base.a = 1.0;
definition->material.reflection = 1.0;
definition->material.shininess = 16.0;
definition->depth_color.r = 0.0;
definition->depth_color.g = 0.1;
definition->depth_color.b = 0.1;
definition->depth_color.a = 1.0;
definition->lighting_depth = 3.0;
definition->scaling = 1.0;
definition->waves_height = 1.0;
definition->detail_height = 0.05;
definition->turbulence = 0.3;
}
waterValidateDefinition(definition);
} }
void waterCopyDefinition(WaterDefinition* source, WaterDefinition* destination) void waterCopyDefinition(WaterDefinition* source, WaterDefinition* destination)
{ {
NoiseGenerator* noise; NoiseGenerator* noise;
noise = destination->waves_noise; noise = destination->_waves_noise;
*destination = *source; *destination = *source;
destination->waves_noise = noise; destination->_waves_noise = noise;
noiseCopy(source->waves_noise, destination->waves_noise); noiseCopy(source->_waves_noise, destination->_waves_noise);
} }
void waterValidateDefinition(WaterDefinition* definition) void waterValidateDefinition(WaterDefinition* definition)
{ {
double scaling = definition->scaling * 0.3;
noiseClearLevels(definition->_waves_noise);
if (definition->waves_height > 0.0)
{
noiseAddLevelsSimple(definition->_waves_noise, 2, scaling, definition->waves_height * scaling * 0.03);
}
if (definition->detail_height > 0.0)
{
noiseAddLevelsSimple(definition->_waves_noise, 3, scaling * 0.1, definition->detail_height * scaling * 0.03);
}
noiseSetFunctionParams(definition->_waves_noise, NOISE_FUNCTION_SIMPLEX, -definition->turbulence);
noiseValidate(definition->_waves_noise);
} }
static inline double _getHeight(WaterDefinition* definition, double x, double z, double detail) static inline double _getHeight(WaterDefinition* definition, double x, double z)
{ {
return definition->height + noiseGet2DDetail(definition->waves_noise, x / definition->waves_noise_scale, z / definition->waves_noise_scale, detail) * definition->waves_noise_height; return definition->height + noiseGet2DTotal(definition->_waves_noise, x, z);
} }
static inline Vector3 _getNormal(WaterDefinition* definition, Vector3 base, double detail) static inline Vector3 _getNormal(WaterDefinition* definition, Vector3 base, double detail)
@ -89,16 +126,21 @@ static inline Vector3 _getNormal(WaterDefinition* definition, Vector3 base, doub
Vector3 back, right; Vector3 back, right;
double x, z; double x, z;
if (detail < 0.00001)
{
detail = 0.00001;
}
x = base.x; x = base.x;
z = base.z; z = base.z;
back.x = x; back.x = x;
back.y = _getHeight(definition, x, z + detail, detail); back.y = _getHeight(definition, x, z + detail);
back.z = z + detail; back.z = z + detail;
back = v3Sub(back, base); back = v3Sub(back, base);
right.x = x + detail; right.x = x + detail;
right.y = _getHeight(definition, x + detail, z, detail); right.y = _getHeight(definition, x + detail, z);
right.z = z; right.z = z;
right = v3Sub(right, base); right = v3Sub(right, base);
@ -135,8 +177,8 @@ HeightInfo waterGetHeightInfo(WaterDefinition* definition)
HeightInfo info; HeightInfo info;
info.base_height = definition->height; info.base_height = definition->height;
info.min_height = definition->height - noiseGetMaxValue(definition->waves_noise) * definition->waves_noise_height; info.min_height = definition->height - noiseGetMaxValue(definition->_waves_noise);
info.max_height = definition->height + noiseGetMaxValue(definition->waves_noise) * definition->waves_noise_height; info.max_height = definition->height + noiseGetMaxValue(definition->_waves_noise);
return info; return info;
} }
@ -185,7 +227,7 @@ WaterResult waterGetColorDetail(WaterDefinition* definition, Renderer* renderer,
detail = renderer->getPrecision(renderer, location); detail = renderer->getPrecision(renderer, location);
location.y = _getHeight(definition, location.x, location.z, detail); location.y = _getHeight(definition, location.x, location.z);
result.location = location; result.location = location;
normal = _getNormal(definition, location, detail); normal = _getNormal(definition, location, detail);
@ -239,7 +281,7 @@ static Vector3 _getFirstPassVertex(WaterDefinition* definition, double x, double
Vector3 result; Vector3 result;
result.x = x; result.x = x;
result.y = _getHeight(definition, x, z, 0.0); result.y = _getHeight(definition, x, z);
result.z = z; result.z = z;
return result; return result;

View file

@ -11,6 +11,11 @@
extern "C" { extern "C" {
#endif #endif
typedef enum
{
WATER_PRESET_STD
} WaterPreset;
typedef struct typedef struct
{ {
double height; double height;
@ -20,9 +25,13 @@ typedef struct
Color depth_color; Color depth_color;
double transparency_depth; double transparency_depth;
double lighting_depth; double lighting_depth;
NoiseGenerator* waves_noise;
double waves_noise_height; double scaling;
double waves_noise_scale; double turbulence;
double waves_height;
double detail_height;
NoiseGenerator* _waves_noise;
} WaterDefinition; } WaterDefinition;
typedef struct typedef struct
@ -39,6 +48,7 @@ void waterLoad(PackStream* stream, WaterDefinition* definition);
WaterDefinition waterCreateDefinition(); WaterDefinition waterCreateDefinition();
void waterDeleteDefinition(WaterDefinition* definition); void waterDeleteDefinition(WaterDefinition* definition);
void waterAutoPreset(WaterDefinition* definition, WaterPreset preset);
void waterCopyDefinition(WaterDefinition* source, WaterDefinition* destination); void waterCopyDefinition(WaterDefinition* source, WaterDefinition* destination);
void waterValidateDefinition(WaterDefinition* definition); void waterValidateDefinition(WaterDefinition* definition);