diff --git a/include/openspace/rendering/renderengine.h b/include/openspace/rendering/renderengine.h index 505d6b8ed9..2eeec180b5 100644 --- a/include/openspace/rendering/renderengine.h +++ b/include/openspace/rendering/renderengine.h @@ -73,6 +73,9 @@ public: void serialize(SyncBuffer* syncBuffer); void deserialize(SyncBuffer* syncBuffer); + + float globalOpacity(); + void setGlobalOpacity(float opacity); /** * Returns the Lua library that contains all Lua functions available to affect the @@ -104,6 +107,8 @@ private: void generateGlslConfig(); + float _globalOpactity; + bool _visualizeABuffer; ABufferVisualizer* _visualizer; }; diff --git a/shaders/postFX_fs.glsl b/shaders/postFX_fs.glsl new file mode 100644 index 0000000000..a9cf57c44b --- /dev/null +++ b/shaders/postFX_fs.glsl @@ -0,0 +1,36 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#version 430 + +in vec2 UV; +out vec4 Color; + +uniform sampler2D Tex; +uniform float Opacity; + +void main() +{ + Color = texture(Tex, UV) * Opacity; +} \ No newline at end of file diff --git a/shaders/postFX_vs.glsl b/shaders/postFX_vs.glsl new file mode 100644 index 0000000000..9c9cc2381f --- /dev/null +++ b/shaders/postFX_vs.glsl @@ -0,0 +1,36 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#version 430 + +layout (location = 0) in vec2 TexCoords; +layout (location = 1) in vec3 Position; + +out vec2 UV; + +void main() +{ + gl_Position = vec4(Position, 1.0); + UV = TexCoords; +} \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index e96516dbd2..eafb155f64 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -24,8 +24,9 @@ ****************************************************************************************/ #include - +#include #include +#include #include sgct::Engine* _sgctEngine; @@ -46,6 +47,12 @@ void mainDecodeFun(); void mainExternalControlCallback(const char * receivedChars, int size); void mainLogCallback(const char* msg); +//temporary post-FX functions, TODO make a more permanent solution to this @JK +void postFXPass(); +void setupPostFX(); +GLint _postFXTexLoc; +GLint _postFXOpacityLoc; + namespace { const std::string _loggerCat = "main"; } @@ -140,6 +147,9 @@ void mainInitFunc() std::cin.ignore(100); exit(EXIT_FAILURE); } + + //temporary post-FX solution, TODO add a more permanent solution @JK + setupPostFX(); } void mainPreSyncFunc() @@ -226,4 +236,22 @@ void mainLogCallback(const char* msg){ std::string message = msg; // Remove the trailing \n that is passed along LINFOC("SGCT", message.substr(0, std::max(message.size() - 1, 0))); +} + +void postFXPass(){ + glUniform1i(_postFXTexLoc, 0); + glUniform1f(_postFXOpacityLoc, OsEng.ref().renderEngine()->globalOpacity()); +} + +void setupPostFX(){ + sgct::PostFX fx[1]; + sgct::ShaderProgram *shader; + fx[0].init("OpacityControl", absPath("${SHADERS}/postFX_vs.glsl"), absPath("${SHADERS}/postFX_fs.glsl")); + fx[0].setUpdateUniformsFunction(postFXPass); + shader = fx[0].getShaderProgram(); + shader->bind(); + _postFXTexLoc = shader->getUniformLocation("Tex"); + _postFXOpacityLoc = shader->getUniformLocation("Opacity"); + shader->unbind(); + _sgctEngine->addPostFX(fx[0]); } \ No newline at end of file diff --git a/src/rendering/renderengine.cpp b/src/rendering/renderengine.cpp index 094a3e1440..60a71f9ed5 100644 --- a/src/rendering/renderengine.cpp +++ b/src/rendering/renderengine.cpp @@ -175,6 +175,7 @@ namespace openspace { , _performanceMemory(nullptr) , _visualizeABuffer(false) , _visualizer(nullptr) + , _globalOpactity(1.f) { } @@ -607,6 +608,14 @@ namespace openspace { return _abuffer; } + float RenderEngine::globalOpacity(){ + return _globalOpactity; + } + + void RenderEngine::setGlobalOpacity(float opacity){ + _globalOpactity = opacity; + } + void RenderEngine::generateGlslConfig() { LDEBUG("Generating GLSLS config, expect shader recompilation"); int xSize = sgct::Engine::instance()->getActiveWindowPtr()->getXFramebufferResolution();;