PDA

View Full Version : confused about color state (with MRTs)



cyrfer
11-20-2006, 12:16 AM
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. http://cyrf.com/temp/mrt/glcolor_white.png

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: http://cyrf.com/temp/mrt/glcolor_green.png

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.
http://cyrf.com/temp/mrt/glcolor_red.png

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.
http://cyrf.com/temp/mrt/glcolor_blue.png

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)
http://cyrf.com/temp/mrt/glcolor_grey.png

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

Komat
11-20-2006, 01:04 AM
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)?

cyrfer
11-20-2006, 09:34 AM
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!