Esempio n. 1
0
        public override void BeginRecording(RecordingSession session)
        {
            outputWidth  = scSettings.outputWidth;
            outputHeight = scSettings.outputHeight;

            int w, h;

            GameViewSize.GetGameRenderSize(out w, out h);
            if (w != outputWidth || h != outputHeight)
            {
                var size = GameViewSize.SetCustomSize(outputWidth, outputHeight) ?? GameViewSize.AddSize(outputWidth, outputHeight);
                if (GameViewSize.modifiedResolutionCount == 0)
                {
                    GameViewSize.BackupCurrentSize();
                }
                else
                {
                    if (size != GameViewSize.currentSize)
                    {
                        Debug.LogError("Requestion a resultion change while a recorder's input has already requested one! Undefined behaviour.");
                    }
                }
                GameViewSize.modifiedResolutionCount++;
                m_ModifiedResolution = true;
                GameViewSize.SelectSize(size);
            }
        }
Esempio n. 2
0
        protected internal override void BeginRecording(RecordingSession session)
        {
            OutputWidth  = scSettings.OutputWidth;
            OutputHeight = scSettings.OutputHeight;

            int w, h;

            GameViewSize.GetGameRenderSize(out w, out h);
            if (w != OutputWidth || h != OutputHeight)
            {
                var size = GameViewSize.SetCustomSize(OutputWidth, OutputHeight) ?? GameViewSize.AddSize(OutputWidth, OutputHeight);
                if (GameViewSize.modifiedResolutionCount == 0)
                {
                    GameViewSize.BackupCurrentSize();
                }
                else
                {
                    if (size != GameViewSize.currentSize)
                    {
                        Debug.LogError("Requesting a resolution change while a recorder's input has already requested one! Undefined behaviour.");
                    }
                }
                GameViewSize.modifiedResolutionCount++;
                m_ModifiedResolution = true;
                GameViewSize.SelectSize(size);
            }

#if !UNITY_2019_1_OR_NEWER
            // Before 2019.1, we capture synchronously into a Texture2D, so we don't need to create
            // a RenderTexture that is used for reading asynchronously.
            return;
#else
            m_CaptureTexture = new RenderTexture(OutputWidth, OutputHeight, 0, RenderTextureFormat.ARGB32)
            {
                wrapMode = TextureWrapMode.Repeat
            };
            m_CaptureTexture.Create();

            var  movieRecorderSettings = session.settings as MovieRecorderSettings;
            bool needToFlip            = scSettings.FlipFinalOutput;
            if (movieRecorderSettings != null)
            {
                bool encoderAlreadyFlips = movieRecorderSettings.encodersRegistered[movieRecorderSettings.encoderSelected].PerformsVerticalFlip;
                needToFlip &= encoderAlreadyFlips;
            }

            if (needToFlip)
            {
                m_VFlipper = new TextureFlipper(false);
                m_VFlipper.Init(m_CaptureTexture);
                OutputRenderTexture = m_VFlipper.workTexture;
            }
            else
            {
                OutputRenderTexture = m_CaptureTexture;
            }
#endif
        }
        public override void BeginRecording(RecordingSession session)
        {
            switch (scSettings.outputHeight)
            {
            case ImageHeight.Window:
            {
                int screenWidth;
                int screenHeight;

                GameViewSize.GetGameRenderSize(out screenWidth, out screenHeight);
                outputWidth  = screenWidth;
                outputHeight = screenHeight;

                if (scSettings.forceEvenSize)
                {
                    outputWidth  = (outputWidth + 1) & ~1;
                    outputHeight = (outputHeight + 1) & ~1;
                }
                break;
            }

            default:
            {
                outputHeight = (int)scSettings.outputHeight;
                outputWidth  = (int)(outputHeight * AspectRatioHelper.GetRealAspect(scSettings.outputAspect));

                if (scSettings.forceEvenSize)
                {
                    outputWidth  = (outputWidth + 1) & ~1;
                    outputHeight = (outputHeight + 1) & ~1;
                }

                break;
            }
            }

            int w, h;

            GameViewSize.GetGameRenderSize(out w, out h);
            if (w != outputWidth || h != outputHeight)
            {
                var size = GameViewSize.SetCustomSize(outputWidth, outputHeight) ?? GameViewSize.AddSize(outputWidth, outputHeight);
                if (GameViewSize.modifiedResolutionCount == 0)
                {
                    GameViewSize.BackupCurrentSize();
                }
                else
                {
                    if (size != GameViewSize.currentSize)
                    {
                        Debug.LogError("Requestion a resultion change while a recorder's input has already requested one! Undefined behaviour.");
                    }
                }
                GameViewSize.modifiedResolutionCount++;
                m_ModifiedResolution = true;
                GameViewSize.SelectSize(size);
            }
        }
Esempio n. 4
0
        protected internal override void BeginRecording(RecordingSession session)
        {
            OutputWidth  = scSettings.OutputWidth;
            OutputHeight = scSettings.OutputHeight;

            if (OutputWidth <= 0 || OutputHeight <= 0)
            {
                return; // error will be handled by ImageInputSettings.CheckForErrors. Otherwise we get a failure at RenderTexture.GetTemporary()
            }
            int w, h;

            GameViewSize.GetGameRenderSize(out w, out h);
            if (w != OutputWidth || h != OutputHeight)
            {
                var size = GameViewSize.SetCustomSize(OutputWidth, OutputHeight) ?? GameViewSize.AddSize(OutputWidth, OutputHeight);
                if (GameViewSize.modifiedResolutionCount == 0)
                {
                    GameViewSize.BackupCurrentSize();
                }
                else
                {
                    if (size != GameViewSize.currentSize)
                    {
                        Debug.LogError("Requesting a resolution change while a recorder's input has already requested one! Undefined behaviour.");
                    }
                }
                GameViewSize.modifiedResolutionCount++;
                m_ModifiedResolution = true;
                GameViewSize.SelectSize(size);
            }

            // Initialize the temporary texture for forcing opacity
            m_TempCaptureTextureOpaque = RenderTexture.GetTemporary(OutputWidth, OutputHeight);

#if !UNITY_2019_1_OR_NEWER
            // Before 2019.1, we capture synchronously into a Texture2D, so we don't need to create
            // a RenderTexture that is used for reading asynchronously.
            return;
#else
            m_CaptureTexture = new RenderTexture(OutputWidth, OutputHeight, 0, RenderTextureFormat.ARGB32)
            {
                wrapMode = TextureWrapMode.Repeat
            };
            m_CaptureTexture.Create();
            m_CaptureTexture.name = "GameViewInput_mCaptureTexture";

            var  movieRecorderSettings = session.settings as MovieRecorderSettings;
            bool encoderAlreadyFlips   = false;
            if (movieRecorderSettings != null)
            {
                encoderAlreadyFlips = movieRecorderSettings.encodersRegistered[movieRecorderSettings.encoderSelected].PerformsVerticalFlip;
            }

            NeedToFlipVertically = UnityHelpers.NeedToActuallyFlip(false, this, encoderAlreadyFlips);
            OutputRenderTexture  = m_CaptureTexture;
#endif
        }
Esempio n. 5
0
        public override void BeginRecording(RecordingSession session)
        {
            outputWidth  = scSettings.outputWidth;
            outputHeight = scSettings.outputHeight;

            int w, h;

            GameViewSize.GetGameRenderSize(out w, out h);
            if (w != outputWidth || h != outputHeight)
            {
                var size = GameViewSize.SetCustomSize(outputWidth, outputHeight) ?? GameViewSize.AddSize(outputWidth, outputHeight);
                if (GameViewSize.modifiedResolutionCount == 0)
                {
                    GameViewSize.BackupCurrentSize();
                }
                else
                {
                    if (size != GameViewSize.currentSize)
                    {
                        Debug.LogError("Requestion a resultion change while a recorder's input has already requested one! Undefined behaviour.");
                    }
                }
                GameViewSize.modifiedResolutionCount++;
                m_ModifiedResolution = true;
                GameViewSize.SelectSize(size);
            }

#if !UNITY_2019_1_OR_NEWER
            // Before 2019.1, we capture syncrhonously into a Texture2D, so we don't need to create
            // a RenderTexture that is used for reading asynchronously.
            return;
#else
            m_CaptureTexture = new RenderTexture(outputWidth, outputHeight, 0, RenderTextureFormat.ARGB32)
            {
                wrapMode = TextureWrapMode.Repeat
            };
            m_CaptureTexture.Create();

            if (scSettings.flipFinalOutput)
            {
                m_VFlipper = new TextureFlipper(false);
                m_VFlipper.Init(m_CaptureTexture);
                outputRT = m_VFlipper.workTexture;
            }
            else
            {
                outputRT = m_CaptureTexture;
            }
#endif
        }
Esempio n. 6
0
        public override void BeginRecording(RecordingSession session)
        {
            if (cbSettings.flipFinalOutput)
            {
                m_VFlipper = new TextureFlipper();
            }

            if (Options.useCameraCaptureCallbacks)
            {
                m_InputStrategy = new CaptureCallbackInputStrategy(cbSettings.allowTransparency);
            }
            else
            {
                m_InputStrategy = new CameraCommandBufferInputStrategy(cbSettings.allowTransparency);
            }

            switch (cbSettings.source)
            {
            case ImageSource.ActiveCamera:
            case ImageSource.MainCamera:
            case ImageSource.TaggedCamera:
            {
                outputWidth  = cbSettings.outputWidth;
                outputHeight = cbSettings.outputHeight;

                if (cbSettings.outputImageHeight != ImageHeight.Window)
                {
                    var size = GameViewSize.SetCustomSize(outputWidth, outputHeight);
                    if (size == null)
                    {
                        size = GameViewSize.AddSize(outputWidth, outputHeight);
                    }

                    if (GameViewSize.modifiedResolutionCount == 0)
                    {
                        GameViewSize.BackupCurrentSize();
                    }
                    else
                    {
                        if (size != GameViewSize.currentSize)
                        {
                            Debug.LogError("Requesting a resolution change while a recorder's input has already requested one! Undefined behaviour.");
                        }
                    }
                    GameViewSize.modifiedResolutionCount++;
                    m_ModifiedResolution = true;
                    GameViewSize.SelectSize(size);
                }
                break;
            }

            default:
                throw new ArgumentOutOfRangeException();
            }

            if (cbSettings.captureUI)
            {
                var uiGO = new GameObject();
                uiGO.name             = "UICamera";
                uiGO.transform.parent = session.recorderGameObject.transform;

                m_UICamera               = uiGO.AddComponent <Camera>();
                m_UICamera.cullingMask   = 1 << 5;
                m_UICamera.clearFlags    = CameraClearFlags.Depth;
                m_UICamera.renderingPath = RenderingPath.DeferredShading;
                m_UICamera.targetTexture = outputRT;
                m_UICamera.enabled       = false;
            }
        }
Esempio n. 7
0
        /// <inheritdoc/>
        protected internal override void BeginRecording(RecordingSession session)
        {
            var encoderAlreadyFlips = session.settings.EncoderAlreadyFlips();

            NeedToFlipVertically = UnityHelpers.NeedToActuallyFlip(cbSettings.FlipFinalOutput, this, encoderAlreadyFlips);

            if (UnityHelpers.UsingLegacyRP())
            {
                m_InputStrategy = new CameraCommandBufferLegacyInputStrategy(cbSettings.RecordTransparency);
            }
            else
            {
                m_InputStrategy = new CaptureCallbackSRPInputStrategy(cbSettings.RecordTransparency);
            }

            m_InputStrategy.NeedToFlipVertically = NeedToFlipVertically.Value; // update the flag in the input strategy

            switch (cbSettings.Source)
            {
            case ImageSource.ActiveCamera:
            case ImageSource.MainCamera:
            case ImageSource.TaggedCamera:
            {
                OutputWidth  = cbSettings.OutputWidth;
                OutputHeight = cbSettings.OutputHeight;

                if (cbSettings.outputImageHeight != ImageHeight.Window)
                {
                    var size = GameViewSize.SetCustomSize(OutputWidth, OutputHeight);
                    if (size == null)
                    {
                        size = GameViewSize.AddSize(OutputWidth, OutputHeight);
                    }

                    if (GameViewSize.modifiedResolutionCount == 0)
                    {
                        GameViewSize.BackupCurrentSize();
                    }
                    else
                    {
                        if (size != GameViewSize.currentSize)
                        {
                            Debug.LogError($"Requesting a resolution change (to {OutputWidth}x{OutputHeight}) while a recorder's input has already requested one! Undefined behaviour. Count: {GameViewSize.modifiedResolutionCount}");
                        }
                    }
                    GameViewSize.modifiedResolutionCount++;
                    m_ModifiedResolution = true;
                    GameViewSize.SelectSize(size);
                }
                break;
            }

            default:
                throw new ArgumentOutOfRangeException();
            }

            if (cbSettings.CaptureUI)
            {
                var uiGO = new GameObject();
                uiGO.name             = "UICamera";
                uiGO.transform.parent = session.recorderGameObject.transform;

                m_UICamera               = uiGO.AddComponent <Camera>();
                m_UICamera.cullingMask   = 1 << 5;
                m_UICamera.clearFlags    = CameraClearFlags.Depth;
                m_UICamera.renderingPath = RenderingPath.DeferredShading;
                m_UICamera.targetTexture = OutputRenderTexture;
                m_UICamera.enabled       = false;
            }
        }
Esempio n. 8
0
        public override void BeginRecording(RecordingSession session)
        {
            if (cbSettings.flipFinalOutput)
            {
                m_VFlipper = new TextureFlipper();
            }

            m_quad = CreateFullscreenQuad();
            switch (cbSettings.source)
            {
            case ImageSource.ActiveCamera:
            case ImageSource.MainCamera:
            case ImageSource.TaggedCamera:
            {
                switch (cbSettings.outputHeight)
                {
                case ImageHeight.Window:
                {
                    int screenWidth;
                    int screenHeight;
                    GameViewSize.GetGameRenderSize(out screenWidth, out screenHeight);
                    outputWidth  = screenWidth;
                    outputHeight = screenHeight;

                    if (cbSettings.forceEvenSize)
                    {
                        outputWidth  = (outputWidth + 1) & ~1;
                        outputHeight = (outputHeight + 1) & ~1;
                    }

                    break;
                }

                default:
                {
                    outputHeight = (int)cbSettings.outputHeight;
                    outputWidth  = (int)(outputHeight * AspectRatioHelper.GetRealAspect(cbSettings.outputAspect));

                    if (cbSettings.forceEvenSize)
                    {
                        outputWidth  = (outputWidth + 1) & ~1;
                        outputHeight = (outputHeight + 1) & ~1;
                    }

                    var size = GameViewSize.SetCustomSize(outputWidth, outputHeight);
                    if (size == null)
                    {
                        size = GameViewSize.AddSize(outputWidth, outputHeight);
                    }

                    if (GameViewSize.modifiedResolutionCount == 0)
                    {
                        GameViewSize.BackupCurrentSize();
                    }
                    else
                    {
                        if (size != GameViewSize.currentSize)
                        {
                            Debug.LogError("Requestion a resultion change while a recorder's input has already requested one! Undefined behaviour.");
                        }
                    }
                    GameViewSize.modifiedResolutionCount++;
                    m_ModifiedResolution = true;
                    GameViewSize.SelectSize(size);
                    break;
                }
                }
                break;
            }

            default:
                throw new ArgumentOutOfRangeException();
            }

            if (cbSettings.captureUI)
            {
                var uiGO = new GameObject();
                uiGO.name             = "UICamera";
                uiGO.transform.parent = session.recorderGameObject.transform;

                m_UICamera               = uiGO.AddComponent <Camera>();
                m_UICamera.cullingMask   = 1 << 5;
                m_UICamera.clearFlags    = CameraClearFlags.Depth;
                m_UICamera.renderingPath = RenderingPath.DeferredShading;
                m_UICamera.targetTexture = outputRT;
                m_UICamera.enabled       = false;
            }
        }