Pretty simple question I think. I need to convert model space coordinates into screen space coordinates for a special shader effect.
I am of course able to just convert them into gl_Position coordinates by just multplyng them with the wold view and projection matrices.
Unfortunately though, thats where I am at my wits end. Since opengl somehow converts normal vertices them into screen coordinates itself, and I need a few extra vertices for a special effect, I have no idea how to achieve this.
So does anybody have any idea how I convert model space coordinates into gl_Fragcoord screen coordinates? I basicly want to be able to give the vertex shader a bunch of model space coordinates and have it spit out where exactly they are on the screen if they were rendered.

  • \$\begingroup\$ Untested, but you should get what you want with a 2d orthographic projection matrix with left=0, right=width, bottom=0, top=height and multiplying a vec4(gl_FragCoord.xyz, 1) with the inverse of the matrix \$\endgroup\$
    – cozmic
    Feb 6, 2017 at 15:12

1 Answer 1


If I understand the problem right, you should look at glm function project:

Map the specified object coordinates (obj.x, obj.y, obj.z) into window coordinates.

But I think that every shader effect do not need a screen space coords. There are must be some way to avoid this, since the operation that converts model space to screen space coords would be very costly.

If you can specify the shader effect you want to implement, I will update the post.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .