Sign in to follow this  

GLSL Screen Space Position

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
Don't know anything about DX side, but at OGL:

gl_FragCoord: [url=""]http://www.opengl.or...l_FragCoord.xml[/url]

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.

// 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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this