0

I'm writing a little 3D engine. I've just added the alpha blending functionality in my program and I wonder one thing: do I have to sort all the primitives compared with the camera?)

Let's take a simple example : I have a scene composed by 1 skybox and 1 tree with alpha blended leafs!

Here's a screenshot of a such scene:

enter image description here

Until here all seems to be correct concerning the alpha blending of the leafs relative to each others.

But if we get closer...

enter image description here

... we can see there is a little trouble on the top right of the image (the area around the leaf forms a quad).

enter image description here

I think this bug comes from the fact these two quads (primitives) should have been rendered later than the ones in back.

What do you think about my supposition ?

PS: I want to precise all the geometry concerning the leafs is rendered in just one draw call.

But if I'm right it would means when I need to render an alpha blended mesh like this tree I need update my VBO each time my camera is moving by sorting all the primitives (triangles or quads) from the camera's point of view. So the primitives in back should be rendered in first...

What do you think of my idea?

genpfault
  • 51,148
  • 11
  • 85
  • 139
user1364743
  • 5,283
  • 6
  • 51
  • 90
  • 3
    Yes, this is the typicall issue if you combinde depth test with blending. There are some advanced approaches on trying to get the GPU do the work for you, the keyword to search for is "order independent transparency" (OIT). However, in your case, it looks like you don't need semi-transparency at all, you might get away with the alpha test/some conditional `discard` in the fragment shader. – derhass May 07 '15 at 18:49
  • Yes thank you. I did not test using this instruction. I've just replaced it in my fragment shader and it works! So if I understood what you say, I would have to sort my primitives if my leafs (in my example ) was semi-transparent (to have the best rendering of course) ! Thanks for your help! I'll take a look to OIT! Bye. – user1364743 May 07 '15 at 19:05
  • 2
    Particularly if you want to use MSAA anyway, enabling alpha-to-coverage is another simple option for order independent transparency. It's somewhat limited, but might work well in this case. My answer to this question attempts to give an overview of some common transparency rendering methods: http://stackoverflow.com/questions/23280692/opengl-es2-alpha-test-problems. – Reto Koradi May 08 '15 at 04:45

0 Answers0