diff --git a/include/openspace/rendering/planets/renderableplanetprojection.h b/include/openspace/rendering/planets/renderableplanetprojection.h index 44980c7f6a..3bba6d83b6 100644 --- a/include/openspace/rendering/planets/renderableplanetprojection.h +++ b/include/openspace/rendering/planets/renderableplanetprojection.h @@ -74,6 +74,8 @@ private: properties::TriggerProperty _imageTrigger; ghoul::opengl::ProgramObject* _programObject; + ghoul::opengl::ProgramObject* _fboProgramObject; + ghoul::opengl::Texture* _texture; ghoul::opengl::Texture* _textureProj; @@ -93,6 +95,9 @@ private: // FBO stuff GLuint _fboID; + GLuint _quad; + GLuint _vertexPositionBuffer; + }; } // namespace openspace diff --git a/openspace-data b/openspace-data index 6c438c384d..afc56f6e14 160000 --- a/openspace-data +++ b/openspace-data @@ -1 +1 @@ -Subproject commit 6c438c384dd74171594e7edcfaa3714bf48b5d33 +Subproject commit afc56f6e14bf766454056ea89619d17db5b47256 diff --git a/shaders/fboPass_fs.glsl b/shaders/fboPass_fs.glsl new file mode 100644 index 0000000000..3abd9160f6 --- /dev/null +++ b/shaders/fboPass_fs.glsl @@ -0,0 +1,43 @@ +/***************************************************************************************** + * * + * 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 + +uniform sampler2D texture1; +in vec4 vs_position; + +out vec4 color; + + +void main() { + vec2 uv = vec2(0.5,0.5)*vs_position.xy+vec2(0.5,0.5); + if(uv.x > 0.5 && uv.x < 0.6){ + color = texture(texture1, uv); + //color.a = 1.f; + color.a = 0.1f;//1.f - abs(uv.x - 0.55) / (0.6 - 0.5); + // output = color*color.a + source*(1-color.a) + }else{ + color = vec4(1,0,0,0); + } +} \ No newline at end of file diff --git a/shaders/fboPass_vs.glsl b/shaders/fboPass_vs.glsl new file mode 100644 index 0000000000..651cc4c9a4 --- /dev/null +++ b/shaders/fboPass_vs.glsl @@ -0,0 +1,34 @@ +/***************************************************************************************** + * * + * 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 vec4 in_position; + +out vec4 vs_position; + +void main() { + vs_position = in_position; + gl_Position = vec4(in_position.xy, 0.0, 1.0); +} diff --git a/shaders/projectiveTexture_fs.glsl b/shaders/projectiveTexture_fs.glsl index b3f9d67ae3..2fc4d1d34a 100644 --- a/shaders/projectiveTexture_fs.glsl +++ b/shaders/projectiveTexture_fs.glsl @@ -78,7 +78,7 @@ void main() // PROJECTIVE TEXTURE vec4 projTexColor = textureProj(texture2, ProjTexCoord); - vec4 shaded = max(intensity * diffuse, ambient); + vec4 shaded = diffuse;//max(intensity * diffuse, ambient); if (ProjTexCoord[0] > 0.0 || ProjTexCoord[1] > 0.0 || ProjTexCoord[0] < ProjTexCoord[2] || diff --git a/src/rendering/planets/renderableplanetprojection.cpp b/src/rendering/planets/renderableplanetprojection.cpp index 7da0e59555..270383f3c8 100644 --- a/src/rendering/planets/renderableplanetprojection.cpp +++ b/src/rendering/planets/renderableplanetprojection.cpp @@ -72,6 +72,7 @@ RenderablePlanetProjection::RenderablePlanetProjection(const ghoul::Dictionary& , _projectionTexturePath("colorTexture", "Color Texture") , _imageTrigger("imageTrigger", "Image Trigger") , _programObject(nullptr) + , _fboProgramObject(nullptr) , _texture(nullptr) , _textureProj(nullptr) , _geometry(nullptr) @@ -131,6 +132,10 @@ bool RenderablePlanetProjection::initialize(){ completeSuccess &= OsEng.ref().configurationManager().getValue("projectiveProgram", _programObject); + if (_fboProgramObject == nullptr) + completeSuccess + &= OsEng.ref().configurationManager().getValue("fboPassProgram", _fboProgramObject); + loadTexture(); completeSuccess &= (_texture != nullptr); completeSuccess &= (_textureProj != nullptr); @@ -148,6 +153,29 @@ bool RenderablePlanetProjection::initialize(){ // switch back to window-system-provided framebuffer glBindFramebuffer(GL_FRAMEBUFFER, 0); + + // SCREEN-QUAD + const GLfloat size = 1.0f; + const GLfloat w = 1.0f; + const GLfloat vertex_data[] = { + // x y z w s t + -size, -size, 0.0f, w, 0, 1, + size, size, 0.0f, w, 1, 0, + -size, size, 0.0f, w, 0, 0, + -size, -size, 0.0f, w, 0, 1, + size, -size, 0.0f, w, 1, 1, + size, size, 0.0f, w, 1, 0, + }; + + glGenVertexArrays(1, &_quad); // generate array + glBindVertexArray(_quad); // bind array + glGenBuffers(1, &_vertexPositionBuffer); // generate buffer + glBindBuffer(GL_ARRAY_BUFFER, _vertexPositionBuffer); // bind buffer + glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_data), vertex_data, GL_STATIC_DRAW); + glEnableVertexAttribArray(0); + glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 6, reinterpret_cast(0)); + glEnableVertexAttribArray(1); + glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 6, reinterpret_cast(sizeof(GLfloat) * 4)); return completeSuccess; } @@ -243,17 +271,44 @@ void RenderablePlanetProjection::updateTex(){ printOpenGLError(); } +#define RENDER_TO_TEXTURE void RenderablePlanetProjection::render(const RenderData& data) { if (!_programObject) return; if (!_textureProj) return; //updateTex(); - // keep handle to the current bound FBO GLint defaultFBO; glGetIntegerv(GL_FRAMEBUFFER_BINDING, &defaultFBO); +#ifdef RENDER_TO_TEXTURE + glBindFramebuffer(GL_FRAMEBUFFER, _fboID); + + glEnable(GL_BLEND); + glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD); + glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ZERO, GL_ZERO); + glViewport(0, 0, 1024, 1024); + //glClear(GL_COLOR_BUFFER_BIT); + _fboProgramObject->activate(); + + ghoul::opengl::TextureUnit unitFbo; + unitFbo.activate(); + _textureProj->bind(); + _fboProgramObject->setUniform("texture1", unitFbo); + + glBindVertexArray(_quad); + glDrawArrays(GL_TRIANGLES, 0, 6); + + _fboProgramObject->deactivate(); + + glDisable(GL_BLEND); + + //bind back to default + glBindFramebuffer(GL_FRAMEBUFFER, defaultFBO); + glViewport(0, 0, 1920, 1080); +#endif + // activate shader _programObject->activate(); diff --git a/src/rendering/renderableplane.cpp b/src/rendering/renderableplane.cpp index a1b60246ff..75c98265d3 100644 --- a/src/rendering/renderableplane.cpp +++ b/src/rendering/renderableplane.cpp @@ -112,7 +112,7 @@ bool RenderablePlane::initialize() { // ============================ // GEOMETRY (quad) // ============================ - const GLfloat size = _size[0]; + const GLfloat size = _size[0]; const GLfloat w = _size[1]; const GLfloat vertex_data[] = { // square of two triangles (sigh) // x y z w s t diff --git a/src/scenegraph/scenegraph.cpp b/src/scenegraph/scenegraph.cpp index 41fe7c642b..986afc53b0 100644 --- a/src/scenegraph/scenegraph.cpp +++ b/src/scenegraph/scenegraph.cpp @@ -163,7 +163,16 @@ bool SceneGraph::initialize() typedef std::chrono::duration > second_; std::chrono::time_point beginning(clock_::now()); - // pscstandard + // fboPassthrough program + tmpProgram = ProgramObject::Build("fboPassProgram", + "${SHADERS}/fboPass_vs.glsl", + "${SHADERS}/fboPass_fs.glsl"); + if (!tmpProgram) return false; + tmpProgram->setProgramObjectCallback(cb); + _programs.push_back(tmpProgram); + OsEng.ref().configurationManager().setValue("fboPassProgram", tmpProgram); + + // projection program tmpProgram = ProgramObject::Build("projectiveProgram", "${SHADERS}/projectiveTexture_vs.glsl", "${SHADERS}/projectiveTexture_fs.glsl");