MRT fragment shader output

I have 3 colour render buffers attached to my FBO and most of the time I will draw to all of them in the same shader using something like

outFragData[0] = vec4(1.0);
outFragData[1] = vec4(1.0);
outFragData[2] = vec4(1.0);

but what if I only want to draw to one of the colour buffers? is this possible without changing the bound Frame Buffer Object? currently if I draw to only one buffer I will get black coloured data in the remaining buffers, is there a way around this?

A glDrawBuffers() call with the list of color attachments you want to draw to will select a subset of the FBO’s attachments. If you’re only selecting one, you can use glDrawBuffer(GL_COLOR_ATTACHMENT#) but you’ll need to use glDrawBuffers() to restore rendering to all three.

int targets[1]={GL_COLOR_ATTACHMENT0};

Then, you restore drawing to the 3:


Thanks guys, I figured that is what I’d have to do, I kind of wondering if there was a was of discarding only certian fragment outputs and not all. I guess not.

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