Sign in to follow this  
chippolot

What does D3D expect as vertex position output?

Recommended Posts

chippolot    122
So... My entire rendering system uses shaders to modify the rendering pipeline. Right now, I'm trying to make a shader that renders UI. It's very simple. You use it on a textured quad and it simply outputs the position (no transforms are preformed on it) and the U,V texture coordinates. I'm testing it on a quad size 1x1 with coordinates (0,0,0). What I thought I would see was a quarter of the quad in the upper lef hand corner of the screen, but what I get is a rectangle in the middle of the screen. Maybe I just don't understand projection space as well as I thought I did, but does the output of a vertex shader not correspond 1 to 1 with screen coordinates? So, if I pass in a position of 0,0,0 into my shader, do no transformations, and output it, does that not end up in the upper left hand corner of the screen?

Share this post


Link to post
Share on other sites
Armadon    1091
What your shader is probably doing is using the transformation pipeline. With this I mean that in your vertex shader you are probably doing something like OUT.position = mul(IN.position, WorldViewProjection), this line will transform vertices from world space to screen space. If you want to work in screen space you will need to use transformed coordinates. This will give you what you are looking for.
Note you will if you are using the vertex declarations the following for the position if you want transformed vertices/coordinates. D3DDECLUSAGE_POSITIONT

I hope this helps.
Take care.

Share this post


Link to post
Share on other sites
chippolot    122
Wait... if I use POSITIONT, won't I actually have to move the physical position of the verticies? I don't want to have to lock and unlock the buffer whenever something moves.

Share this post


Link to post
Share on other sites
jollyjeffers    1570
Quote:
Original post by chippolot
Wait... if I use POSITIONT, won't I actually have to move the physical position of the verticies? I don't want to have to lock and unlock the buffer whenever something moves.

From the aforementioned documentation page, POSITIONT instructs D3D to ignore the VShader; which is functionally equivalent to using D3DFVF_XYZRHW vertices in the fixed-function pipeline.

I've seen code that used a single vertex buffer defined as 4 corners with only texture coordinates (0,0),(1,0),(0,1),(1,1) - and everything else was constructed via the vertex shader and constants that the application passed in (it passed percentage top/left/height/width values). It was quite an elegant solution, but the downside was that it required a large number of draw calls..

hth
Jack

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