OpenGL Blending & Depth Test für volles 32-Bit Alpha-Blending
Guten Tag,
Ich kämpfe mich gerade mit java und lwjgl (Als Schnittstelle für OpenGL) durch das Darstellen von Texturen in einem 2D Kontext.
Bisher funktioniert alles wunderbar doch nun stieß ich auf ein großes Problem, das korrekte Blenden von Texturen mit Alphakanälen.
Als BlendFunc benutze ich:
Und die DepthFunc ist:
mit einem Viewport Setting von:
Das Ergebnis sieht leider so aus: Anhang 15693
Der Planet hat hierbei eine niedrigere Z-Koordinate als der Sternenhintergrund. Wie man erkennt wird hier nicht korrekt "geblendet" sondern die ankommenden Pixel der Sterne einfach so übernommen ohne eine Umrechnung mit den bereits vorhandenen Pixeln des Planeten.
Ich habe dazu schon ein wenig recherche betrieben und das Internet hat mir folgenden Artikel ausgespuckt:
Zitat
[...]
We enable blending just like everything else. Then we set the equation, and turn off depth buffer writing when drawing transparent objects, since we still want objects behind the translucent shapes to be drawn. This isn't the proper way to blend, but most the time in simple projects it will work fine. Rui Martins Adds: The correct way is to draw all the transparent (with alpha < 1.0) polys after you have drawn the entire scene, and to draw them in reverse depth order (farthest first). This is due to the fact that blending two polygons (1 and 2) in different order gives different results, i.e. (assuming poly 1 is nearest to the viewer, the correct way would be to draw poly 2 first and then poly 1. If you look at it, like in reality, all the light comming from behind these two polys (which are transparent) has to pass poly 2 first and then poly 1 before it reaches the eye of the viewer. You should SORT THE TRANSPARENT POLYGONS BY DEPTH and draw them AFTER THE ENTIRE SCENE HAS BEEN DRAWN, with the DEPTH BUFFER ENABLED, or you will get incorrect results. I know this sometimes is a pain, but this is the correct way to do it.
[...]
...
Das wäre nun ein enormer Aufwand und nach meinem derzeitigen Verständnis der Depth-Funktion auch nicht im Sinne der Sache.
Immerhin soll doch die Depth-Funktion dafür da sein, damit ich mich eben nicht darum kümmern muss die einzelnen Objekte nach ihrer Höhe zu sortieren sondern, dass die Grafikkarte dies übernehmen kann.
Kann mir jemand vielleicht sagen, ob der Artikel recht hat? Oder ob es eine einfachere Alternative dazu gibt?