A few questions about blendFunc


(Max1) #1

Hello,

I tested the blendfunc parameters gl_dst_alpha, gl_one_minus_dst_alpha and gl_src_alpha_saturate, but I experienced some problems.

I use the following shader:

textures/minigame_2/test_shader
{
qer_editorimage textures/minigame_2/blendfunc_test.tga
nomipmaps
{
map textures/minigame_2/dst_alpha.tga
blendfunc gl_dst_color gl_zero
// alphagen const 0
}
{
map textures/minigame_2/blendfunc_test.tga
blendfunc gl_dst_alpha gl_one_minus_dst_alpha
}
}

The texture dst_alpha.tga has entire white RGB channels and an alpha channel with some black and white parts. I expected the first blendfunc to do this:

[(Rs,Gs,Bs,As)(Rd,Gd,Bd,Ad)]+[(Rd,Gd,Bd,Ad)(0,0,0,0)]

Rs,Gs,Bs and As reperesent the source RGBA and Rd,Gd,Bd and Ad the destination RGBA.

Since the RGB of the source was white and I assumed the alpha channel of the Destination to be white, the blendfunc should give this:

[(1,1,1,As)*(Rd,Gd,Bd,1)]+[(0,0,0,0)]=(Rd,Gd,Bd,As)

This means the first stage of the shader shouldnt change the color information in the frame buffer, but only add the alpha channel.

The blendfunc of the second stage is just like the common blendfunc blend, but with the destination alpha instead of the source alpha.

The problem is that in the second stage the alpha channel of the frame buffer is just white. That means in the end you just see blendfunc_test.tga. Even after i put alphagen const 0, which should create an entire black alpha channel, the second stage behaved as if the destination alpha channel was white.

So my questions are:

  1. Is alpha channel information stored in the frame buffer, or does the information just get lost?

  2. Is there a way to get this work?

The reason why I’d like to have such a shader is that I could add alpha channels to textures in the pak0 without having to ship them with my own .pk3 (and some other ideas).

Best Regards,

Max1