Archived

This topic is now archived and is closed to further replies.

Z-Buffer with Transformed Vertices?

This topic is 5126 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

Is it possible to use a Z-buffer with transformed vertices? I''m writing a simple 2D engine, and i wand the sprites drawn to have decreasing Z-values, so that sprites drawn later are drawn over the previous ones. I can''t just draw them in that order, because i sort by texture before rendering, so i might end up drawing some that should be at the front first (sorry, thats a crap explanation ) At the moment, i''ve been setting the Z-coordinate of the vertices to try to get the Z-buffer to use it, but its not. Should i be changing the rhw instead? Will i need to perform my own transformations? I don''t mind doing that. but obviously i''d prefer not to. Cheers, Steve

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Yes it''s possible. Set Z between 0 (minimum Z) and 1 (max Z) and make sure you have enabled Z buffering.

Remember though that to get transparencies and blending correct (real alpha, not alpha testing) you do need to draw the transparent things AFTER all non tranparent things have been drawn.

Share this post


Link to post
Share on other sites
hey while were on the subject is it posable to mix transformed and non-transformed, I tryed for a good while to get my partaly 2d engine to work with bother parts of the old 2d engine and the new 3d one

Share this post


Link to post
Share on other sites
quote:
Original post by Bobboau
hey while were on the subject is it posable to mix transformed and non-transformed, I tryed for a good while to get my partaly 2d engine to work with bother parts of the old 2d engine and the new 3d one


Yes, most PC games that use D3D use [already] transformed vertices (D3DFVF_XYZRHW style vertices) for their 2D HUD and front end elements and untransformed vertices for the 3D stuff.

If your existing engine only uses D3DFVF_XYZRHW style vertices and you''re having problems putting in 3D stuff, make sure your matrices are all set up correctly.

Actually, having at least the projection matrix set up is still advisable when you''re only using D3DFVF_XYZRHW since to clip those kinds of vertices requires back-transformation.


Tip: if the primitives you render that use D3DFVF_XYZRHW style transformed vertices are completely visible on the screen (or the guard band area if your card supports it), then set D3DRS_CLIPPING to FALSE for those primitives. This can improve performance by disabling the back-transformation into clip space mentioned above.

--
Simon O''Connor
3D Game Programmer &
Microsoft DirectX MVP

Share this post


Link to post
Share on other sites