PDA

View Full Version : color matrix from arb_imaging



mmm
08-03-2002, 04:59 PM
hi guys,

i would like to know why this color matrix




0.4 0.3 0.3 0.0
0.4 0.3 0.3 0.0
0.4 0.3 0.3 0.0
0.0 0.0 0.0 1.0


is gray-scaling only texturized polys. Non texturized polys stay unchanged (as they would be with an identity color matrix).

thanks
marcio

andrewl
08-03-2002, 05:20 PM
The colour matrix only applies to colours during pixel transfer operations, e.g. glDrawPixels, glReadPixels, glCopyPixels and glTex(Copy)(Sub)Image*.

Take a look at figures 3.7, 4.2 and 4.3 in the OpenGL 1.4 spec to see where it figures in. (It's the box labeled "color matrix scale and bias".)

So what's happening is that the vertex colours are left unchanged, but your texture is altered when you load it.

[This message has been edited by andrewl (edited 08-03-2002).]

mmm
08-03-2002, 05:47 PM
thank you.
I was thinking color matrix to be applied in rasterization (on fragment color).
BTW do you know how to grayscale a scene? (using standard GL 1.3 or ARB exts. NV_register_combiners can do it but i would not like to use it).

thanks
marcio

Dan82181
08-03-2002, 09:22 PM
mmm,

there are several ways in which you can grayscale a scene, some simple, some not so simple.

1 - The fastest way (in terms of rendering) would be to take every texture and grayscale it all before doing any drawing (and white vertex coloring). Downside is that some blending effects might not give the same/correct results.

2 - You could draw everything with normal coloring, use glPixelTransfer[if] to scale each color, use glReadPixels to read the scaled image, add the RGB components of each pixel and replicate it back, set glPixelTransfer[if] back to normal scaling, and use glDrawPixels to draw the intensity (grayscaled) image back to the framebuffer. Downside is that it will probably be much slower and you will eat some fillrate and bus transfer bandwidth, not to mention the additional work by the processor.

I'm sure others would have fancier and better ways of doing it, this is just what I can think of off the top of my head at 1:20 in the morning.

Dan

ScottManDeath
08-04-2002, 03:07 AM
Hi

with GL_ARB_texture_env_combine && GL_ARB_texture_env_dot3 you can do it :

1. Render your scene as usually
2. Read back your scene into a texture (full screen)using glTexSubImage2D, or using render_texture extenion.
3. Render a full scene quad and set the combiners so that they do a GL_DOT3_ARB between GL_TEXTURE_ARB and GL_CONSTANT_ARB
set the texture environment constant to {0.59,0.30,0.11,1.0}
Perhaps you need to play a little bit with with the constant because the GL_DOT3_ARB does

dot3= (r0-0.5)*(r1-0.5)+(g0-0.5)*(g1-0.5)+(b0-0.5)*(b1-0.5)
where r0..b0 is the first operand and r1..b1 is the second operand

See the specs for further details

Bye
ScottManDeath

knackered
08-04-2002, 03:25 AM
Or use register combiners to spread one of the rgb components over the final output colour.