From 982af74c2d3c7cafc75612bd6d4a8c7354277eb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Tue, 8 Sep 2015 01:00:34 +0200 Subject: [PATCH] Added /water/reflection property --- graphics/icons.svg | 39 ++++++++++++++---- src/definition/WaterDefinition.cpp | 11 +++-- src/definition/WaterDefinition.h | 6 ++- .../modeler/quickapp/WaterModeler.cpp | 3 ++ src/interface/modeler/quickapp/WaterModeler.h | 1 + .../modeler/quickapp/qml/WaterSection.qml | 22 ++++++++++ src/interface/modeler/quickapp/qml/app.qrc | 1 + .../qml/images/icon_water_reflection.png | Bin 0 -> 646 bytes src/render/opengl/OpenGLRenderer.cpp | 2 +- src/render/opengl/OpenGLWater.cpp | 8 ++-- src/render/software/WaterRenderer.cpp | 10 +++-- 11 files changed, 79 insertions(+), 24 deletions(-) create mode 100644 src/interface/modeler/quickapp/qml/images/icon_water_reflection.png diff --git a/graphics/icons.svg b/graphics/icons.svg index ab65164..bec6ff5 100644 --- a/graphics/icons.svg +++ b/graphics/icons.svg @@ -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"> @@ -99,6 +101,13 @@ sodipodi:nodetypes="ccccccccccc" /> + @@ -191,6 +200,18 @@ d="m 440,292.36218 65,95 70,-95" id="path4025" inkscape:connector-curvature="0" /> + + diff --git a/src/definition/WaterDefinition.cpp b/src/definition/WaterDefinition.cpp index e238755..e6bd72a 100644 --- a/src/definition/WaterDefinition.cpp +++ b/src/definition/WaterDefinition.cpp @@ -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; diff --git a/src/definition/WaterDefinition.h b/src/definition/WaterDefinition.h index 5564c0a..c55f999 100644 --- a/src/definition/WaterDefinition.h +++ b/src/definition/WaterDefinition.h @@ -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; }; } diff --git a/src/interface/modeler/quickapp/WaterModeler.cpp b/src/interface/modeler/quickapp/WaterModeler.cpp index 4ee6884..4f4fe73 100644 --- a/src/interface/modeler/quickapp/WaterModeler.cpp +++ b/src/interface/modeler/quickapp/WaterModeler.cpp @@ -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) diff --git a/src/interface/modeler/quickapp/WaterModeler.h b/src/interface/modeler/quickapp/WaterModeler.h index d2840d5..a50a9a1 100644 --- a/src/interface/modeler/quickapp/WaterModeler.h +++ b/src/interface/modeler/quickapp/WaterModeler.h @@ -21,6 +21,7 @@ public slots: private: MainModelerWindow *ui; FloatPropertyBind *prop_water_height; + FloatPropertyBind *prop_water_reflexion; }; } diff --git a/src/interface/modeler/quickapp/qml/WaterSection.qml b/src/interface/modeler/quickapp/qml/WaterSection.qml index f549c8c..d77d6ce 100644 --- a/src/interface/modeler/quickapp/qml/WaterSection.qml +++ b/src/interface/modeler/quickapp/qml/WaterSection.qml @@ -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 + } } ] } diff --git a/src/interface/modeler/quickapp/qml/app.qrc b/src/interface/modeler/quickapp/qml/app.qrc index b33947d..73d2d65 100644 --- a/src/interface/modeler/quickapp/qml/app.qrc +++ b/src/interface/modeler/quickapp/qml/app.qrc @@ -43,5 +43,6 @@ BaseSection.qml AtmosphereSection.qml PanelSimpleFloat.qml + images/icon_water_reflection.png diff --git a/src/interface/modeler/quickapp/qml/images/icon_water_reflection.png b/src/interface/modeler/quickapp/qml/images/icon_water_reflection.png new file mode 100644 index 0000000000000000000000000000000000000000..5939053c7b3a89dbffe95454c74eb0cdc957f950 GIT binary patch literal 646 zcmV;10(t$3P)c zl&?sVl7*UPHa9y~6c(7Zg^h)cW<#+WJ1GlaQOZKHu+dmyA^F;9Qp!RhvJzo2F}`NT z<|t`C?tMSTo!9fPx7%Cy+~>UibKd7U=X42zAP9mW2!bF8g8z=%EW~JH5hmJf*M&ED zKG!8bNe`dpI$w6@x@JMZw;XMMRzW~V69Pg&2nYcoAOwVf5D)@7l<~3y%xmF0ORz5E z&haxA=IGx_^rAas`w={wZYMg^L)CB&YcZOk13$18i!(mJOFV9IpeF14M)crQ))APG z`#DAc9_82$pUOGIk6Jkp-2|kkEL;q+7oGC!!b?nPxcmP9qJI5>C zKoU@IrwVjq4|Y_b)W60Dtih{RXTbVYKHgPiy)%TJ?Ysg9aHXK&wGI$)2YXu;uoT;H zx1ivo_>M1aUSnw;Q3Nm2Z*FfT2b{o#)F3y_W^(}=>1ul&GCVw7)GQdpN!*xDz=|~b zs|uWc6CIKVZl}*4Je}$l=*QU(>U7Z@$FAvez;0Zu@b32}Hcus>FD0J$6&CO@CDz`_ z1e{KzKUQG@-BnBCqhTl9^p_8 z%kTiVG9En4bRg1?glGetError()) != GL_NO_ERROR) { Logs::warning() << "[OpenGL] ERROR : " << error_code << std::endl; } diff --git a/src/render/opengl/OpenGLWater.cpp b/src/render/opengl/OpenGLWater.cpp index 5406e1e..7d057d4 100644 --- a/src/render/opengl/OpenGLWater.cpp +++ b/src/render/opengl/OpenGLWater.cpp @@ -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) diff --git a/src/render/software/WaterRenderer.cpp b/src/render/software/WaterRenderer.cpp index 75ca18c..a1a0a11 100644 --- a/src/render/software/WaterRenderer.cpp +++ b/src/render/software/WaterRenderer.cpp @@ -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);