Jump to content
  • Advertisement
Sign in to follow this  
ascorbic

XNA - Alpha channels and SpriteBlendMode

This topic is 3984 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

Hopefully an easy solution to a XNA beginner's question... I'm looking to take a .DDS file and draw it with a given opacity AND be non-transparent. I'm looking to do #4 in the linked graphic below. Link By playing with the SpriteBlendMode and alpha values I've been able to accomplish 1-3 but not 4. What method do I use to accomplish this?

Share this post


Link to post
Share on other sites
Advertisement
IIRC, in order to get that last effect, you'll need to depth sort the sprites in the opposite order that you draw them.

Basically, both will have 75 or whatever alpha channel value. You draw the blob first, then the rectangle. However, in the SpriteBatch.Draw calls, you need to depth sort them so that the rectangle is on the bottom and the blob is on the top.

Share this post


Link to post
Share on other sites
Thanks for the reply. I've thought about what you've said but that is not what I'm looking for. I'm only trying to draw one sprite, not two or more. I just want to draw every pixel non-transparent but with opacity.

By using SpriteBlendMode.None, it draws every pixel non-transparent but it appears I lose the ability to set the opacity. I'm looking for a way to override this. The opacity information I assume is inherent in the .DDS file. I shouldn't have to modify the file every frame to accomplish what I'm looking to do.

Share this post


Link to post
Share on other sites
You'll have to write your own pixel shader. Fortunately, it'd be pretty simple, and you can give it an opacity constant that you can set to whatever value you want.

Share this post


Link to post
Share on other sites
Thanks everyone for the replies.

I figure my only two options would be:
1) Use two separate sprite files: one transparant, one not. Use the needed one in each given situation.
2) Write a shader. Not too familiar with shaders, but that doesn't sound too mind-shattering to do.

I guess I started this thread on a somewhat false assumption. Thanks for straightening me out a bit.

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!