Alpha Vanishes

Hi there,

I’m sure this is just a matter of understanding and not a bug, but how come that when I sample some DX-Output containing transparency, the alpha value seems to vanish?

Please see the small patch I attached.

AlphaTest.v4p (4.5 kB)

you are right, is not a bug. It depends on the texture format. take a look of this patch

AlphaTest2.v4p (5.0 kB)

well, you killed the alpha channel, so now the dx-texture is no more transparent…

u must set texture with alpha formtat in dx9texture. It’s like ARGB etc.

hi sven,

when drawing with default blend mode a semi-transparent white quad onto a transparent black texture you will get the folowing:

R, G, B = a
A = a*a

the alpha value of your quad is used for blending its color onto the background color. so colors are already affected.
additionally the alpha value of your quad changes the alpha of the texture. in fact the same formula is used to compute the resulting alpha value.

default blend mode is explained here: Transparency

the above example in detail:
transparent black = (C1, A1) = (0, 0)
semi transparent white = (C2, A2) = (1, a)
->
C = C1 * (1-A2) + C2 * A2 = 0 * (1-a) + 1 * a = a
A = A1 * (1-A2) + A2 * A2 = 0 * (1-a) + a * a = a*a

it gets worse after sampling the texture in the next render pass:
with using the the default blend mode at the end the color you see is:
RGB = aaa
A = you can’t see an alpha value

sorrily this part of the rendering pipeline cannot be programmed with shaders. but the price question would be what exactly you would want to see: just the same color in the lower renderer?

so: RGB = a?

  • the textures’ alpha would be a and the color would be 1 (no premultiplication / blending)
  • the textures’ color would be a and alpha would be 1 (this is the same like having no alpha texture at all)

or what kind of special thing do would you want to do with the alpha? i will check if i can make the blend (advanced) node still more advanced, so that you can use different blending operations for processing alpha than for processing colors.

for now i can think of two ways how to get around this issue:

  • use another blend mode in the first render pass. if you want to have the alpha value of the quad in the alpha channel of the texture then disable alpha blending. the specified alpha value will no longer be used for blending colors but will directly be written into the texture. (like the colors also)

  • use another stage to process alpha values the way you want.

AlphaTest.v4p (14.6 kB)

Hello Gregsn,

thanks a lot for your comprehensive explanation and the example patch.
I attached a simple demonstration of the “special thing” I’m trying to implement.
Do you think there might be any chance to steer against that exponential falloff by kind of amplifying the alpha level back in the shader - maybe with accepting a certain loss of definition?

Best,
Sven

AlphaBlur.zip (12.2 kB)

the attached solution probably only works pleasing for non overlapping particle systems ?!

but your idea is clever. either

  • write a shader which does the recovery of the orginal alpha value by taking the nth root of the alpha and use it at the end of you rendering chain (try use floating point textures for better results)
  • or put that code into each inbetween shader.

yes! can!

Alpha Problem.v4p (15.6 kB)

Got it. A simple division by its SQRT in each shader step seems to do the trick :)

Thanks again for your help!

Cheers,
Sven