Alpha wierdness

Started by
6 comments, last by Wicked Ewok 20 years, 6 months ago
I''m having problems with alphas sometimes letting an object behind through and other times, blocking it with the clear color. I''ve been checking out the other posts on this but I''m fairly new to opengl and I still don''t understand what''s wrong with my blending setups. Here''s what I see, it''s clearly not what I want. I hope you can tell what''s wrong with it, but in short, the bars are letting you see the black ring but not the bars behind it. Why is this? http://www.mojo9.com/~wickedewok/wrong.jpg Here''s the current set up of my blending functions and my depth testing(might it have anything to do with depth testing?): ::glEnable( GL_TEXTURE_2D ); ::glEnable(GL_BLEND); ::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); ::glEnable(GL_LIGHTING); ::glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND); ::glBindTexture(GL_TEXTURE_2D, tex ); depthtesting setup: ::glClearDepth(1.0f); ::glEnable(GL_DEPTH_TEST); ::glDepthFunc(GL_LESS); Thanks
-=~''^''~=-.,_Wicked_,.-=~''^''~=-
Advertisement
In order for transparency to work you have to render polygons in back to front order. You''ll have to sort the polygons such that the furthest are rendered first.
-Ostsol
But couldn''t we let OpenGL do that through Z buffering? The program I''m working with(the teacher''s) is not set up to render back to front at all, and it would be a lot of rewriting of the core code to get that to work. I''ve never had trouble doing this in Direct3D even without rendering in order.
-=~''^''~=-.,_Wicked_,.-=~''^''~=-
You should also disable writes to the z-buffer before you render the transparent objects (glDepthMask(GL_FALSE).

And about the sorting. I would suggest to first render all non-transparent objects without sorting them. And then render all transparent objects (they should be sorted back to front, to avoid problems with some blend modes).




--
Programmer of Star Torn


--

There are only 10 types of people in the world:
Those who understand binary, and those who don''t.
Z-Buffering does not sort anything. All it does is keep track of the z-values of each pixel rendered to the screen. When a pixel is incoming, its z-value is compared to what is in the z-buffer at the same location. If the new pixel fails the z-test, it will simply not be rendered.
-Ostsol
Did I said z-buffering would sort anything?

You just gave the reason why you should disable Z-writes before rendering transparent objects. Because else the z-test would fail for everything behind the transparent object (which of course shouldn''t happen).


--
Programmer of Star Torn


--

There are only 10 types of people in the world:
Those who understand binary, and those who don''t.
quote:Original post by Woodoo
Did I said z-buffering would sort anything?

You just gave the reason why you should disable Z-writes before rendering transparent objects. Because else the z-test would fail for everything behind the transparent object (which of course shouldn''t happen).

Sorry, I wasn''t replying to you. I should have quoted Ewok''s post.
-Ostsol
Hrmm, thanks for the replies. I think I got it down, but since I wanted any object to be able to have a alpha channeled texture, I guess I really have to render back to front sorted. And isn''t that a really bad idea since we won''t be doing any fast culling - if many things had transparencies?

I know zbuffering doesn''t sort, but it allows for some good optimization in rendering any order, front to back being most efficient.

So let''s say there was a world where any texture can potentially have a transparency. But not all of them do. Would the most efficient way to go about rendering be: find which textures have any portion of their alpha channel bits < 255; then do the sort that way? or do people just brute force back to front? It''s a hypothetical question. I''m just curious now.

-=~''''^''''~=-.,_Wicked_,.-=~''''^''''~=-
-=~''^''~=-.,_Wicked_,.-=~''^''~=-

This topic is closed to new replies.

Advertisement