0
votes

Hello

I want to apply multiple image processing effects to an input texture using OpenGL ES.

I successfully managned to apply one post processing effect using a Framebuffer Object but I do not quite understand how, without repeating every single step of my step of my process, I can apply numerous post processing effect without having to redo every step each time.

The steps I am going through right now are the following:

  1. Loading my shader(s) and getting the desired location to transfer my data
  2. Initializating my FBO
  3. Creating a texture using my input data
  4. Binding FBO
  5. Activating TEXTURE0 and binding the previously generated texture
  6. Sending data using the acquired location
  7. Drawing a full screen quad and making it use my shader program
  8. Reading the FBO texture (using glReadPixels) and saving the result to an image
  9. Unbinding everything to clean up.

From what I understand I do need to repeat the step 5,6,7 with my other post processing shader and using the texture I finally got in step 8 but I do not think this is the right way to go as it wil force me to read data from FBO into a texture to then retransfert them which is really costy.

Am I missing something ?

1

1 Answers

2
votes

If your 2 post-processing effects can be done in a single shader then you should do that, it's much more efficient that way because the memory bandwidth costs of reading and writing entire framebuffers often dwarfs the cost of a few extra shader calculations.

However, many post-processing effects need to operate on the finished result of previous post-processing pass. The typical solution is to setup two FBOs and 'ping-pong' between them. So, if you had 3 post-processing effects that need to be chained, you'd have 3 passes:

  • Pass 1. Texture=Input Data, Shader=Effect1, Render Target=FBO A.
  • Pass 2. Texture=FBO A, Shader=Effect2, Render Target=FBO B.
  • Pass 3. Texture=FBO B, Shader=Effect1, Render Target=FBO A.

I think the bit you're missing is that you can use the texture from a framebuffer directly without having to create a brand new texture populated with data from glReadPixels. This tutorial might help.