NDC to Screenspace

Kinda a semi-newbie question,
Can someone please help me understand this:

vec2 screen_space(vec4 vertex)
    return (clamp(vertex.xy, -1.3, 1.3)+1) * (screen_size*0.5);

Its from here: http://codeflow.org/entries/2010/nov/07/opengl-4-tessellation/

I could be wrong but it seems to convert OpenGL screen space positions into application screen positions. When points are rendered they are transformed into the range of (-1 -> 1) for x and y positions. If your screen position is (0;0) then your opengl position is (-1;-1) and if your max resolution is (800;600) then the opengl position will be (1;1) at that point. Basically what the function is doing is taking the opengl co-ordinate in the shader and converts it into a screen space co-ordinate as the function is named.

Ok thanks, but why does it clamp it to some strange values. Makes no sense.

Could be to reduce artifacts caused by the shader, you can test it out by comparing (-1;1) with (-1.3;1.3) clamping to identify the need to clamp over the border of the screen.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.