Jump to content
  • Advertisement
Sign in to follow this  
Monkeys

XNA partially transparent pixels

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey guys,

I have the graphic of a tree
67MmG.png

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
2012-01-10_1827.png

Saved it as TGA, but we still get weird stuff that won't be fully transparent like this in XNA;
2012-01-10_1732.png

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

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
Share on other sites
Hey Tsus, thanks for your reply.

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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

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!