Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenGL depth sorting

I'm doing basic object transparency using depth sort. As depth i use distance (squared) from camera to every center of model's triangles, which i calculate as {(x1+x2+x3)/3, (y1+y2+y3)/3, (z1+z2+z3)/3}. Although result is almost fine, but there are some mistakes.

monkey head without sorting no sorting

with sorting sorting

Is there anything i can do about those errors?

like image 633
spacevillain Avatar asked Nov 29 '10 16:11

spacevillain


2 Answers

There is no way to sort the triangles in a perfect way. Look at the examples at end of the Transparency Sorting article on opengl.org wiki.

@kos: Give a look at Order Independent Transparency with Dual Depth Peeling and Alpha to Coverage.

like image 70
tibur Avatar answered Oct 10 '22 10:10

tibur


Unless you have screen-aligned particles, sorting arbitrary triangles is really quite difficult. For a perfect result you have to start splitting triangles.

As @tibur says, you can get away with some simple approximations but order-independent transparency (OIT) is a decent solution too. It does however require OpenGL 3 era graphics features. I have an implementation available on github, which shows some ways to make exact OIT quite fast.

It's worth taking a look at "adaptive transparency", "multi-layer alpha blending" and "hybrid transparency". These are fast approximate solutions but give very good results for common scenes.


Some similar questions...

  • three.js point clouds, BufferGeometry and incorrect transparency
  • glPoint Alpha Blending issue
  • OpenGL transparency not working properly
  • Model with transparency
  • OpenGL transparency/translucency
  • How do I make textures transparent in OpenGL?
  • OpenGL Alpha blending and object independent transparency
  • Transperency in modern games and other 3D applications
  • Why doesn't alpha blending work in ortho?
like image 22
jozxyqk Avatar answered Oct 10 '22 11:10

jozxyqk