plotting isosurfaces in 2013 and 2014 versions

1 view (last 30 days)
Hi, I noticed the behaviour of isosurface is different in versions 2013a and 2014b (see image below). I wonder if I could some help to get the same sharper effect in the 2014b version. Thank you!

Accepted Answer

Mike Garrity
Mike Garrity on 1 Apr 2015
Ah, I've been meaning to write up something about this for the graphics blog.
Transparency and the depth sorting technique that OpenGL uses (known as Z-buffer) interact in a very interesting way. To correctly draw multiple layers of transparent objects (as you have here) you need to draw each layer in back to front order. That's because the "over operator" (the blend function we use for transparent objects) doesn't commute. That means that order matters. The Z-buffer depth sorting technique can't help here. That's because all it can do is determine which layer is closest. It can't tell us anything about the order of all of the other layers. Therefore we need to use a different sorting technique.
In earlier versions of MATLAB, we sorted the transparent objects using a technique called "object". This simply meant that we sorted objects based the distance to their centroids. That didn't work well for isosurface, because it dumps all of the triangles into a single object. This meant that the object sort method couldn't do anything with it. As a result, we simply drew the triangles in the order in which they were created. This resulted in the picture on the left.
Starting in R2014b we overhauled the sorting technique that we use for transparent objects. The new technique (known as "depth peeling") actually sorts the layers separately for each pixel, rather than for each object. This means that in R2014b, we're actually drawing transparent isosurfaces correctly. That results in the picture on the right above.
We didn't leave a good way to switch back to the incorrect sorting of previous versions because it was actually getting the wrong answer. There actually are a couple of ways in which you can get it if you really, really want it.
First, there is a new property on the axes in R2014b named "SortMethod". You can set this to "childorder" to disable all depth sorting. Note that this will also stop sorting your opaque objects too though!
Second, the new depth peeling technique depends on a feature in relatively new graphics cards called a "programmable shader". This means that you will still get the picture on the left if you run MATLAB on a really low-end card, or a really old card. You can also get that result if you start MATLAB with the "-softwareopengl" flag, because our software OpenGL implementation doesn't yet support this feature.
Does that make sense?
  1 Comment
Bi Bu
Bi Bu on 2 Apr 2015
Thanks so much for the fast reply and in-depth explanation! All working good now.

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!