Sign in to follow this  
akhin

GLSL Screen Space Position

Recommended Posts

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

--------------------------
gl_FragCoord: [url="http://www.opengl.org/sdk/docs/manglsl/xhtml/gl_FragCoord.xml"]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.

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

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