Search Unity

Stereo portal or mirror support with single pass rendering

Discussion in 'AR/VR (XR) Discussion' started by tsgcpp, Oct 1, 2019.

  1. tsgcpp

    tsgcpp

    Joined:
    Aug 5, 2017
    Posts:
    4
    I want to create a stereo portal system or a stereo mirror system with single pass rendering for performances.
    However, I have some troubles stated below:
    • XR camera won't directly render images to stereo render texture created by XRSettings.eyeTextureDesc.
    • XR camera overwrite the position and the rotation by trackings, so It's hard to set the Camera to the mirror position.
    • In Stereo Pass mode, it's unable to set custom eye projection matrices to XR Camera, so creating mirror texture needs one more pass to flip it.
    • It's not easy to get correct eye separation by devices.
    • and so on...
    I have some workaround without single pass rendering but I think they aren't effective implements in XR.
    I hope that freature supports to solve the problems are provided by Unity.
     
  2. tsgcpp

    tsgcpp

    Joined:
    Aug 5, 2017
    Posts:
    4
    Now, I implement them like below:
    • Set camera position by using SetStereoViewMatrix.
    I use SetStereoViewMatrix to disable camera's overwrites by tracking.
    However, in this case, I need to calculate correct eye separation in consideration of device settings updates.

    • Get render results by command buffer.
    Code (CSharp):
    1. renderTexture = new RenderTexture(XRSettings.eyeTextureDesc);
    2.  
    3. CommandBuffer commandBuffer = new CommandBuffer();
    4. // effectMaterial is to flip render texture.
    5. commandBuffer.Blit(BuiltinRenderTextureType.CameraTarget, renderTargetId, effectMaterial);
    6. camera.AddCommandBuffer(CameraEvent.AfterEverything, commandBuffer);
    This implement doesn't prevent the camera from rendering to Screen. so it has a overhead.

    • Exchange left and right textures by shader for mirroring.
    unity_StereoEyeIndex = 1 - i.stereoTargetEyeIndex


    Exchanging textures would have some trouble. For instance, results of left texture and right texture aren't aligned in Y axis.
    When setting the same view matrix to left and right, you can see this.

    Unity 2019-10-01 131729.jpg