Site Stability Read more... ×

XNA partially transparent pixels

This topic is 2836 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hey guys,

I have the graphic of a tree

It's a Photoshop PNG with transparent background, but apparently Photoshop doesn't make alpha channels by default with PNGs.

So I made it a TGA with an alpha channel

Saved it as TGA, but we still get weird stuff that won't be fully transparent like this in XNA;

(The trees with solid black shadow were our first try in PNG, it just made partially transparent pixels solid black )

Any idea/tips on how to achieve good transparency with certain pixels being only partially transparent (i.e; for shadows)?

Thanks!

P.S: I'm really sorry for the awful sentence construction, I'm absolutely exhausted and can't brain very hard at the moment. You guys know how it is. ;)

P.S 2: We'd prefer not to use the pink background technique. It doesn't seem to work very well with partially transparent pixels (i.e; causes the pink outline issue) and as far as I know isn't the way to go. We really need some help understanding/learning how to use true Alpha. Thanks!

Share on other sites
Hi!

This rather looks like you have used alpha testing. Alpha testing makes a binary decision and gives you either full transparency or opacity.
But, perhaps this is an issue caused by the pre-multiplied alpha. This article here explains how alpha blending is done in xna 4.0.

Share on other sites

Could you elaborate on "alpha testing"? What do you mean by that? If we're using that, it's definitely not intentional. Could you explain how to turn it off and allow partial transparency?

Thanks.

Share on other sites
Hi again,

Alpha testing discards a pixel if its alpha value is smaller or greater than some reference value. If a pixel is discarded it does not reach the output merger state, so no writes will occur, which makes it faster than alpha blending. However, you can only have full transparency or opacity. Since alpha testing was formerly a fixed-function pipeline feature and is now deprecated, you either have to implement yourself in a shader or use the AlphaTestEffect. (So, it is not enabled by a state anymore.)

To use alpha blending you should first make sure that the texture content processor (you find it in the properties of your texture) has “Premultiply Alpha” enabled.
And then you can use in your rendering:
spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend); spriteBatch.Draw(…); spriteBatch.End();
That should do it. If it doesn’t could you post your png/tga texture, so that we can have a look at it and test it here?

Share on other sites
Hey Tsus, unfortunately that didn't work.

Here's the PNG and TGA we've been trying everything on;

www.araetis.com/misc/1.png
www.araetis.com/misc/1.tga

If you have trouble downloading the TGA, I zipped both images under www.araetis.com/misc/misc.zip

Thanks again for your prompt replies and sorry for my slow ones.

Share on other sites
Hi!

The png looks fine, while the tga looks a little grayish.

I attached a small sample for you which loads and shows both textures with alpha blending on some grass. Perhaps you can spot the difference to your code. It works as expected on my end.

Good luck!

Share on other sites
Update; we figured it out. A bit of old code slipped through our nets and there was a loop where a loop shouldn't be. We can display transparency great with PNGs now, thanks for your reply!

• Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 15
• 21
• 21
• 11
• 25
×

Important Information

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!