Jump to content
  • Advertisement
Sign in to follow this  
akhin

GLSL Screen Space Position

This topic is 2451 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 all ,

I need to know the GLSL equivalent of HLSL VPOS semantics , which gives you screen space position
as normalised ( in range of 0-1 and 0-1 for both dimensions ) .

I checked gl_FragCoord but I dont think it is normalised. Could you advise about porting VPOS to GLSL ?

many thanks in advance

Share this post


Link to post
Share on other sites
Advertisement
Don't know anything about DX side, but at OGL:

--------------------------
gl_FragCoord: http://www.opengl.or...l_FragCoord.xml

--------------------------
Output from vertex shader is expected (well, technically, you can do whatever monkey business after that too - in geometry shader for example) to be in Clip Coordinates (CC). CC /= CC.w gives Normalized Device Coordinates (NDC).

NDC coordinates are in [-1..1] range.

So,
// vertex shader
vec4 transformedPos = someTransformations(vxPos); // usually just the typical multiplications with modelview and projection matrices.
vec4 NDC = transformedPos / transformedPos.w;
// fragment shader
vec2 normalizedScreenPosAsYouDefined = NDC.xy * 0.5 + 0.5; // 0:0 is bottom left, flip y (ie. 1-y) if you want it to be top-left, which is quite freakish - but you might prefer it coming from DX.

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!