Alpha textures not working properly

Started by
5 comments, last by dpadam450 12 years, 10 months ago
I have a scene in OpenGL that looks great, except for the fact that some of the texture's alphas don't show how I want them to. The alphas of the textures seem to show all the way through objects in the background all the way to the sky. However, some alphas seem to work properly, and show the object immediately behind it.

This is hard to explain, so I am attaching a picture to show what I am talking about. The palm tree's alphas seem to "cut" right through the building on the right, but the building on the left of the palm tree seem so show up properly. If anyone can tell me what is going on it would be greatly appreciated.

Fedora 13 x64
Qt 4.6.3 (using QGLWidget)
Objects are loaded using GLM Wavefront OBJ library
TZire.jpg
Advertisement
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, .4);

Thats a basic solution, it will still have some blue edges but not as you do now. All your alpha spots in the texture are still blending and writing depth values. alpha testing will remove the pixel and not even blend it.

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

I think I may have found the answer: http://www.opengl.org/resources/faq/technical/transparency.htm

Question 15.020 last paragraph:

When using depth buffering in an application, you need to be careful about the order in which you render primitives. Fully opaque primitives need to be rendered first, followed by partially opaque primitives in back-to-front order. If you don't render primitives in this order, the primitives, which would otherwise be visible through a partially opaque primitive, might lose the depth test entirely.[/quote]

glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, .4);

Thats a basic solution, it will still have some blue edges but not as you do now. All your alpha spots in the texture are still blending and writing depth values. alpha testing will remove the pixel and not even blend it.


Oh ok, I'll try that and let you know.

[quote name='dpadam450' timestamp='1307550421' post='4820968']
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, .4);

Thats a basic solution, it will still have some blue edges but not as you do now. All your alpha spots in the texture are still blending and writing depth values. alpha testing will remove the pixel and not even blend it.


Oh ok, I'll try that and let you know.
[/quote]

Ah thank you so much. That works great. I am guessing that this solution does not allow any semi-transparent textures and it just converts them to either fully opaque or fully transparent based on whether the alpha is greater than or less than 0.4? Any tips/ideas on getting some semi transparent textures working? I would like to have some dirty windows that you can still see through.
What you are showing is a draw order issue. In theory, you should draw all your solid objects first(probably sorted by texure) and then draw the alpha polygons from back to front. Anything with alpha needs to have what is behind it drawn first since it blends with what is already on the screen. This is easier said that done, tho. You are probably drawing whole meshes at a time - those you can sort form back to front pretty easily. But you wouldn't want to sort the polygons within the mesh from back to front each frame because that would be super slow. You could either live with blue outlines like dpadam450 mentioned, use hard edged alpha textures or lookup order independent transparency techniques like depth peeling...
http://blog.wolfire.com/2009/02/rendering-plants-with-smooth-edges/

You can do this or you can look up Multisampling Alpha or Multisampling transparency.

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

This topic is closed to new replies.

Advertisement