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.

  • 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 – cozmic Feb 6 '17 at 15:12
up vote 0 down vote accepted

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.

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.