ID3DXSprite depth sorting

时光怂恿深爱的人放手 提交于 2019-12-11 13:57:01

问题


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


回答1:


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:



来源:https://stackoverflow.com/questions/20869571/id3dxsprite-depth-sorting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!