paysages: More water settings + lighted preview.

git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@247 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
Michaël Lemaire 2012-01-28 18:32:08 +00:00 committed by ThunderK
parent 318bb99ba4
commit 210b3d5e4c
6 changed files with 76 additions and 20 deletions

View file

@ -7,6 +7,7 @@
#include "../lib_paysages/terrain.h"
#include "../lib_paysages/water.h"
#include "../lib_paysages/lighting.h"
#include "../lib_paysages/scenery.h"
#include "../lib_paysages/renderer.h"
#include "../lib_paysages/shared/functions.h"
@ -36,7 +37,7 @@ protected:
}
else
{
return colorToQColor(_definition.main_color);
return colorToQColor(_definition.material.base);
}
}
void updateData()
@ -54,11 +55,27 @@ class PreviewWaterColor:public Preview
public:
PreviewWaterColor(QWidget* parent):Preview(parent)
{
LightDefinition light;
_water = waterCreateDefinition();
_lighting = lightingCreateDefinition();
light.color = COLOR_WHITE;
light.amplitude = 0.0;
light.direction.x = 0.0;
light.direction.y = -0.4794;
light.direction.z = 0.8776;
light.filtered = 0;
light.masked = 0;
light.reflection = 1.0;
lightingAddLight(&_lighting, light);
lightingValidateDefinition(&_lighting);
_renderer = rendererGetFake();
_renderer.rayWalking = _rayWalking;
// TODO Lighting
_renderer.applyLightingToSurface = _applyLightingToSurface;
_renderer.customData[0] = &_water;
_renderer.customData[1] = &_lighting;
}
protected:
QColor getColor(double x, double y)
@ -98,6 +115,8 @@ protected:
private:
Renderer _renderer;
WaterDefinition _water;
LightingDefinition _lighting;
static RayCastingResult _rayWalking(Renderer* renderer, Vector3 location, Vector3 direction, int terrain, int water, int sky, int clouds)
{
RayCastingResult result;
@ -129,6 +148,17 @@ private:
return result;
}
static Color _applyLightingToSurface(Renderer* renderer, Vector3 location, Vector3 normal, SurfaceMaterial material)
{
if (location.x >= 0.0)
{
return lightingApplyToSurface((LightingDefinition*)renderer->customData[1], renderer, location, normal, material);
}
else
{
return material.base;
}
}
};
/**************** Form ****************/
@ -140,14 +170,17 @@ FormWater::FormWater(QWidget *parent):
previewCoverage = new PreviewWaterCoverage(this);
previewColor = new PreviewWaterColor(this);
addPreview(previewCoverage, QString("Coverage preview"));
addPreview(previewColor, QString("Color preview"));
addPreview(previewColor, QString("Rendered preview (without/with lighting)"));
addInputDouble("Height", &_definition.height, -10.0, 10.0, 0.1, 1.0);
addInputColor("Surface color", &_definition.main_color);
addInputColor("Surface color", &_definition.material.base);
addInputDouble("Light reflection", &_definition.material.reflection, 0.0, 1.0, 0.01, 0.1);
addInputDouble("Shininess to light", &_definition.material.shininess, 0.0, 20.0, 0.1, 1.0);
addInputDouble("Transparency", &_definition.transparency, 0.0, 1.0, 0.001, 0.1);
addInputDouble("Reflection", &_definition.reflection, 0.0, 1.0, 0.001, 0.1);
addInputDouble("Transparency distance", &_definition.transparency_depth, 0.0, 20.0, 0.1, 1.0);
addInputColor("Depth color", &_definition.depth_color);
addInputDouble("Depth filtering", &_definition.transparency_depth, 0.0, 100.0, 0.5, 5.0);
addInputDouble("Light-through distance", &_definition.lighting_depth, 0.0, 20.0, 0.1, 1.0);
addInputNoise("Waves noise", _definition.waves_noise);
addInputDouble("Waves height", &_definition.waves_noise_height, 0.0, 0.1, 0.001, 0.01);
addInputDouble("Waves scaling", &_definition.waves_noise_scale, 0.01, 1.0, 0.01, 0.1);

View file

@ -115,14 +115,17 @@ void autoGenRealisticLandscape(int seed)
water.transparency = 0.5;
water.reflection = 0.3;
water.transparency_depth = 6.0;
water.main_color.r = 0.1;
water.main_color.g = 0.3;
water.main_color.b = 0.4;
water.main_color.a = 1.0;
water.material.base.r = 0.1;
water.material.base.g = 0.3;
water.material.base.b = 0.4;
water.material.base.a = 1.0;
water.material.reflection = 1.0;
water.material.shininess = 12.0;
water.depth_color.r = 0.0;
water.depth_color.g = 0.2;
water.depth_color.b = 0.3;
water.depth_color.a = 1.0;
water.lighting_depth = 3.0;
water.waves_noise_height = 0.015;
water.waves_noise_scale = 0.2;
noiseGenerateBaseNoise(water.waves_noise, 262144);

View file

@ -79,6 +79,8 @@ void toolsSaveDouble(FILE* f, double value);
double toolsLoadDouble(FILE* f);
void toolsSaveInt(FILE* f, int value);
int toolsLoadInt(FILE* f);
void materialSave(FILE* f, SurfaceMaterial* material);
void materialLoad(FILE* f, SurfaceMaterial* material);
/* zone.c */
Zone* zoneCreate();

View file

@ -79,3 +79,16 @@ int toolsLoadInt(FILE* f)
return value;
}
void materialSave(FILE* f, SurfaceMaterial* material)
{
colorSave(material->base, f);
toolsSaveDouble(f, material->reflection);
toolsSaveDouble(f, material->shininess);
}
void materialLoad(FILE* f, SurfaceMaterial* material)
{
material->base = colorLoad(f);
material->reflection = toolsLoadDouble(f);
material->shininess = toolsLoadDouble(f);
}

View file

@ -17,11 +17,12 @@ void waterInit()
void waterSave(FILE* f, WaterDefinition* definition)
{
toolsSaveDouble(f, definition->height);
colorSave(definition->main_color, f);
materialSave(f, &definition->material);
colorSave(definition->depth_color, f);
toolsSaveDouble(f, definition->transparency_depth);
toolsSaveDouble(f, definition->transparency);
toolsSaveDouble(f, definition->reflection);
toolsSaveDouble(f, definition->lighting_depth);
noiseSave(definition->waves_noise, f);
toolsSaveDouble(f, definition->waves_noise_height);
toolsSaveDouble(f, definition->waves_noise_scale);
@ -30,11 +31,12 @@ void waterSave(FILE* f, WaterDefinition* definition)
void waterLoad(FILE* f, WaterDefinition* definition)
{
definition->height = toolsLoadDouble(f);
definition->main_color = colorLoad(f);
materialLoad(f, &definition->material);
definition->depth_color = colorLoad(f);
definition->transparency_depth = toolsLoadDouble(f);
definition->transparency = toolsLoadDouble(f);
definition->reflection = toolsLoadDouble(f);
definition->lighting_depth = toolsLoadDouble(f);
noiseLoad(definition->waves_noise, f);
definition->waves_noise_height = toolsLoadDouble(f);
definition->waves_noise_scale = toolsLoadDouble(f);
@ -46,12 +48,15 @@ WaterDefinition waterCreateDefinition()
{
WaterDefinition result;
result.main_color = COLOR_BLACK;
result.material.base = COLOR_BLACK;
result.material.reflection = 0.0;
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;
@ -137,7 +142,7 @@ Color waterLightFilter(WaterDefinition* definition, Renderer* renderer, Color li
{
if (direction_to_light.y > 0.00001)
{
factor = (definition->height - location.y) / (direction_to_light.y * 3.0); // TODO Configurable
factor = (definition->height - location.y) / (direction_to_light.y * definition->lighting_depth);
if (factor > 1.0)
{
factor = 1.0;
@ -193,18 +198,17 @@ WaterResult waterGetColorDetail(WaterDefinition* definition, Renderer* renderer,
result.refracted.a = 1.0;
}
color.r = definition->main_color.r * (1.0 - definition->transparency) + result.reflected.r * definition->reflection + result.refracted.r * definition->transparency;
color.g = definition->main_color.g * (1.0 - definition->transparency) + result.reflected.g * definition->reflection + result.refracted.g * definition->transparency;
color.b = definition->main_color.b * (1.0 - definition->transparency) + result.reflected.b * definition->reflection + result.refracted.b * definition->transparency;
color.r = definition->material.base.r * (1.0 - definition->transparency) + result.reflected.r * definition->reflection + result.refracted.r * definition->transparency;
color.g = definition->material.base.g * (1.0 - definition->transparency) + result.reflected.g * definition->reflection + result.refracted.g * definition->transparency;
color.b = definition->material.base.b * (1.0 - definition->transparency) + result.reflected.b * definition->reflection + result.refracted.b * definition->transparency;
color.a = 1.0;
material = definition->material;
material.base = color;
material.reflection = 1.0;
material.shininess = 12.0;
color = renderer->applyLightingToSurface(renderer, location, normal, material);
color = renderer->applyAtmosphere(renderer, location, color);
result.base = definition->main_color;
result.base = definition->material.base;
result.final = color;
return result;

View file

@ -16,9 +16,10 @@ typedef struct
double height;
double transparency;
double reflection;
Color main_color;
SurfaceMaterial material;
Color depth_color;
double transparency_depth;
double lighting_depth;
NoiseGenerator* waves_noise;
double waves_noise_height;
double waves_noise_scale;