Output multiple fragments to a single buffer

I have my fragment shader in which I access 4 different fragments in a texture by giving calls to texture2DRect. After doing some calculations I want to write these 4 values(each of which is a vec4) to a single frame buffer attachment. i.e. say GL_COLOR_ATTACHMENT0_EXT. Normally we can output a single value. Is there any way in which I can output multiple values to the buffer ?

You can see the fragment shader as a function that computes a value of a single fragment in a specific position. So, the short answer to your question is “no”.

Multiple render target!

gl_FragData[0] = result0.rgba;
gl_FragData[1] = result1.rgba;
gl_FragData[2] = result2.rgba;
gl_FragData[3] = result3.rgba;

Elvis, that is not what I want. In the code that you have suggested we are writing to 4 different targets. I want to write result0, result1, result2 and result3 to the same target, say for example GL_COLOR_ATTACHMENT0_EXT.

Well as Zengar already said this is not possible. Because the Results of a Fragment Shader are only written to that Fragment which it was executed for. So you will have to go with the way elvis pointed out or don’t do it at all.

Well, that depends on the desired precision e.g. it’s possible to write 16 8-bit values to a single RGBA_32F attachment using pixel packing.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.