Exemplo n.º 1
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
        }
Exemplo n.º 2
0
        private Material _matSRGBConversion = null; // a shader for doing linear to sRGB conversion

        protected internal override void BeginRecording(RecordingSession session)
        {
            if (cbSettings.renderTexture == null)
            {
                return; // error will have been triggered in RenderTextureInputSettings.CheckForErrors()
            }
            OutputHeight        = cbSettings.OutputHeight;
            OutputWidth         = cbSettings.OutputWidth;
            OutputRenderTexture = cbSettings.renderTexture;

            var encoderAlreadyFlips = session.settings.EncoderAlreadyFlips();

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

            var requiredColorSpace = ImageRecorderSettings.ColorSpaceType.sRGB_sRGB;

            if (session.settings is ImageRecorderSettings)
            {
                requiredColorSpace = ((ImageRecorderSettings)session.settings).OutputColorSpaceComputed;
            }
            else if (session.settings is MovieRecorderSettings)
            {
                requiredColorSpace = ImageRecorderSettings.ColorSpaceType.sRGB_sRGB;                               // always sRGB
            }
            var renderTextureColorSpace = UnityHelpers.GetColorSpaceType(cbSettings.renderTexture.graphicsFormat); // the color space of the RenderTexture
            var projectColorSpace       = PlayerSettings.colorSpace;

            // Log warnings in unsupported contexts
            if (projectColorSpace == ColorSpace.Gamma)
            {
                if (requiredColorSpace == ImageRecorderSettings.ColorSpaceType.Unclamped_linear_sRGB)
                {
                    Debug.LogWarning($"Gamma color space does not support linear output format. This operation is not supported.");
                }

                if (renderTextureColorSpace != ImageRecorderSettings.ColorSpaceType.Unclamped_linear_sRGB)
                {
                    Debug.LogWarning($"Gamma color space does not support non-linear textures. This operation is not supported.");
                }
            }

            // We convert from linear to sRGB if the project is linear + the source RT is linear + the output color space is sRGB
            m_needToConvertLinearToSRGB = (projectColorSpace == ColorSpace.Linear && renderTextureColorSpace == ImageRecorderSettings.ColorSpaceType.Unclamped_linear_sRGB) && requiredColorSpace == ImageRecorderSettings.ColorSpaceType.sRGB_sRGB;

            // We convert from sRGB to linear if the RT is sRGB (gamma) and the output color space is linear (e.g., linear EXR)
            m_needToConvertSRGBToLinear = renderTextureColorSpace == ImageRecorderSettings.ColorSpaceType.sRGB_sRGB && requiredColorSpace == ImageRecorderSettings.ColorSpaceType.Unclamped_linear_sRGB;

            if (NeedToFlipVertically.Value || m_needToConvertLinearToSRGB || m_needToConvertSRGBToLinear)
            {
                workTexture      = new RenderTexture(OutputRenderTexture);
                workTexture.name = "RenderTextureInput_intermediate";
            }
        }
Exemplo n.º 3
0
        RenderTexture m_TempCaptureTextureVFlip; // A temp RenderTexture for vertical flips

        protected internal override void BeginRecording(RecordingSession session)
        {
            var encoderAlreadyFlips = session.settings.EncoderAlreadyFlips();

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

            OutputWidth  = settings360.OutputWidth;
            OutputHeight = settings360.OutputHeight;

            if (NeedToFlipVertically.Value)
            {
                m_TempCaptureTextureVFlip = RenderTexture.GetTemporary(OutputWidth, OutputHeight);
            }
        }
Exemplo n.º 4
0
        protected internal override void BeginRecording(RecordingSession session)
        {
            superShader      = Shader.Find("Hidden/Volund/BS4SuperShader");
            accumulateShader = Shader.Find("Hidden/BeautyShot/Accumulate");
            normalizeShader  = Shader.Find("Hidden/BeautyShot/Normalize");

            var  movieRecorderSettings = session.settings as MovieRecorderSettings;
            bool encoderAlreadyFlips   = false;

            if (movieRecorderSettings != null)
            {
                encoderAlreadyFlips = movieRecorderSettings.encodersRegistered[movieRecorderSettings.encoderSelected].PerformsVerticalFlip;
            }
            NeedToFlipVertically = UnityHelpers.NeedToActuallyFlip(rtsSettings.FlipFinalOutput, this, encoderAlreadyFlips);

            var requiredColorSpace = ImageRecorderSettings.ColorSpaceType.sRGB_sRGB;

            if (session.settings is ImageRecorderSettings)
            {
                requiredColorSpace = ((ImageRecorderSettings)session.settings).OutputColorSpaceComputed;
            }
            else if (session.settings is MovieRecorderSettings)
            {
                requiredColorSpace = ImageRecorderSettings.ColorSpaceType.sRGB_sRGB; // always sRGB
            }

            var projectColorSpace = PlayerSettings.colorSpace;

            // Log warnings in unsupported contexts
            if (projectColorSpace == ColorSpace.Gamma)
            {
                if (requiredColorSpace == ImageRecorderSettings.ColorSpaceType.Unclamped_linear_sRGB)
                {
                    Debug.LogWarning(
                        $"Gamma color space does not support linear output format. This operation is not supported.");
                }
            }

            // We convert from linear to sRGB if the project is linear + the source RT is linear + the output color space is sRGB
            m_needToConvertLinearToSRGB = projectColorSpace == ColorSpace.Linear && requiredColorSpace == ImageRecorderSettings.ColorSpaceType.sRGB_sRGB;

            // We convert from sRGB to linear if the RT is sRGB (gamma) and the output color space is linear (e.g., linear EXR)
            m_needToConvertSRGBToLinear = projectColorSpace == ColorSpace.Gamma && requiredColorSpace == ImageRecorderSettings.ColorSpaceType.Unclamped_linear_sRGB;

            var h = rtsSettings.OutputHeight;

            // Below here is considered 'void Start()', but we run it for directly "various reasons".
            if (h > rtsSettings.RenderHeight)
            {
                throw new UnityException("Upscaling is not supported! Output dimension must be smaller or equal to render dimension.");
            }

            // Calculate aspect and render/output sizes
            // Clamp size to 16K, which is the min always supported size in d3d11
            // Force output to divisible by two as x264 doesn't approve of odd image dimensions.
            //var aspect = rtsSettings.m_OutputAspect.GetAspect();
            m_renderHeight = Mathf.Min(16 * 1024, Mathf.RoundToInt(rtsSettings.RenderHeight)); //rtsSettings.renderHeight; //m_RenderSize;
            m_renderWidth  = Mathf.Min(16 * 1024, Mathf.RoundToInt(rtsSettings.RenderWidth));

            OutputHeight = h;
            OutputWidth  = rtsSettings.OutputWidth;

            m_superMaterial = new Material(superShader)
            {
                hideFlags = HideFlags.DontSave
            };

            m_accumulateMaterial = new Material(accumulateShader)
            {
                hideFlags = HideFlags.DontSave
            };

            m_normalizeMaterial = new Material(normalizeShader)
            {
                hideFlags = HideFlags.DontSave
            };

            m_renderRT = new RenderTexture(m_renderWidth, m_renderHeight, 24, RenderTextureFormat.DefaultHDR,
                                           RenderTextureReadWrite.Linear)
            {
                wrapMode = TextureWrapMode.Clamp
            };

            for (int i = 0; i < 2; ++i)
            {
                m_accumulateRTs[i] = new RenderTexture(m_renderWidth, m_renderHeight, 0, RenderTextureFormat.DefaultHDR, RenderTextureReadWrite.Linear)
                {
                    wrapMode = TextureWrapMode.Clamp
                };

                m_accumulateRTs[i].Create();
            }

            var rt = new RenderTexture(OutputWidth, OutputHeight, 0, RenderTextureFormat.DefaultHDR, RenderTextureReadWrite.Linear);

            rt.Create();
            OutputRenderTexture = rt;
            m_samples           = new Vector2[(int)rtsSettings.SuperSampling];
            GenerateSamplesMSAA(m_samples, rtsSettings.SuperSampling);

            m_hookedCameras = new List <HookedCamera>();
        }
Exemplo n.º 5
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;
            }
        }