XNA - Alpha channels and SpriteBlendMode

Started by
4 comments, last by ascorbic 16 years, 3 months ago
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?
.
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.
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.
.
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.
what ascorbic is talking about is the painters algorithm. Render back to front.
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.
.

This topic is closed to new replies.

Advertisement