Advertisement Jump to content
Sign in to follow this  
JoshuaWaring

OpenGL OpenGL Screen Transformations

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

If I pass vertices to a shader between -1 and 1, with 0 being the middle of the screen.

would I be able to use those values without any modifications?

Share this post


Link to post
Share on other sites
Advertisement

Yes

Those are the limits in the Normalized Device Coordinates system (NDC)

 

If you also want UV coordinates for this, simply do:

out_texcoord = (in_vertex + vec2(1.0)) * 0.5;

 

note that this is only for a fullscreen quad

for anything else you will want to provide UVs as well

Share this post


Link to post
Share on other sites

Yes, but you must make sure that the w component of the vertex position is 1, because the perspective divide will still occur after the vertex shader. 

Share this post


Link to post
Share on other sites

Thank you :)

 

What are the UV quads relative to?
If I provided a quad's verticies between -1 and 1 couldn't I use them again for the UV if it's relative to the screen

or -1 and 1 if it's relative to the quad.

Share this post


Link to post
Share on other sites

Thank you smile.png

 

What are the UV quads relative to?
If I provided a quad's verticies between -1 and 1 couldn't I use them again for the UV if it's relative to the screen

or -1 and 1 if it's relative to the quad.

UVs are texture coordinates, between 0 and 1, unless the texture repeats, always smile.png

Of course there are lots of variations on how people specify these coordinates due to eg. texture atlasing.

But, what I did in my example was simply scaling the vertex coordinates [-1, 1] to [0, 1] so that you could re-use the vertex coordinates for a fullscreen quad. Those UVs represent the entire texture.

 

To answer your question - yes, but you still need to rescale the UVs to match the [0, 1] scale of texture coordinates.

Edited by Kaptein

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!