Combining multiple opengl fragment shaders

I want to transfer some image processing work to OpenGL for performance using OpenGL ES. I have a very simple threshold algorithm, but I would like to combine additional filters with the image (for example, contrast).

My first thought was to complete this using several fragmentary shaders. However, I would like to do this pretty quickly, so that it will cause a lot of changes in the state? The only method I read about is to do this by working on the texture, and then I will call "use the program" several times.

Is there a more efficient way to do this? Ideally, I would like to perform contrast stretching and histogram balance as part of the steps.

If I cannot combine this with a single shader, will there be FBO for me here?

I'm a little new to OpenGL (in case you couldn't tell).

Thank!

Simon

+3
source share
2 answers

You cannot โ€œmergeโ€ a fragment shader unless you do it manually, so the only reasonable choice is to render โ€œping-pongโ€ using FBOs. You have 2 FBOs, draw one and read from the other, then switch the FBOs and repeat, switching the fragment shaders between rendering.

+4
source

Ping pong rendering , ! , LibGDX, "" , , , FrameBuffers:

FrameBuffer ping = fbo; // the framebuffer containing your rendered texture
for (ShaderProgram shader : shaders) {
    pong.clear();
    pong.begin();
    batch.begin();
    batch.setShader(shader);
    batch.draw(ping.getColorBufferTexture(), 0, 0, width, height);
    batch.end();
    pong.end();
    ping = pong;
}
batch.begin();
batch.draw(pong.getColorBufferTexture(), 0, 0, width, height);
batch.end();

( , ) , preallocating . , , .

+1

All Articles