I have this code I use to convert a point relative to the camera into a screen coordinate (each axes between 0 and 1, like a texture coordinate):
vec3 CameraPositionToScreenCoord(in vec3 position)
{
float aspect = BufferSize.x / BufferSize.y;
position.x /= position.z / CameraZoom;
position.y /= -position.z / CameraZoom;
position.x /= 2.0f * aspect;
position.y /= 2.0f;
position.xy += 0.5f;
return position;
}
This only works with an orthographic matrix, and as I understand it some VR headsets use funny sheared projection matrices. However, if I do a matrix multiplication of the position times the projection matrix, the results don't seem to be mapped to the screen correctly.
Here is the coordinate visualized using my code above:
![](https://uploads.gamedev.net/forums/monthly_2022_10/fb558a5ae0f3410abce3150c11f27d55.Image5.jpg)
Here is the result if I multiply the position by the projection matrix, just like in the vertex shader:
![](https://uploads.gamedev.net/forums/monthly_2022_10/e1d576c6b3984683bf49b4358adf1995.image6.jpg)
What am I missing here?