Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I've been looking at creating some 2D rendering systems in D3D9, basically because I don't like ID3DXSprite. For the output of the vertex shader, what co-ordinate system does the run-time expect vertex co-ordinates in, like homogenous device co-ordinates? And secondly, does the depth of the resulting vertices have any effect except on the culling/depth buffering? I wanted to "reserve" a section of depth for use in 2D drawing, and then have a section for 3D geometry, to ensure that 3D geometry is always behind 2D.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

For the output of the vertex shader, what co-ordinate system does the run-time expect vertex co-ordinates in?

You should output vertices in clip space from the vertex shader (this is generally where things end up after the projection matrix is applied). The hardware will take the output of the vertex shader, perform clipping, and then perform the perspective division by w and continue along the pipeline.

Does the depth of the resulting vertices have any effect except on the culling/depth buffering?

It could also be used in early-Z optimizations, potentially, and possibly a few other things like that. And maybe fixed-function fog, but I don't think anybody uses that any longer anyhow.

So in general, no. You're probably fine trying to reserve a range in the depth buffer for 2D versus 3D from that standpoint, although I suspect it may be a touch cumbersome to give the 3D elements proper depth from the eye to ensure they land in the desired range (it may be easier just to disable the depth test for the 2D elements or clear the depth buffer to the desired "2D far" value after all the 3D elements are rendered, or something, depending on exactly what you need).

The only other thing to be aware of it is the non-linearity of the depth buffer, so you should probably use a much smaller range for the 2D stuff since it will presumably be closer and thus in the more granular region of the buffer.

share|improve this answer
    
So if I wanted to pass in co-ordinates in relative or absolute 2D screen space, how could I output vertices in the appropriate clip space? –  DeadMG May 5 '11 at 15:44
    
You want to send screen space coordinates in to the shader, and avoid having the pipeline screw with them after the shader? If you set w to 1 before you output your vertex, they should still be properly clipped and the perspective divide will no-op, which sounds like it will give you the desired result. The range of the output coordinates in X and Y should be -1 to 1 in this case, so scale accordingly if you're sending actual pixel coordinates in. –  Josh Petrie May 5 '11 at 15:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.