Question

I have two sprites A and B. A - opaque, Z = 1. B - half-transparent, Z = 0. Draw call order A -> B.

According to MSDN I should use flag D3DXSPRITE_SORT_DEPTH_BACKTOFRONT when drawing transparent sprites of varying depths. Problem is it works vice versa - only with flag D3DXSPRITE_SORT_DEPTH_FRONTTOBACK.

Please explain how depth sorting works in ID3DXSprite and where is Z value growing (I assume from 0 to 1, 1 being most remote from screen).

Was it helpful?

Solution

If you use D3DXSPRITE_SORT_DEPTH_FRONTTOBACK, you'll get the sprites rendered in this order:

Z = 1.0
Z = 0.0

So your opaque sprite is drawn first, then your half-transparent sprite is rendered on top of it. If you didn't expect to see both sprites (as you would with this scenario), then maybe the problem is that your transparent sprite has the wrong Z coordinate - you are drawing it behind the opaque sprite.

I can't at the moment find a link to a specific reference but the fact is that sprites with a lower Z value are drawn behind sprites with a higher value. This is more like the Z-order of windows rather than the context as used for depth testing. Maybe this is because sprites are inherently 2D.

From here, you can read this:

zorder

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top