Sign in to follow this  
szpaq234

D3DX9 sprite z sort

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:
[code]D3DPRESENT_PARAMETERS pp;
pp.BackBufferFormat = D3DFMT_A8R8G8B8;
pp.EnableAutoDepthStencil=1;
pp.AutoDepthStencilFormat = D3DFMT_D16;[/code]
[code]g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, 0x0000FF00, 1.0f, 0L );
g_pd3dDevice->BeginScene();
gameRender();
g_pd3dDevice->EndScene();
g_pd3dDevice->Present( NULL, NULL, NULL, NULL ); [/code]
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this