public override void BeginRecording(RecordingSession session)
        {
            superShader      = Shader.Find("Hidden/Volund/BS4SuperShader");
            accumulateShader = Shader.Find("Hidden/BeautyShot/Accumulate");
            normalizeShader  = Shader.Find("Hidden/BeautyShot/Normalize");

            if (rtsSettings.flipFinalOutput)
            {
                m_VFlipper = new TextureFlipper();
            }

            // Below here is considered 'void Start()', but we run it for directly "various reasons".
            if (rtsSettings.outputHeight > rtsSettings.renderSize)
            {
                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 = AspectRatioHelper.GetRealAspect(rtsSettings.outputAspect);

            m_renderHeight = (int)rtsSettings.renderSize;
            m_renderWidth  = Mathf.Min(16 * 1024, Mathf.RoundToInt(m_renderHeight * aspect));
            outputHeight   = (int)rtsSettings.outputHeight;
            outputWidth    = Mathf.Min(16 * 1024, Mathf.RoundToInt(outputHeight * aspect));
            if (rtsSettings.forceEvenSize)
            {
                outputWidth  = (outputWidth + 1) & ~1;
                outputHeight = (outputHeight + 1) & ~1;
            }

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

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

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

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

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

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