Unable to use Camera.SetStereoViewMatrix in instanced mode.

,

I’ve been trying to implement a VR mirror and I’m not exactly seeing a way to get it to work, because calling
SetStereoViewMatrix breaks rendering.

Basically, consider following script:

using UnityEngine;

public class StereoCamDebug: MonoBehaviour{
    Camera cam;

    void Awake(){
        cam = GetComponent<Camera>();
    }

    void LateUpdate(){
        if (cam.stereoEnabled){
            setupStereoMatrices();
        }
    }

    void setupStereoMatrices(){
        cam.ResetStereoProjectionMatrices();
        cam.ResetStereoViewMatrices();

        var leftView = cam.GetStereoViewMatrix(Camera.StereoscopicEye.Left);
        var rightView = cam.GetStereoViewMatrix(Camera.StereoscopicEye.Right);

        var leftProj = cam.GetStereoProjectionMatrix(Camera.StereoscopicEye.Left);
        var rightProj = cam.GetStereoProjectionMatrix(Camera.StereoscopicEye.Right);

        Debug.Log($"leftView: {leftView}; rightView: {rightView}");
        Debug.Log($"leftProj: {leftProj}; rightProj: {rightProj}");

        //cam.SetStereoViewMatrix(Camera.StereoscopicEye.Left, leftView);
        //cam.SetStereoViewMatrix(Camera.StereoscopicEye.Right, rightView);
    }
}

The moment I uncomment “cam.SetStereoViewMatrix”, I get this:

Or

leftView: -1.00000    0.00000    0.00000    0.03504
0.00000    1.00000    0.00001    -0.00001
0.00000    -0.00001    1.00000    -3.54000
0.00000    0.00000    0.00000    1.00000
; rightView: -1.00000    0.00000    0.00000    -0.03504
0.00000    1.00000    0.00001    -0.00001
0.00000    -0.00001    1.00000    -3.54000
0.00000    0.00000    0.00000    1.00000

UnityEngine.Debug:Log (object)
StereoCamDebug:setupStereoMatrices () (at Assets/Scripts/StereoCamDebug.cs:26)
StereoCamDebug:LateUpdate () (at Assets/Scripts/StereoCamDebug.cs:12)

leftProj: 0.78129    0.00000    0.00000    0.00000
0.00000    0.75355    0.00000    0.00000
0.00000    0.00000    -1.00006    -0.06000
0.00000    0.00000    -1.00000    0.00000
; rightProj: 0.78129    0.00000    0.00000    0.00000
0.00000    0.75355    0.00000    0.00000
0.00000    0.00000    -1.00006    -0.06000
0.00000    0.00000    -1.00000    0.00000

UnityEngine.Debug:Log (object)
StereoCamDebug:setupStereoMatrices () (at Assets/Scripts/StereoCamDebug.cs:27)
StereoCamDebug:LateUpdate () (at Assets/Scripts/StereoCamDebug.cs:12)

Can't calculate the eye texture aspect ratio. Culling/Shadows are likely to break.
UnityEngine.GUIUtility:processEvent (int,intptr,bool&)

Screen position out of view frustum (screen pos 0.000000, 0.000000, 1000.000000) (Camera rect 0 0 0 0)
UnityEngine.GUIUtility:processEvent (int,intptr,bool&)

Screen position out of view frustum (screen pos 0.000000, 0.000000, 1000.000000) (Camera rect 0 0 0 0)
UnityEngine.GUIUtility:processEvent (int,intptr,bool&)

Assertion failed on expression: 'std::abs(det) > FLT_MIN'
UnityEngine.GUIUtility:processEvent (int,intptr,bool&)

Assertion failed on expression: 'std::abs(det) > FLT_MIN'
UnityEngine.GUIUtility:processEvent (int,intptr,bool&)

Assertion failed on expression: 'std::abs(det) > FLT_MIN'
UnityEngine.GUIUtility:processEvent (int,intptr,bool&)

Assertion failed on expression: 'std::abs(det) > FLT_MIN'
UnityEngine.GUIUtility:processEvent (int,intptr,bool&)

Assertion failed on expression: 'std::abs(det) > FLT_MIN'
UnityEngine.GUIUtility:processEvent (int,intptr,bool&)

Assertion failed on expression: 'std::abs(det) > FLT_MIN'
UnityEngine.GUIUtility:processEvent (int,intptr,bool&)

Assertion failed on expression: 'std::abs(det) > FLT_MIN'
UnityEngine.GUIUtility:processEvent (int,intptr,bool&)

Assertion failed on expression: 'std::abs(det) > FLT_MIN'
UnityEngine.GUIUtility:processEvent (int,intptr,bool&)

Screen position out of view frustum (screen pos 0.000000, 0.000000, 1000.000000) (Camera rect 0 0 0 0)
UnityEngine.GUIUtility:processEvent (int,intptr,bool&)

Meaning I can’t set any matrices, so that effectively kills my attempt to setup mirror camera.

This is on unity 2021.2.5f1 .

How can I deal with this? I’d expect matrices to be compatible since they’re taken from the camera itself.

By the way, the unity example from here also doens’t function:

So, how can I deal with this? @bgolus , @mabulous , maybe one of you would know?

There’s also this thread:

But with no solution.

1 Like

I’ve received no advice regarding this issue, and I’ve found no way to work around it. I’m marking this as a bug.

1 Like