Added separate shader for write to texture, relies on blend logic.

This commit is contained in:
Michal Marcinkowski
2014-12-22 10:02:31 -05:00
parent b14ff04f76
commit ee306cf54c
8 changed files with 151 additions and 5 deletions

View File

@@ -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

43
shaders/fboPass_fs.glsl Normal file
View File

@@ -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);
}
}

34
shaders/fboPass_vs.glsl Normal file
View File

@@ -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);
}

View File

@@ -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] ||

View File

@@ -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<void*>(0));
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 6, reinterpret_cast<void*>(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();

View File

@@ -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

View File

@@ -163,7 +163,16 @@ bool SceneGraph::initialize()
typedef std::chrono::duration<double, std::ratio<1> > second_;
std::chrono::time_point<clock_> 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");