1

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

Demion
  • 857
  • 1
  • 14
  • 27

1 Answers1

2

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

Roger Rowland
  • 25,885
  • 11
  • 72
  • 113
  • It works exactly as you described. But I assumed front to back means first nearest sprites (with less Z value) are rendered than most furthest are renderd (with Z closest to 1). Also MSDN suggests BACKTOFRONT for transparent sprites. – Demion Jan 01 '14 at 14:42
  • @Demion It's also dependent on whether you called `SetWorldViewLH` or `SetWorldViewRH`, which MSDN says you must call before sorting. If you called neither, I don't know what it would use as default. – Roger Rowland Jan 01 '14 at 14:46
  • SetWorldViewLH / RH doesnt change anything if I pass the identity matrix (null) for the world and the view transform. – Demion Jan 01 '14 at 14:52