Search Unity

Bug Unable to use Camera.SetStereoViewMatrix in instanced mode.

Discussion in 'VR' started by neginfinity, Dec 27, 2021.

  1. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,572
    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:
    Code (csharp):
    1.  
    2. using UnityEngine;
    3.  
    4. public class StereoCamDebug: MonoBehaviour{
    5.     Camera cam;
    6.  
    7.     void Awake(){
    8.         cam = GetComponent<Camera>();
    9.     }
    10.  
    11.     void LateUpdate(){
    12.         if (cam.stereoEnabled){
    13.             setupStereoMatrices();
    14.         }
    15.     }
    16.  
    17.     void setupStereoMatrices(){
    18.         cam.ResetStereoProjectionMatrices();
    19.         cam.ResetStereoViewMatrices();
    20.  
    21.         var leftView = cam.GetStereoViewMatrix(Camera.StereoscopicEye.Left);
    22.         var rightView = cam.GetStereoViewMatrix(Camera.StereoscopicEye.Right);
    23.  
    24.         var leftProj = cam.GetStereoProjectionMatrix(Camera.StereoscopicEye.Left);
    25.         var rightProj = cam.GetStereoProjectionMatrix(Camera.StereoscopicEye.Right);
    26.  
    27.         Debug.Log($"leftView: {leftView}; rightView: {rightView}");
    28.         Debug.Log($"leftProj: {leftProj}; rightProj: {rightProj}");
    29.  
    30.         //cam.SetStereoViewMatrix(Camera.StereoscopicEye.Left, leftView);
    31.         //cam.SetStereoViewMatrix(Camera.StereoscopicEye.Right, rightView);
    32.     }
    33. }
    34.  
    35.  
    The moment I uncomment "cam.SetStereoViewMatrix", I get this:
    upload_2021-12-27_15-55-17.png

    Or
    Code (csharp):
    1.  
    2. leftView: -1.00000    0.00000    0.00000    0.03504
    3. 0.00000    1.00000    0.00001    -0.00001
    4. 0.00000    -0.00001    1.00000    -3.54000
    5. 0.00000    0.00000    0.00000    1.00000
    6. ; rightView: -1.00000    0.00000    0.00000    -0.03504
    7. 0.00000    1.00000    0.00001    -0.00001
    8. 0.00000    -0.00001    1.00000    -3.54000
    9. 0.00000    0.00000    0.00000    1.00000
    10.  
    11. UnityEngine.Debug:Log (object)
    12. StereoCamDebug:setupStereoMatrices () (at Assets/Scripts/StereoCamDebug.cs:26)
    13. StereoCamDebug:LateUpdate () (at Assets/Scripts/StereoCamDebug.cs:12)
    14.  
    15. leftProj: 0.78129    0.00000    0.00000    0.00000
    16. 0.00000    0.75355    0.00000    0.00000
    17. 0.00000    0.00000    -1.00006    -0.06000
    18. 0.00000    0.00000    -1.00000    0.00000
    19. ; rightProj: 0.78129    0.00000    0.00000    0.00000
    20. 0.00000    0.75355    0.00000    0.00000
    21. 0.00000    0.00000    -1.00006    -0.06000
    22. 0.00000    0.00000    -1.00000    0.00000
    23.  
    24. UnityEngine.Debug:Log (object)
    25. StereoCamDebug:setupStereoMatrices () (at Assets/Scripts/StereoCamDebug.cs:27)
    26. StereoCamDebug:LateUpdate () (at Assets/Scripts/StereoCamDebug.cs:12)
    27.  
    28. Can't calculate the eye texture aspect ratio. Culling/Shadows are likely to break.
    29. UnityEngine.GUIUtility:processEvent (int,intptr,bool&)
    30.  
    31. Screen position out of view frustum (screen pos 0.000000, 0.000000, 1000.000000) (Camera rect 0 0 0 0)
    32. UnityEngine.GUIUtility:processEvent (int,intptr,bool&)
    33.  
    34. Screen position out of view frustum (screen pos 0.000000, 0.000000, 1000.000000) (Camera rect 0 0 0 0)
    35. UnityEngine.GUIUtility:processEvent (int,intptr,bool&)
    36.  
    37. Assertion failed on expression: 'std::abs(det) > FLT_MIN'
    38. UnityEngine.GUIUtility:processEvent (int,intptr,bool&)
    39.  
    40. Assertion failed on expression: 'std::abs(det) > FLT_MIN'
    41. UnityEngine.GUIUtility:processEvent (int,intptr,bool&)
    42.  
    43. Assertion failed on expression: 'std::abs(det) > FLT_MIN'
    44. UnityEngine.GUIUtility:processEvent (int,intptr,bool&)
    45.  
    46. Assertion failed on expression: 'std::abs(det) > FLT_MIN'
    47. UnityEngine.GUIUtility:processEvent (int,intptr,bool&)
    48.  
    49. Assertion failed on expression: 'std::abs(det) > FLT_MIN'
    50. UnityEngine.GUIUtility:processEvent (int,intptr,bool&)
    51.  
    52. Assertion failed on expression: 'std::abs(det) > FLT_MIN'
    53. UnityEngine.GUIUtility:processEvent (int,intptr,bool&)
    54.  
    55. Assertion failed on expression: 'std::abs(det) > FLT_MIN'
    56. UnityEngine.GUIUtility:processEvent (int,intptr,bool&)
    57.  
    58. Assertion failed on expression: 'std::abs(det) > FLT_MIN'
    59. UnityEngine.GUIUtility:processEvent (int,intptr,bool&)
    60.  
    61. Screen position out of view frustum (screen pos 0.000000, 0.000000, 1000.000000) (Camera rect 0 0 0 0)
    62. UnityEngine.GUIUtility:processEvent (int,intptr,bool&)
    63.  

    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:
    https://docs.unity3d.com/ScriptReference/Camera.SetStereoViewMatrix.html

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

    There's also this thread:
    https://forum.unity.com/threads/some-weird-issues-w-setstereoviewmatrix.754664/

    But with no solution.
     
    DonCornholio likes this.
  2. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,572
    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.
     
    DonCornholio likes this.