Jump to content
  • Advertisement
Sign in to follow this  

D3DX9 sprite z sort

This topic is 2570 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I figured out how to "z sort" my sprites (ID3DXSprite) so i don't have to worry about which sprites are rendered first. I just change the z value for coordinates. However, i noticed some stupid flaw in this method. Look at the attached image. On the picture on the left, upper fern is rendered later so it covers lower fern, everything is ok. On the right i changed the z coord of the lower fern to make it cover the upper one. At the edges of the fern i can see the ground. Somehow the upper fern is not rendered correctly. Textures are TGA files.
Things that i think are relevant:
pp.BackBufferFormat = D3DFMT_A8R8G8B8;
pp.AutoDepthStencilFormat = D3DFMT_D16;

g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, 0x0000FF00, 1.0f, 0L );
g_pd3dDevice->Present( NULL, NULL, NULL, NULL );

Thank you.

Share this post

Link to post
Share on other sites
The edges of the fern have a non-zero, but still quite low alpha value (E.g. 3 or so). Because the alpha is non-zero, that pixel is written to the z-buffer because it's technically opaque (or semi-opaque). Then the lower Z-value (dark green) fern is drawn, the rasterizer performs a Z-test and sees that the semi-translucent pixels in the light green fern are closer to the camera than the ones being drawn by the dark green fern, so they aren't rendered.

With semi-translucent objects (Objects with alpha other than 0 or 255), you need to render them in back-to-front order for them to display correctly - even if you're using ID3DXSprite.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!