Jump to content
  • Advertisement


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

andy maddison

getting screen coords in a vertex shade

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

Hi, what is the simplest way to get the screen coordinates of a world space vertex in a vertex shader? Once I''ve transformed my vertex and output oPos, do I then divide x and y by the w coord to get in the range (-1,-1) to (1,1)? And then do a bit of arithmetic to get (0,0) to (1,1). What I''m trying to do is generate texture coords based on screen position. It seems to be almost working. Andy.

Share this post

Link to post
Share on other sites
To get screen position:
Before shader: view * projection
In shader: vector(px,py,pz,1) * matrix

I have never actually checked what values it puts out. What you could try to check it, is set a color to the position as well and color the pixel accordingly. If it goes black to whatever, TL corner to BR then its 0.0 to 1.0. Drop the Z value though for coloring.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!