//////////////////////////////////////////////////////////////////////////////// // // Copyright (C) 2007-2020 , Inc. All Rights Reserved. // //////////////////////////////////////////////////////////////////////////////// using UnityEngine; namespace GCSeries.Core.Extensions { public static class CameraExtensions { /// /// Makes this camera's settings match the other camera. /// /// /// /// This will copy all camera variables (field of view, clear flags, /// culling mask, etc.) from the other camera. /// /// Additionally it will copy the other camera's stereo projection /// matrix to this camera's mono/stereo projection matrices and set /// the stereo target eye based on the specified eye. /// /// /// /// The camera to copy settings from. /// /// /// The stereo target eye to copy the projection matrix from. /// public static void CopyFrom( this Camera c, Camera other, Camera.StereoscopicEye eye) { c.CopyFrom(other); c.projectionMatrix = c.GetStereoProjectionMatrix(eye); switch (eye) { case Camera.StereoscopicEye.Left: c.stereoTargetEye = StereoTargetEyeMask.Left; break; case Camera.StereoscopicEye.Right: c.stereoTargetEye = StereoTargetEyeMask.Right; break; } } /// /// Renders the camera to the specified target texture. /// /// /// /// The target texture to render to. /// public static void Render( this Camera c, RenderTexture targetTexture) { RenderTexture originalTargetTexture = c.targetTexture; { c.targetTexture = targetTexture; c.Render(); } c.targetTexture = originalTargetTexture; } /// /// Renders the camera to the specified target texture. /// /// /// /// The specified target eye will determine which projection matrix /// to use when rendering. For example, if the eye is set to /// Camera.StereoscopicEye.Left, the camera will use its left eye /// stereo projection matrix. /// /// /// /// The target texture to render to. /// /// /// The target eye to render the perspective from. /// public static void Render( this Camera c, RenderTexture targetTexture, Camera.StereoscopicEye eye) { Matrix4x4 originalProjectionMatrix = c.projectionMatrix; { c.projectionMatrix = c.GetStereoProjectionMatrix(eye); c.Render(targetTexture); } c.projectionMatrix = originalProjectionMatrix; } /// /// Renders the camera to the specified target texture. /// /// /// /// The specified target eye will determine which projection matrix /// to use when rendering. For example, if the eye is set to /// Camera.StereoscopicEye.Left, the camera will use its left eye /// stereo projection matrix. /// /// Additionally, the specified pose corresponds to the desired world /// pose to render the camera perspective from. /// /// /// /// The target texture to render to. /// /// /// The target eye to render the perspective from. /// /// /// The world pose to render the perspective from. /// public static void Render( this Camera c, RenderTexture targetTexture, Camera.StereoscopicEye eye, Pose pose) { Pose originalPose = c.transform.ToPose(); { c.transform.SetPose(pose); c.Render(targetTexture, eye); } c.transform.SetPose(originalPose); } } }