zed-ar-headfree-passthrough/Assets/ZED/SDK/Helpers/Scripts/MR/ZEDMirror.cs

46 lines
No EOL
1.5 KiB
C#

//======= Copyright (c) Stereolabs Corporation, All rights reserved. ===============
using UnityEngine;
/// <summary>
/// In AR mode, displays a full-screen, non-timewarped view of the scene for the editor's Game window.
/// Replaces Unity's default behavior of replicating the left eye view directly,
/// which would otherwise have black borders and move around when the headset moves because of
/// latency compensation.
/// ZEDManager creates a hidden camera with this script attached when in AR mode (see ZEDManager.CreateMirror()).
/// </summary>
public class ZEDMirror : MonoBehaviour
{
/// <summary>
/// The scene's ZEDManager component, for getting the texture overlay.
/// </summary>
public ZEDManager manager;
/// <summary>
/// Reference to the ZEDRenderingPlane that renders the left eye, so we can get its target RenderTexture.
/// </summary>
private ZEDRenderingPlane textureOverlayLeft;
void Start()
{
UnityEngine.XR.XRSettings.showDeviceView = false; //Turn off default behavior.
}
private void Update()
{
if (textureOverlayLeft == null && manager != null)
{
textureOverlayLeft = manager.GetLeftCameraTransform().GetComponent<ZEDRenderingPlane>();
}
}
private void OnRenderImage(RenderTexture source, RenderTexture destination)
{
if (textureOverlayLeft != null)
{
//Ignore source. Copy ZEDRenderingPlane's texture as the final image.
Graphics.Blit(textureOverlayLeft.target, destination);
}
}
}