Skip to content

Commit

Permalink
Enable stereo in post credits scene (#509)
Browse files Browse the repository at this point in the history
  • Loading branch information
artumino authored Jun 16, 2022
1 parent c2bfd28 commit fd45fe1
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion NomaiVR/EffectFixes/PostCreditsFix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Camera>();
screenTransform = cameraTransform.GetChild(0);
screenTransform.parent = null;

Expand All @@ -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()
Expand All @@ -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);
}
}
}
Expand Down

0 comments on commit fd45fe1

Please sign in to comment.