Sign in to follow this  

need help with doing viewport transformation in vertex shader

Recommended Posts


I'm trying to do manual viewport transformation in vertex shader ...

first, i'm setting an identity viewport matrix by doing the following

vp.Width = 2;
vp.Height = -2;
vp.TopLeftX = -1;
vp.TopLeftY = 1;
vp.MaxDepth = 1.0f;
vp.MinDepth = 0.0f;
g_grcCurrentContext->RSSetViewports( 1, &vp );

and then, in vertex shader, after doing world/view/projection transformation, i do the following (given that i want to render into 1024x1024 viewport with 1.0 maxz and 0.0 minz)

OUT.pos.x = OUT.pos.x * 512.0f + 512.0f * OUT.pos.w;
OUT.pos.y = OUT.pos.y * -512.0f + 512.0f * OUT.pos.w;

I can't think of anything else that i need to do to get this working .... i'd appreciate any help, thx

Share this post

Link to post
Share on other sites
The viewport is in pixel coordinates and is used to convert the normalized pixel coordinates from the VS after perspective project into screenspace.

THE VS then shouldn;t need to know anything of the size of the viewport. For a fullscreen effect then the x and Y are in the range -OUT.pos.w to +OUT.pos.w;

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