Hey,
I tried to use a jpg image instead of an alpha channel in one of my shaders. I actually found a way to achieve this and i got some good results, but the bad side is that i need 4 stages. Does someone maybe know a more efficent way? In case someone is interested how i did it here is the shader:
textures/minigame_2/jpg_alpha
{
qer_editorimage textures/minigame_2/blendfunc_test
{
map $whiteimage
blendfunc gl_one_minus_dst_color GL_ZERO
}
{
map textures/minigame_2/test_texture.jpg
blendfunc gl_one gl_one
}
{
map textures/minigame_2/test_alpha.jpg
blendfunc gl_one_minus_dst_color gl_zero
}
{
map textures/minigame_2/test_texture.jpg
blendfunc gl_one gl_one
}
}
The mathematical idea behind the shader is the following:
little Substitution:
1 = $whiteimage
D = Destination
T = Texture
A = Alpha
First stage gives:
1*(1-D) + 0
The second stage just adds the texture:
T + (1-D)
The third stage does this:
A*(1-(T+1-D)) + 0
So as the final result we get:
T + A*(D-T)
which is equal to good old gl_one_minus_src_ alpha gl_src_alpha but with a jpg texture instead of alpha channel:
T*(1-A) + D*A
One problem i could think of is that if a stage creates color values above 1 the value will be written to framebuffer as 1. (I’m not quite sure about this point, maybe some experts here?)
Best regards,
Max1