10

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?

spacevillain
  • 1,336
  • 1
  • 14
  • 25

3 Answers3

6

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.

tibur
  • 11,531
  • 2
  • 37
  • 39
  • So still there's not a single solution to render arbitrary transparency properly? – Kos Nov 29 '10 at 17:42
  • 1
    @Kos: check http://www.yakiimo3d.com/2010/07/19/dx11-order-independent-transparency/ and http://blog.icare3d.org/2010/07/opengl-40-abuffer-v20-linked-lists-of.html – elmattic Nov 30 '10 at 10:23
3

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...

Community
  • 1
  • 1
jozxyqk
  • 16,424
  • 12
  • 91
  • 180
0

Mathematically speaking, if you know something about the body it could help sorting.

For instance the faces of a cube can be depth sorted by barycenter (face center) alone. If the center of the square face A will be closer than the center of B, B will never have any part in front of A (again, for a cube.)

In fact, for a convex body, faces can be sorted by orientation alone.

adrian O
  • 81
  • 1
  • 3