コード例 #1
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;

            m_needToFlipVertically = cbSettings.FlipFinalOutput; // whether or not the recorder settings have the flip box checked
            var movieRecorderSettings = session.settings as MovieRecorderSettings;

            if (movieRecorderSettings != null)
            {
                bool encoderAlreadyFlips = movieRecorderSettings.encodersRegistered[movieRecorderSettings.encoderSelected].PerformsVerticalFlip;
                m_needToFlipVertically = m_needToFlipVertically ? encoderAlreadyFlips : !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 (m_needToFlipVertically || m_needToConvertLinearToSRGB || m_needToConvertSRGBToLinear)
            {
                workTexture      = new RenderTexture(OutputRenderTexture);
                workTexture.name = "RenderTextureInput_intermediate";
            }
        }