Question

Should i use Frame Buffer Objects When i have 2 shaders that alters the color but the later one need to know what the previous shader set the fragment color to.

Was it helpful?

Solution

Most probably.

The wording of your question ("2 shaders that alter the color" -- so shader #1 already consumes an input image/texture that it alters?) is not 100% clear about what exactly you're trying to achieve.
You might need more than just one texture and you might need more than one FBO. But in general, as I understand your intent, yes, a FBO would be what you want to use.

If you want fragment shader #2 to access the output of fragment shader #1, rendering to a texture bound to a FBO using shader #1 and then fetching from that texture later in shader #2 is the most straightforward way. It is also the most compatible way that works even with 10 year old hardware.
This even works in a "ping pong" way (using two textures, and swapping them), for example if you do numerical integration. It is how everybody did physics simulations prior to the arrival of compute shaders.

If what you are trying to do is something more general of a "shader 1 produces some data and shader 2 consumes that to produces some other data, and not necessarily the same size / amount", then you will likely want to use a shader storage object instead.

Or, if the two shaders really just run one after another (so basically every pixel is processed by them in order), you might consider collapsing the two shaders together into one without producing an intermediate texture, which is more efficient for bandwidth and ROP/blending, and which also possibly has better accuracy.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top