Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question How to make a URP VR portal?

Discussion in 'VR' started by NewMagic-Studio, May 14, 2023.

  1. NewMagic-Studio

    NewMagic-Studio

    Joined:
    Feb 25, 2015
    Posts:
    454
    Hi,
    From what i read about the Render method in builtin you needed to disable the camera https://docs.unity3d.com/ScriptReference/Camera.Render.html, i did the same with RenderSingleCamera for URP but i see the method just executes in case i have the camera component active, i am not sure if having the camera active is fine or can have any problem, cause i am using two rendersinglecamera, one for each eye, but i camera doesn't actually render the objects belonging to the culling mask it has. I am applying to each camera stereo matrix for each eye, like this for left eye currentCamera.GetStereoProjectionMatrix(Camera.StereoscopicEye.Left);. Seems the projection matrix is wrong as if i don't change the camera matrix i can see the objects for each eye but wrong when i see with both eyes
     
  2. NewMagic-Studio

    NewMagic-Studio

    Joined:
    Feb 25, 2015
    Posts:
    454
    I also noticed that objects look nearer than they should be, tried col = tex2D(_LeftTex, UnityStereoScreenSpaceUVAdjust(i.uv, _LeftTex_ST)); in shader instead col = tex2D(_LeftTex, screenUV); using float2 screenUV = i.screenPos.xy / i.screenPos.w; but doesn't work, just show the objects smaller
    Also rotation is wrong, seems camera projectionmatrix is not correct
     
  3. NewMagic-Studio

    NewMagic-Studio

    Joined:
    Feb 25, 2015
    Posts:
    454
    This is my code
    Code (CSharp):
    1.  
    2.     private void OnEnable()
    3.     {
    4.         //UnityEngine.XR.XRSettings.gameViewRenderMode = UnityEngine.XR.GameViewRenderMode.BothEyes;
    5.         RenderPipelineManager.beginCameraRendering += UpdateCurrentCam;
    6.     }
    7.  
    8.     private void OnDisable()
    9.     {
    10.         RenderPipelineManager.beginCameraRendering -= UpdateCurrentCam;
    11.     }
    12.  
    13.     void Start()
    14.     {
    15.         meshRenderer = GetComponent<MeshRenderer>();
    16.     }
    17.  
    18.     void UpdateCurrentCam(ScriptableRenderContext context, Camera currentCamera)
    19.     {
    20.         if (meshRenderer != null && currentCamera.gameObject.name == "PortalCamera")
    21.         {
    22.             currentCamera.projectionMatrix = currentCamera.GetStereoProjectionMatrix(Camera.StereoscopicEye.Left);
    23.             UniversalRenderPipeline.RenderSingleCamera(context, currentCamera);
    24.             meshRenderer.material.SetTexture("_LeftTex", currentCamera.targetTexture);
    25.             currentCamera.projectionMatrix = currentCamera.GetStereoProjectionMatrix(Camera.StereoscopicEye.Right);
    26.             UniversalRenderPipeline.RenderSingleCamera(context, currentCamera);
    27.             meshRenderer.material.SetTexture("_RightTex", currentCamera.targetTexture);
    28.         }
    29.     }
     
  4. NewMagic-Studio

    NewMagic-Studio

    Joined:
    Feb 25, 2015
    Posts:
    454
    upload_2023-5-14_17-37-34.png

    I have seen code from other projects and they use obliquematrix but don't know why, what does obliquematrix? If i transform matrix with obliquematrix and it renders the box column in front of the camera but wrong. I have set the same models for both dimensions but the portal camera renders wrong scale and rotation, i have set the portal camera as child of main camera but render just the culling mask for objects in the other dimension
     

    Attached Files:

    Last edited: May 14, 2023