Yesterday I came across an issue that I first thought would be an easy work-around. When OpenGL uses blending it mixes fragments already written to the colour buffer, and rewrites fragments written to the depth buffer. Unfortunately this causes really annoying artefacts where there is plain alpha in a texture, and upon research I found out a few solutions. The first thing is to use blending like I already am and simply order rendering of transparent objects from back to front, but this seems over-complex for a problem so mundane. The second option, is to use a fragment shader that simply discards the fragment all together if it contains alpha. As I have read, the second option seems to be very simple and eliminates the need to order back-to-front as well as the need to use blending.

However...

It's not working. I used the shader provided by this (http://www.opengl.org/wiki/Transparency_Sorting) page and many variants constructed from other tutorials, even some blatant copy & pastes. Still, discard doesn't seem to work at all. As I understand, discard should literally cut out holes in the quads where there's alpha on the textures, but it doesn't. I even tried to discard any fragment that has a green value greater than 0, the "discard" command does nothing. I'm really tearing my hair out over this because not only would it solve my problem with blending, it would remove alpha fragments from the depth buffer and make shadow mapping possible.

Here is the problem:

And here's what it should look like (accept with depth testing):

My questions are: is there ultimately a better approach to transparency sorting that will allow for shadow mapping in the future? Am I misinterpreting the use of the "discard" command? If the latter, how can I properly use it to achieve transparency sorting with out the obvious front-to-back procedure?

Thanks for reading, and sorry for the long post! I just don't understand what to do, and tutorials don't actually come out and explain the steps to solving this.

If I apply textures in my Java program do fragments take on the texel's colour, or do I have to re-map textures in the shader? Because maybe it's determining colours before the textures have been applied, as if they were on a solid white plane?

EDIT: It's getting late here, I'm going in a few minutes, I'll check back tomorrow, and thanks for all the quick replies! I'll have to ask my programming teacher about this, it appears as though "discard" should be working properly, so I'm unsure as to what I should do next.

The shader is a possible elegant solution to the problem that would also allow for shadow mapping that includes the alpha in textures. Also, if I could avoid the heavy process of manually sorting with a fast program that runs on the GPU it'd save a lot time and processing power.

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org