JPG as alpha channel - what to think of it?

Discussion for Level editing, modeling, programming, or any of the other technical aspects of Quake
Post Reply
User avatar
monaster
Posts: 532
Joined: Mon Apr 28, 2008 1:52 pm

JPG as alpha channel - what to think of it?

Post by monaster »

Found that on the splash damage forums: sounds ... strange to me (especially these 4 stages minimum), but I'm clearly not an expert in this regard, who's smarter?

Code: Select all

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?)
If you are caught on a golf course during a storm and are afraid of lightning, hold up a 1-iron. Not even God can hit a 1-iron.
-Lee Trevino, golfer who actually has been struck by lightning.
Silicone_Milk
Posts: 2237
Joined: Sat Mar 12, 2005 10:49 pm

Re: JPG as alpha channel - what to think of it?

Post by Silicone_Milk »

A more efficient way would be to just use a .tga file...
Post Reply