Sign in to follow this  
greerws

Android - partial transparency

Recommended Posts

greerws    148
Hello all. I'm laying out the design for a game on the Android using openGL ES, and I've stumbled upon an issue that I can't seem to find a solution for. I'm looking to be able to draw something on the screen, like a wall, then have a character pass behind the wall. When the character is behind the wall, I'm looking to apply an auro of transparency on the wall in front of the character, enabling you to see the character behind, without making the entire wall transparent.

Any help anyone could offer any help, or at least point me in the right direction, I'd greatly appreciate it.

Shawn Edited by greerws

Share this post


Link to post
Share on other sites
freakchild    572
Use the blend functions for transparency alone:

[CODE]
glEnable( GL_BLEND );
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
[/CODE]

There are several blend functions so it might be worth reading up on them [url="http://www.khronos.org/opengles/sdk/docs/man/xhtml/glBlendFunc.xml"]here[/url].

If you're looking for an aura from transparency then you could also do something in the shader based around the incoming transparency value.

Bear in mind that for making the character go behind the wall, simple depth pixel tests might suffice for that. If depth fails, you could use the incoming transparency value to write your aura over the wall. You could also just use the painters algorithm (drawing in a particular order) to bring one or the other to the front.

You may also consider a render to texture pass for the wall layer. This would allow you to read that layer into your shader as a texture so that it could be taken into account along with the transparency value as you write your final image. This would certainly let you take the wall into account as you decide which pixel to write, but it really may be overkill.

For basic transparency alone though go for the basic blending above so you don't overwork the shader. The link above may lead you to a blending equation that keeps things simple. Edited by freakchild

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this