PDA

View Full Version : Chroma keying through Pixel shader programme



mayursb
05-06-2005, 05:38 AM
I want to blend two textures :

Texture 1 : 8 bit Luminance
Texture 2 : 32 bit R5G5B5A1

While merging these two, I want to treat RGB(0,0,0) in texture 2 to be transparent.

Can anybody guide me how to do it through shader programme ?

Aeluned
05-06-2005, 06:47 AM
Yeah, in the fragment shader you sample the textures, check the returned color of the second
texture, if it's not 0,0,0 you can blend it with the first texture as follows (this is GLSL pseudocode):

vec4 tex1Sample = texture2D();
vec4 tex2Sample = texture2D();

if(tex2Sample.rgb = vec3(0,0,0))
gl_FragColor = tex1Sample;
else
gl_FragColor = tex1Sample*tex2Sample;

this will simply use the first texture value if the second texture rgb is black (0,0,0) or modulate them otherwise.

hope that's along the lines of what you're asking.