confused about color state (with MRTs)

Hi. I’m seeing unexpected rendering results when changing the color state for an object. First off, I’m tryin to learn about Multiple Render Targets. I have disabled lighting, and I’m rendering a very simple scene, just a cube, from a perspective view. My FrameBufferObject instance has 3 attached targets, and I’m using a fragment shader to affect those 3 targets differently when rendering. The frag shader just writes out a different color to each of the 3 targets. For now, I’ve hard coded the output color for 2 of the targets, and the 3rd target is assigned the value of gl_Color.

Again, I’m binding an FBO which has 3 attachments, rendering my scene, & using a shader to fill the 3 attachments.

I see expected results when the sole object in my scene is a white color, assigned with the glColor3f function. In the following screen shot, please notice the lower-right image shows the gl_Color value.

The black color is the clear color when the FBO is bound. I’ve used glScissor, glViewport and glClear with a grey clear color to show rectangles with the 3 FBO targets bound. The upper right rectangle is essentially a copy of the one to its left, within another rendered rectangle and its own combination of glScissor, glViewport, and glClear with a blue clear color.

The problem becomes evident when I change the color of the cube in the scene. If you will notice the lower-right attachment again, as I change the glColor3f call, all the attachments are affected. I hoped that only the lower right rectangle would change, because the lower-left and upper-left are both hard coded by the fragment shader (to be red and green) used to fill the 3 attachments. Here is the first color change:

If you will continue to watch the lower-right rectangle which is showing the results of gl_Color, I will again change the color of the scene object, and notice how the other ‘hard-coded’ attachments are affected.

I’m also confused about why the clear color for the upper right rectange-in-rectange was affected. Notice how the clear color in the upper right is available again if the clear color for that viewport matches the scene object’s color.

I expected that my simple MRT shader would be able to control the output color for each of the attachments, but it seems that the scene object’s color state can greatly affect it. Does anyone know why the color in the hard-coded targets is affected by the scene object’s color state?

Look at what happens with I have the scene object colored with:
glColor3d(0.5, 0.5, 0.5)

The frag shader is:

varying vec4 color;

void main(void)
{
	gl_FragData[0] = color;
	gl_FragData[1] = vec4(1.0, 0.0, 0.0, 1.0);
	gl_FragData[2] = vec4(0.0, 1.0, 0.0, 1.0);
}

Thanks for any help, -cyrfer

Are you sure that the code you use to show the content of all attachements does not modulate the textures with vertex color (e.g. using GL_MODULATE which is the default fixed function mode)?

What a great clue! I was using modulate, and this made me wonder about the color of the quad used to show the attachments…I looked and I had no color being set for these quads. THANKS!