I'm writing a application where a user is allowed to toggle between different shaders, and combinations of them. Thus i want to draw the exact same scene a multiple time.
In the end, all the passes should be combined into one single output. To combine all the passes i thought about using glblendfunc, but i dont get the result I want to have.
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//use first shader
draw();
if (secondShaderWished) {
//use second shader
draw()
}
In each draw call i draw a texture which does have alpha values, e.g. transparent regions. The Endresult i get is that I see mainly the effect of the last render pass, but on the boundary (where the alpha-values slightly drop off) I do see the first shader effects. What I do think is that i should use a second glBlendFunc which allows to blend the two passes, but I cant think of a way to not touch any of the alpha values, which would destroy the wished effect.
What should I do? Is there something else then alphablending?
Edit: My goal is to combine one or more passes. I want to mix the colors (most probably adding them together), wehereas the color in each path is calculated via the following blending function across different layers: glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA)
EDIT: Hi again! I'm working on this problem but I get stuck. I dont understand how i can properly set the sampler2d in any shader... What am I doing wrong?
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, _FBO)
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, _Tex);
glViewport(0, 0, viewportSize.x(), viewportSize.y());
draw();
GLuint texLocation = glGetUniformLocation(_shader->getProgramID(),"pass0");
glUniform1i(texLocation, 0);
glBindTexture(GL_TEXTURE_2D, 0);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);