OpenVR Rendering Upside Down

I’ve been making great strides with MonoGame and I’ve recently started my plunge into VR via the OpenVR. I’m dangerous close to it working 100% thanks to examples from Jjagg. However, it’s rendering to the headset Upside down and reversed! While I’ve not found anything obviously wrong my ‘assumption’ was it’s something to do with my matrix or the conversion of it. I’m using these functions to convert the OpenVR matrix for rendering:

public static Matrix ToMg(this HmdMatrix34_t mat) {
        var m = new Matrix(
            mat.m0, mat.m4, mat.m8, 0.0f,
            mat.m1, mat.m5, mat.m9, 0.0f,
            mat.m2, mat.m6, mat.m10, 0.0f,
            mat.m3, mat.m7, mat.m11, 1.0f);

        return m;
    }

    public static Matrix ToMg(this HmdMatrix44_t mat) {
        var m = new Matrix(
            mat.m0, mat.m4, mat.m8, mat.m12,
            mat.m1, mat.m5, mat.m9, mat.m13,
            mat.m2, mat.m6, mat.m10, mat.m14,
            mat.m3, mat.m7, mat.m11, mat.m15);

        return m;
    }

I know that OpenVR returns Left Handed matrix but I admit I’m lost on how that converts.

Anyone run into this or have some insight? Thanks gang!

David

Hey David, I think the issue is not with the conversion to MG matrices, but maybe with matrix multiplication order. Could you include the part where matrices are multiplied?

Yep totally fair! I’m just trying to find the missing link… Another tid bit is that text rendered to the screen is upside down as well. So I feel like the issue is in-between the eye rendering and it being copied to the headset.

        var view = Matrix.CreateLookAt(camera.Position, camera.Target, camera.Up);
        var forward = Vector3.TransformNormal(camera.Forward, Matrix.Invert(hmd * eyeMatrix));
        DrawToTarget(forward, projection, view * hmd * eyeMatrix);

In fact if I run the VR sample code and simply draw text to the left and right RenderTargets they are upside down as well. So even in the base code it’s flipped. These Matrix really mess with me I admit.

I vaguely remember running into this issue… If I remember correctly, this was related to the the texture UV settings.

Are you using DirectX or OpenGL?

These are the UV settings I ended up settling on that worked for me:

DirectX

        uMin = 0
        uMax = 1
        vMin = 0
        vMax = 1

OpenGL

        uMin = 0
        uMax = 1
        vMin = 1
        vMax = 0

I’m just now getting back to this (yes it’s been a bit). I’m on DirectX and I will give that a try.