# Convert Eye Coords to Window Coords in GLSL?

Hey guys, I don’t know a lot about the projection and coordinate systems in OpenGL, but I’m trying to implement a light scattering (god rays) shader via mod that allows GLSL into a game. The mod can tell me a uniform float called sunVector which is the position of the sun (area from where the scattering will come from) in eye coordinates. What the shader I’m implementing needs are window coordinates.
So my question is, how can I convert them? I know I need to modify it by the projection matrix or something, but how?
I’m a real noob at this right now; this isn’t my type of programming . . . thanks!

It should be simple first multiply the value by the projection matrix to get it into clipspace.Do the perspective division. Then scale and translate the value by half screen screen to obtain the screenspace value. So its something like this,

//esPos is eye space position
//P is the projection matrix
csPos = P*esPos;
csPos.xyz/=csPos.w; //prespective division
winX = (1+csPos.x)* half_screen_width;
winY = (1+csPos.y)* half_screen_height;
winZ = csPos.z; //clipspace z is in 0-1 range with 0 at the near
//clip plane and 1 at the far clip plane.

Ah, so which one of those would be floats and which matrices?

only P is the projection matrix the rest are vec3.

Hopefully this helps, i had the same question awhile ago and was working with transforming window coords to clip space and clip space to window coords. (Clip-space is where you are after your perspective and transformation vertex, or in my case quaternion, calculations are)