spritebatch and alpha

hi I have a question regarding alpha values on sprit batch.

I’m working on my GUI. It’s has a slight transparent. But of cause if I draw several UI elements the alpha values add together so in the end some parts are not transparent. Is it possible to only take the max alpha value of two textures when drawing them on top each other?

Trying to layer several GUI components, each with its own alpha value, is very difficult to get right. I have found the best way to get a consistently translucent interface with no alpha artifacts is to render the GUI items at full alpha to a render target that has been cleared to Color.Transparent. Then draw the render target to the main frame buffer at whatever alpha value you want. This is particularly useful for fading in and out GUI elements that are made up of several layered textures because it means the alpha blending artifacts are no longer visible.

This was really tricky to do in Empty Keys UI. I remember fixing/changing it many times. On the end the best “OK” result was to calculate opacity of each element based on opacity of parent element. EK UI has visual tree similar to WPF so I calculate each element opacity as ParentOpacity * ElementOpacity and draw it with White * FinalOpacity overlay color. The only problematic are elements, which are siblings (for example Grid with no rows or columns and many elements in it), but you don’t have that many of those in UI.

That is an awsome idea, so anoyed that I didnt think of it :wink:

If I did this wouldent the colours blend together? Ie i draw a blue form with a white textbox with some alpha on both. The blue and white would blend to create a whiter blue, but I would want the colour white.

yes they will and that’s correct behavior for “standard” UI’s.