DX11 ZSort/Order with Alpha only works for Shaders not Quad etc

I can’t tell you you how much pain trying to use alpha textures in DX11 has caused me over the years. It seemed to work sometimes, then not others; I usually was able to work around it when it didn’t by using an Add instead of Blend, but finally came up against a case where that was innapropriate.

So I started trying different test cases, and found different results depending on what the alpha texture was being applied to. In the attached patch, I send the layer(s) from a Quad node, a Constant node, and two different uses of the Sprite node into ZSort. As can be seen, only the Constant node provides the expected result.

The Sprite node when used by sending multiple XYZ points in with one transform does not work, but when a spread of Transforms are sent into it, the depth does sort OK, but the color spread is not applied. Oddly the Quad with a spread of transforms does not sort while Sprite does.

So now I can see why it seemed to work sometimes and not others over the years - the behavior over nodes is inconsistent. Seems like DX11 for beta is a dead project, so I’m posting this here to perhaps help someone else who has been bashing their head against their keyboard over this…

DepthSortBugs.v4p (24.7 KB)


1 Like

Well the proper depth is only possible for solid objects, semi transparent object would override depth, basically if you draw something semi transparent you have to disable depth buffer on that render pass…
Then, sprite and quad uses some optimization under the hood, it takes all your transforms, converts them to buffers and do a single render call using instancing, with instancing i think isn’t possible for elements being transparent to each other… And normal shader doesn’t do any optimization, that’s why result is different…

To sort that out there are few options, fastest and mostly used is Alpha to Coverage, you can enabled that on Blend Advanced, gpu would try to convert transparency in to solid to enable depth. Second options is ColorAndDepth node, you build depth and color for everything that isn’t transparent on first pass then apply semitransparent stuff on top, this tech used to draw glass and windows on top of solids…

There you go
DepthSortBugs1.v4p (31.6 KB)

1 Like

Thanks @antokhio, that does work. I figured there was some external way to do it figuring distance from the camera, it’s just not something one has to do in other packages.

Interestingly, by turning on debug timing, Sprite is actually a lot slower in that example than Quad or Constant! Even if you up the spread count to 1000 it is still way more efficient. I expect it gets more efficient with lots of objects, but for now I’m switching over to using Constant, and will evaluate if going this route with Sprite is more efficient for the numbers of things I use in each case.

Thanks again!

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.