mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-02 01:30:34 -06:00
created postFX functions in main and added a postFX pass to sgct engine to allow for a global fade after executing certain scripts.
added global opacity member variable with set/get methods in render engine. added two VERY simple shaders used in the post FX pass. Note these are not handled in openspace so updating files does not update shader
This commit is contained in:
@@ -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;
|
||||
};
|
||||
|
||||
36
shaders/postFX_fs.glsl
Normal file
36
shaders/postFX_fs.glsl
Normal file
@@ -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;
|
||||
}
|
||||
36
shaders/postFX_vs.glsl
Normal file
36
shaders/postFX_vs.glsl
Normal file
@@ -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;
|
||||
}
|
||||
30
src/main.cpp
30
src/main.cpp
@@ -24,8 +24,9 @@
|
||||
****************************************************************************************/
|
||||
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <ghoul/logging/logging>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <sgct.h>
|
||||
|
||||
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<size_t>(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]);
|
||||
}
|
||||
@@ -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();;
|
||||
|
||||
Reference in New Issue
Block a user