Archived

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

getting screen coords in a vertex shade

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