1
0
Fork 0

Added /water/reflection property

This commit is contained in:
Michaël Lemaire 2015-09-08 01:00:34 +02:00
parent 3cb287dfeb
commit 982af74c2d
11 changed files with 79 additions and 24 deletions

View File

@ -14,7 +14,7 @@
height="297mm"
id="svg2"
version="1.1"
inkscape:version="0.48.4 r9939"
inkscape:version="0.91 r13725"
sodipodi:docname="icons.svg"
inkscape:export-filename="/home/michael/workspace/paysages3d/graphics/icons.png"
inkscape:export-xdpi="154.89854"
@ -28,19 +28,21 @@
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="1.979899"
inkscape:cx="468.77289"
inkscape:cy="831.55692"
inkscape:zoom="2.8"
inkscape:cx="274.84974"
inkscape:cy="462.35469"
inkscape:document-units="px"
inkscape:current-layer="g3986"
showgrid="true"
inkscape:window-width="1920"
inkscape:window-height="1030"
inkscape:window-height="1037"
inkscape:window-x="1440"
inkscape:window-y="25"
inkscape:window-maximized="1"
inkscape:window-y="20"
inkscape:window-maximized="0"
showguides="true"
inkscape:snap-object-midpoints="false">
inkscape:snap-object-midpoints="false"
inkscape:object-nodes="false"
inkscape:snap-grids="true">
<inkscape:grid
type="xygrid"
id="grid3004" />
@ -99,6 +101,13 @@
sodipodi:nodetypes="ccccccccccc" />
<g
id="g3986">
<rect
style="opacity:1;fill:#656565;fill-opacity:1;stroke:none;stroke-width:3.4000001;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
id="rect4171-0"
width="50"
height="30.000034"
x="180"
y="567.36218" />
<g
id="g3969">
<path
@ -109,7 +118,7 @@
sodipodi:cy="187.36218"
sodipodi:rx="35"
sodipodi:ry="35"
d="m 105,187.36218 c 0,19.32997 -15.670034,35 -35,35 -19.329966,0 -35,-15.67003 -35,-35 0,-19.32996 15.670034,-35 35,-35 19.329966,0 35,15.67004 35,35 z"
d="m 105,187.36218 a 35,35 0 0 1 -35,35 35,35 0 0 1 -35,-35 35,35 0 0 1 35,-35 35,35 0 0 1 35,35 z"
transform="translate(5.3571428,58.571429)" />
<g
id="g3961">
@ -191,6 +200,18 @@
d="m 440,292.36218 65,95 70,-95"
id="path4025"
inkscape:connector-curvature="0" />
<path
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2.80700541;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="m 104.66045,597.62168 200.67929,0 -22.85304,-57.73976 -152.74134,0 z"
id="path4169"
inkscape:connector-curvature="0" />
<rect
style="opacity:1;fill:#000000;fill-opacity:1;stroke:none;stroke-width:3.4000001;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
id="rect4171"
width="50"
height="75"
x="180"
y="492.36221" />
</g>
</g>
</svg>

Before

Width:  |  Height:  |  Size: 9.9 KiB

After

Width:  |  Height:  |  Size: 11 KiB

View File

@ -4,10 +4,13 @@
#include "NoiseState.h"
#include "Color.h"
#include "SurfaceMaterial.h"
#include "FloatNode.h"
WaterDefinition::WaterDefinition(DefinitionNode* parent):
DefinitionNode(parent, "water", "water")
{
reflection = new FloatNode(this, "reflection");
material = new SurfaceMaterial;
depth_color = new Color;
foam_material = new SurfaceMaterial;
@ -15,7 +18,6 @@ WaterDefinition::WaterDefinition(DefinitionNode* parent):
transparency_depth = 0.0;
transparency = 0.0;
reflection = 0.0;
lighting_depth = 0.0;
scaling = 1.0;
waves_height = 0.0;
@ -40,7 +42,6 @@ void WaterDefinition::save(PackStream* stream) const
depth_color->save(stream);
stream->write(&transparency_depth);
stream->write(&transparency);
stream->write(&reflection);
stream->write(&lighting_depth);
stream->write(&scaling);
@ -62,7 +63,6 @@ void WaterDefinition::load(PackStream* stream)
depth_color->load(stream);
stream->read(&transparency_depth);
stream->read(&transparency);
stream->read(&reflection);
stream->read(&lighting_depth);
stream->read(&scaling);
@ -87,7 +87,6 @@ void WaterDefinition::copy(DefinitionNode* _destination) const
*destination->depth_color = *depth_color;
destination->transparency_depth = transparency_depth;
destination->transparency = transparency;
destination->reflection = reflection;
destination->lighting_depth = lighting_depth;
destination->scaling = scaling;
destination->waves_height = waves_height;
@ -113,7 +112,7 @@ void WaterDefinition::applyPreset(WaterPreset preset)
if (preset == WATER_PRESET_LAKE)
{
transparency = 0.5;
reflection = 0.2;
reflection->setValue(0.2);
transparency_depth = 4.0;
material->setColor(0.08, 0.15, 0.2, 1.0);
depth_color->r = 0.0;
@ -129,7 +128,7 @@ void WaterDefinition::applyPreset(WaterPreset preset)
else if (preset == WATER_PRESET_SEA)
{
transparency = 0.3;
reflection = 0.07;
reflection->setValue(0.07);
transparency_depth = 3.0;
material->setColor(0.05, 0.18, 0.2, 1.0);
depth_color->r = 0.0;

View File

@ -20,6 +20,8 @@ public:
virtual void copy(DefinitionNode* destination) const override;
virtual void validate() override;
inline FloatNode *propReflection() const {return reflection;}
public:
typedef enum
{
@ -30,7 +32,6 @@ public:
public:
double transparency;
double reflection;
SurfaceMaterial* material;
Color* depth_color;
double transparency_depth;
@ -45,6 +46,9 @@ public:
SurfaceMaterial* foam_material;
NoiseState* noise_state;
private:
FloatNode *reflection;
};
}

View File

@ -3,6 +3,7 @@
#include "MainModelerWindow.h"
#include "Scenery.h"
#include "TerrainDefinition.h"
#include "WaterDefinition.h"
#include "FloatPropertyBind.h"
#include "OpenGLRenderer.h"
#include "OpenGLWater.h"
@ -17,11 +18,13 @@ WaterModeler::WaterModeler(MainModelerWindow *ui):
}
prop_water_height = new FloatPropertyBind(ui, "water_height", "value", ui->getScenery()->getTerrain()->propWaterHeight());
prop_water_reflexion = new FloatPropertyBind(ui, "water_reflection", "value", ui->getScenery()->getWater()->propReflection());
}
WaterModeler::~WaterModeler()
{
delete prop_water_height;
delete prop_water_reflexion;
}
void WaterModeler::enableRendering(bool enable)

View File

@ -21,6 +21,7 @@ public slots:
private:
MainModelerWindow *ui;
FloatPropertyBind *prop_water_height;
FloatPropertyBind *prop_water_reflexion;
};
}

View File

@ -13,6 +13,13 @@ BaseSection {
picture: "images/icon_water_level.png"
hovertext: qsTr("Change the water altitude")
}
ToolbarButton {
id: tool_water_reflection
checked: false
picture: "images/icon_water_reflection.png"
hovertext: qsTr("Reflection of the water surface")
}
}
PanelSimpleFloat {
@ -24,6 +31,13 @@ BaseSection {
objectName: "water_height"
}
PanelSimpleFloat {
id: panel_water_reflection
enabled: false
anchors.left: toolbar.right
objectName: "water_reflection"
}
states: [
State {
name: "WaterHeight"
@ -32,6 +46,14 @@ BaseSection {
target: panel_water_level
enabled: true
}
},
State {
name: "WaterReflection"
when: tool_water_reflection.checked
PropertyChanges {
target: panel_water_reflection
enabled: true
}
}
]
}

View File

@ -43,5 +43,6 @@
<file>BaseSection.qml</file>
<file>AtmosphereSection.qml</file>
<file>PanelSimpleFloat.qml</file>
<file>images/icon_water_reflection.png</file>
</qresource>
</RCC>

Binary file not shown.

After

Width:  |  Height:  |  Size: 646 B

View File

@ -156,7 +156,7 @@ void OpenGLRenderer::paint()
}
int error_code;
while ((error_code = glGetError()) != GL_NO_ERROR)
while ((error_code = functions->glGetError()) != GL_NO_ERROR)
{
Logs::warning() << "[OpenGL] ERROR : " << error_code << std::endl;
}

View File

@ -41,6 +41,7 @@ void OpenGLWater::initialize()
// Watch for definition changes
renderer->getScenery()->getTerrain()->propWaterHeight()->addWatcher(this, true);
renderer->getScenery()->getWater()->propReflection()->addWatcher(this, true);
}
void OpenGLWater::update()
@ -48,9 +49,6 @@ void OpenGLWater::update()
Color water_color = *renderer->getScenery()->getWater()->material->base;
renderer->getSharedState()->set("waterColor", water_color);
double water_reflection = renderer->getScenery()->getWater()->reflection;
renderer->getSharedState()->set("waterReflection", water_reflection);
renderer->getSharedState()->set("simplexSampler", NoiseFunctionSimplex::getNormalTexture(), true, true);
}
@ -75,6 +73,10 @@ void OpenGLWater::nodeChanged(const DefinitionNode *node, const DefinitionDiff *
{
renderer->getSharedState()->set("waterOffset", renderer->getScenery()->getTerrain()->getWaterOffset());
}
else if (node->getPath() == "/water/reflection")
{
renderer->getSharedState()->set("waterReflection", renderer->getScenery()->getWater()->propReflection()->getValue());
}
}
void OpenGLWater::setEnabled(bool enabled)

View File

@ -8,6 +8,7 @@
#include "Scenery.h"
#include "SurfaceMaterial.h"
#include "NoiseFunctionSimplex.h"
#include "FloatNode.h"
WaterRenderer::WaterRenderer(SoftwareRenderer* parent):
parent(parent)
@ -172,6 +173,7 @@ WaterRenderer::WaterResult WaterRenderer::getResult(double x, double z)
Vector3 location, normal, look_direction;
Color color, foam;
double detail, depth;
double reflection = definition->propReflection()->getValue();
location.x = x;
location.y = _getHeight(noise, x, z);
@ -188,7 +190,7 @@ WaterRenderer::WaterResult WaterRenderer::getResult(double x, double z)
look_direction = location.sub(parent->getCameraLocation(location)).normalize();
/* Reflection */
if (definition->reflection == 0.0)
if (reflection == 0.0)
{
result.reflected = COLOR_BLACK;
}
@ -225,9 +227,9 @@ WaterRenderer::WaterResult WaterRenderer::getResult(double x, double z)
/* Lighting from environment */
color = parent->applyLightingToSurface(location, normal, *definition->material);
color.r += result.reflected.r * definition->reflection + result.refracted.r * definition->transparency;
color.g += result.reflected.g * definition->reflection + result.refracted.g * definition->transparency;
color.b += result.reflected.b * definition->reflection + result.refracted.b * definition->transparency;
color.r += result.reflected.r * reflection + result.refracted.r * definition->transparency;
color.g += result.reflected.g * reflection + result.refracted.g * definition->transparency;
color.b += result.reflected.b * reflection + result.refracted.b * definition->transparency;
/* Merge with foam */
foam = _getFoamMask(parent, definition, noise, location, normal, detail);