From fd45fe117171ced780d82f4e3fbca6ed96bb5816 Mon Sep 17 00:00:00 2001 From: artum Date: Thu, 16 Jun 2022 19:21:26 +0200 Subject: [PATCH] Enable stereo in post credits scene (#509) --- NomaiVR/EffectFixes/PostCreditsFix.cs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/NomaiVR/EffectFixes/PostCreditsFix.cs b/NomaiVR/EffectFixes/PostCreditsFix.cs index 9c84e1c8..c0379892 100644 --- a/NomaiVR/EffectFixes/PostCreditsFix.cs +++ b/NomaiVR/EffectFixes/PostCreditsFix.cs @@ -13,10 +13,14 @@ public class Behaviour : MonoBehaviour private Transform screenTransform; private Transform cameraTransform; private Transform offsetTransform; + private Camera originalCamera; + private Camera vrCamera; + private RenderTexture stereoTexture; internal void Start() { cameraTransform = Instantiate(AssetLoader.PostCreditsPrefab).transform; + vrCamera = cameraTransform.GetComponentInChildren(); screenTransform = cameraTransform.GetChild(0); screenTransform.parent = null; @@ -30,13 +34,19 @@ internal void Start() cameraTransform.localPosition = Vector3.zero; cameraTransform.localRotation = Quaternion.identity; - var originalCamera = Camera.main; + originalCamera = Camera.main; originalCamera.tag = "Untagged"; originalCamera.cullingMask &= ~(1 << LayerMask.NameToLayer("UNUSED")); originalCamera.transform.position = new Vector3(1075, 505, -765); originalCamera.transform.rotation = Quaternion.identity; originalCamera.rect.Set(0, 0, 1, 0.5f); originalCamera.targetTexture = AssetLoader.PostCreditsRenderTexture; + originalCamera.enabled = false; + + stereoTexture = new RenderTexture(AssetLoader.PostCreditsRenderTexture.descriptor); + stereoTexture.Create(); + + Camera.onPreRender += OnCameraPreRender; } internal void Update() @@ -49,6 +59,19 @@ internal void Update() { offsetTransform.localRotation *= Quaternion.Euler(0, signedCameraAngle, 0); } + + originalCamera.targetTexture = AssetLoader.PostCreditsRenderTexture; + originalCamera.Render(); + originalCamera.transform.position += Vector3.right * 10; + originalCamera.targetTexture = stereoTexture; + originalCamera.Render(); + } + + void OnCameraPreRender(Camera camera) + { + if (camera != vrCamera || camera.stereoActiveEye != Camera.MonoOrStereoscopicEye.Right) + return; + Graphics.CopyTexture(stereoTexture, AssetLoader.PostCreditsRenderTexture); } } }