Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Telamon

ARRRGG!!! Depth-testing and Transparency

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

Hi. I''m working on a school project with two other people and we are adding a particle engine to our game. As a base for this, we are using the code from NeHe''s particles tutorial (I think it''s number 19). Anyways, when we turn on depth testing, the particles don''t blend right - you can see where the edges are. NeHe uses a weird alpha blend function to blend the black pixels of bitmaps onto the background (his particle images don''t have an alpha channel). When we turn depth testing off in our game to render particles, they look great. But with depth testing they don''t draw completely transparently onto what''s behind them. This is a problem because we want the particles to be occuldable. I tried turning on depth testing in NeHe''s lesson 9 (the one with the spinning particles) just to see what would happen, and it completely messed up his drawing code, just like it is in our game. What gives? Any advice would be greatly appreciated! ---------------------------------------- Let be be finale of seem, seems to me. ---------------------------------------- Coding: http://www.stanford.edu/~jjshed/coding Miscellany: http://www.stanford.edu/~jjshed

Share this post


Link to post
Share on other sites
Advertisement
I''ve had trouble with multiple transparent objects drawn out of order before which is (I think) what you''re having a problem with. What I did to fix it was to use alpha testing (look up glAlphaFunc) to test each fragments alpha value against a constant value. Hope that helps

Share this post


Link to post
Share on other sites
The normal way of drawing transparant stuff is:
1. Draw all solid stuff (with z-check and z-write)
2. Sort all you transparant stuff
3. Draw all you transparant stuff, back to front (with z-check, but not z-write)

Problem with this is that the transparant stuff don't occlude, but since you draw them last it usually isn't a problem.

Edit: Another thing, if you use additive blending, sorting isn't needed.

[edited by - Jolle on November 17, 2003 1:35:35 PM]

Share this post


Link to post
Share on other sites
I understand the problem: NeHe uses something called masking to get rid of the edges. The problem is when you change the color of a transparent object, the black changes color slightly to what you are changing the color to (im assuming you are using a white particle with a black background and want to turn it another color to simular fire or water or something). Also, if you have fog the color will be changed. Tell me if either of these things im saying is true then I can post a resolution to one/both

Share this post


Link to post
Share on other sites
I am having the EXACT same problem with my game right now too, I know exactly what that looks like. I think the way to do it is just what Jolle said, but can I get a description of what Z-check & Z-write mean? Is that just depth testing of some sort?

Thanks

Share this post


Link to post
Share on other sites
Hey, this is just off the top of my head so i may be wrong but I think if you do this:

glDepthMask(false);
//Draw Particles
glDepthMask(true);

that should solve the problem.

Luke.

Hyperdev

"To err is human, to really mess up requires a computer"

Share this post


Link to post
Share on other sites
Z-check: Compare z-value against the value in the z-buffer and only draw the fragment if it is greater/smaller/whatever. To disable z-check, glDepthFunc(GL_ALWAYS) can be used. To turn it back on, use glDepthFunc(GL_LEQUAL) (or GL_LESS/GL_GREATER/whatever).

Z-write: Whatever you write the fragments z-value to the z-buffer or not. To disable, use what Lukerd said.

Another note: On a second thought, if you actually sort the transparant stuff, disabling Z-write isn''t needed.

So you shouldn''t then have to worry at all about z-write/z-check. Simply use what you usually use.

Share this post


Link to post
Share on other sites
quote:
Original post by Lukerd
Hey, this is just off the top of my head so i may be wrong but I think if you do this:

glDepthMask(false);
//Draw Particles
glDepthMask(true);

that should solve the problem.

Luke.



what he said.


if its mixed with solid objects, try this


glEnable(GL_DEPTH_TEST);
DrawNonAlphaObjects();
glDepthMask(false);
DrawAlphaObjects();
glDepthMask(true);
glDisable(GL_DEPTH_TEST);


using teh depth mask tells it to check, but not update the depth buffer. Very handy (and it also increases speed).

Share this post


Link to post
Share on other sites
Also, the Blending Factors in BlendFunc that are used in NeHe's code are kind of stupid. Try out different Blending Factors to see what works best.

The eight blending factors are:

GL_ZERO
GL_ONE
GL_SRC_COLOR
GL_ONE_MINUS_SRC_COLOR
GL_SRC_ALPHA
GL_ONE_MINUS_SRC_ALPHA
GL_DST_ALPHA
GL_ONE_MINUS_DST_ALPHA

Or something like that.

If it has no Alpha Channel, you are somewhat limited, but if you want black to be transparent, use (GL_ONE,GL_ONE_MINUS_SRC_COLOR). I think that should work.

Edit: You could also use (GL_ONE,GL_ONE) which would be like screening in Photoshop. The Dark Colors would not show up at all, but the Light ones will. This would probably be better.

--------------------------------------
I am the master of stories.....
If only I could just write them down...

[edited by - Nathaniel Hammen on November 21, 2003 12:49:20 PM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
EXCELLENT, I will test out some of those blending equations... I think the (GL_ONE,GL_ONE_MINUS_SRC_COLOR) is the setup I want... so that the black doesn''t show up. I guess if I wasn''t a lazy bumb I could have looked it up myself. THANKS!!!!

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!