Godot Version
Godot Version 4.2.2
Question
Im pretty new to Godot and I am currently implementing a small optical Illusion in VR. For the effect to work I had to project vertecies of my mesh into screenspace and send this data to my fragment shader, where I am using them to calculate a mask in which the effect should be aplied.
I now moved my project over to VR and I learend very Quickly that the UnprojectPosition function of the Camera3D Object does not work properly in Vr. While it does produce a valid looking output it does not seem to be Projected to either eye/view.
I found a function to get a ProjectionMatrix from the XRInterface and what I think is the Inverse of viewmatrix of the Camera.
XRInterface xRInterface = XRServer.PrimaryInterface ;
Rect2 viewport = new Rect2(Vector2.Zero, new Vector2(1920,1832));
leftProjection = xRInterface.GetProjectionForView(0,viewport.Size.X / viewport.Size.Y ,cam.Near,cam.Far);
leftTransform = xRInterface.GetTransformForView(0,xrOrigin.GlobalTransform);
Now my matrix math and knowledge of projection is limited at best but I tried to do my on projection but the data I get from is never quite right.
leftTransform = leftTransform.Inverse();
Projection cameraProjection = new Projection(leftTransform);
Projection viewProjection = projection * cameraProjection;
Vector4 output = new Vector4(vertex.X, vertex.Y,vertex.Z,1);
output = viewProjection * output;
output = output * (1/output.W);
return new Vector2(output.X,output.Y);
Does anyone here know what I am doing wrong ? Any help would be greatly appreciated