Jump to content
  • Advertisement
Sign in to follow this  

need help with doing viewport transformation in vertex shader

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


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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!