• Advertisement
Sign in to follow this  

Displaying a transparent sprite through a transparent surface.

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

Hello all. =) This is a question on behalf of my friend, actually. He's writing a small 3D game of sorts. He has a very basic terrain system in place, however he has a simple problem that doesn't seem to have a simple solution. His primary character is a simple sprite--a textured quad that uses an alpha channel to hide the border. Think Ragnarok Online as to how it looks. His problem is when his sprite is to appear going into water. If he renders the water first, when the sprite goes into the water, the part in the water is completely cut off (you can see the ground under the water but not the sprite), and when he renders the water last, the bottom half of the sprite (in the water) is perfectly fine, but above the water, the water gets cut off and shows the ground without the alpha blended water over it. He knows it's best to avoid putting two transparent objects together like this, but is there actually a fix short of splitting the sprite in two, one half for above the water, and one half for below? Thanks =)

Share this post


Link to post
Share on other sites
Advertisement
You usually don't want to split objects, look for a better workaround than that. Here's 2 good options:

1) Look into turning off your zbuffer. With the zbuffer off, the 2 images will blend regardless of which one gets drawn first. You may want to adjust your blending options to fix any color problems.

2) Alpha test. Assuming your sprite has a hard border, you can turn on alpha testing. This will give you ability to not render the pixels that are outside the sprites border (so that they won't be set into the zbuffer, and the water behind the quad will still be drawn). Note: this won't solve the problem if the sprite is partially transparent.
So turn alpha testing on.
Set the alpha reference. You usually set this to 0 or 1.
Set the alpha test func. You will set this to greater-than or greater-than-equal-to.

I know you can do this in D3D. I'm assuming that means you can do it with OpenGL, but I can't say for sure.
PM if you can't find an example of implementing it. Be wary, I've seen a tutorial be wrong on the alpha test function.
G'luck.

Share this post


Link to post
Share on other sites
Thank you very much =) I stupidly forgot to mention he is using DirectX and I completely forgot about the zbuffer.

Thanks again, I'll pass along the information!

Share this post


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

  • Advertisement