Пример #1
0
        private void Transparent()
        {
            try { OnPreCapture?.Invoke(); }
            catch (Exception ex) { Logger.LogError(ex); }

            Config.Reload();
            var width       = CaptureWidth.Value;
            var height      = CaptureHeight.Value;
            var downScaling = Downscaling.Value;

            var scaledWidth  = width * downScaling;
            var scaledHeight = height * downScaling;

            var colour = Capture(scaledWidth, scaledHeight, false);

            var ppl = Camera.main.gameObject.GetComponent <PostProcessLayer>();

            ppl.enabled = false;

            var m3D = SceneManager.GetActiveScene().GetRootGameObjects()[0].transform.Find("CustomControl/Map3D/p_ai_mi_createBG00_00").gameObject; //Disable background. Sinful, truly.

            m3D.SetActive(false);

            var mask = Capture(scaledWidth, scaledHeight, true);

            ppl.enabled = true;

            m3D.SetActive(true);

            var alpha = RenderTexture.GetTemporary(scaledWidth, scaledHeight, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default);

            _matComposite.SetTexture("_Overlay", mask);

            Graphics.Blit(colour, alpha, _matComposite);

            RenderTexture.ReleaseTemporary(mask);
            RenderTexture.ReleaseTemporary(colour);

            ScaleTex(ref alpha, width, height, downScaling);

            StartCoroutine(WriteTex(alpha, true));

            try { OnPostCapture?.Invoke(); }
            catch (Exception ex) { Logger.LogError(ex); }
        }
Пример #2
0
        /// <summary>
        /// Capture the screen into a texture based on supplied arguments. Remember to RenderTexture.ReleaseTemporary the texture when done with it.
        /// </summary>
        /// <param name="width">Width of the resulting capture, after downscaling</param>
        /// <param name="height">Height of the resulting capture, after downscaling</param>
        /// <param name="downscaling">How much to oversize and then downscale. 1 for none.</param>
        /// <param name="transparent">Should the capture be transparent</param>
        public RenderTexture Capture(int width, int height, int downscaling, bool transparent)
        {
            try { OnPreCapture?.Invoke(); }
            catch (Exception ex) { Logger.LogError(ex); }

            try
            {
                if (!transparent)
                {
                    return(CaptureOpaque(width, height, downscaling));
                }
                else
                {
                    return(CaptureTransparent(width, height, downscaling));
                }
            }
            finally
            {
                try { OnPostCapture?.Invoke(); }
                catch (Exception ex) { Logger.LogError(ex); }
            }
        }
Пример #3
0
        private void Opaque()
        {
            try { OnPreCapture?.Invoke(); }
            catch (Exception ex) { Logger.LogError(ex); }

            Config.Reload();
            var width       = CaptureWidth.Value;
            var height      = CaptureHeight.Value;
            var downScaling = Downscaling.Value;

            var scaledWidth  = width * downScaling;
            var scaledHeight = height * downScaling;

            var colour = Capture(scaledWidth, scaledHeight, false);

            ScaleTex(ref colour, width, height, downScaling);

            StartCoroutine(WriteTex(colour, false));

            try { OnPostCapture?.Invoke(); }
            catch (Exception ex) { Logger.LogError(ex); }
        }
        private IEnumerator Take360Screenshot(bool in3D)
        {
            try { OnPreCapture?.Invoke(); }
            catch (Exception ex) { Logger.LogError(ex); }

            yield return(new WaitForEndOfFrame());

            if (!in3D)
            {
                yield return(new WaitForEndOfFrame());

                var output  = I360Render.CaptureTex(Resolution360.Value);
                var capture = EncodeToXmpFile(output);

                //var filename = GetUniqueFilename("360");
                var filename = GetUniqueFilename("_360");
                File.WriteAllBytes(filename, capture);

                Logger.Log(ScreenshotMessage.Value ? LogLevel.Message : LogLevel.Info, $"360 screenshot saved to {filename}");

                Destroy(output);
            }
            else
            {
                var targetTr = Camera.main.transform;

                ToggleCameraControllers(targetTr, false);
                Time.timeScale = 0.01f;
                yield return(new WaitForEndOfFrame());

                targetTr.position += targetTr.right * EyeSeparation.Value / 2;
                // Let the game render at the new position
                yield return(new WaitForEndOfFrame());

                var capture = I360Render.CaptureTex(Resolution360.Value);

                targetTr.position -= targetTr.right * EyeSeparation.Value;
                yield return(new WaitForEndOfFrame());

                var capture2 = I360Render.CaptureTex(Resolution360.Value);

                targetTr.position += targetTr.right * EyeSeparation.Value / 2;

                ToggleCameraControllers(targetTr, true);
                Time.timeScale = 1;

                // Overlap is useless for these so don't use
                var result = StitchImages(capture, capture2, 0);

                //var filename = GetUniqueFilename("3D-360");
                var filename = GetUniqueFilename("_360_RL");
                File.WriteAllBytes(filename, EncodeToXmpFile(result));

                Logger.Log(ScreenshotMessage.Value ? LogLevel.Message : LogLevel.Info, $"3D 360 screenshot saved to {filename}");

                Destroy(result);
                Destroy(capture);
                Destroy(capture2);
            }

            try { OnPostCapture?.Invoke(); }
            catch (Exception ex) { Logger.LogError(ex); }

            Utils.Sound.Play(SystemSE.photo);
        }
        private IEnumerator TakeCharScreenshot(bool in3D)
        {
            if (currentAlphaShot == null)
            {
                Logger.Log(LogLevel.Message, "Can't render a screenshot here, try UI screenshot instead");
                yield break;
            }

            try { OnPreCapture?.Invoke(); }
            catch (Exception ex) { Logger.LogError(ex); }

            if (!in3D)
            {
                yield return(new WaitForEndOfFrame());

                var capture = currentAlphaShot.CaptureTex(ResolutionX.Value, ResolutionY.Value, DownscalingRate.Value, CaptureAlpha.Value);

                var filename = GetUniqueFilename("Render");
                File.WriteAllBytes(filename, EncodeToFile(capture));
                Logger.Log(ScreenshotMessage.Value ? LogLevel.Message : LogLevel.Info, $"Character screenshot saved to {filename}");

                Destroy(capture);
            }
            else
            {
                var targetTr = Camera.main.transform;

                ToggleCameraControllers(targetTr, false);
                Time.timeScale = 0.01f;
                yield return(new WaitForEndOfFrame());

                targetTr.position += targetTr.right * EyeSeparation.Value / 2;
                // Let the game render at the new position
                yield return(new WaitForEndOfFrame());

                var capture = currentAlphaShot.CaptureTex(ResolutionX.Value, ResolutionY.Value, DownscalingRate.Value, CaptureAlpha.Value);

                targetTr.position -= targetTr.right * EyeSeparation.Value;
                yield return(new WaitForEndOfFrame());

                var capture2 = currentAlphaShot.CaptureTex(ResolutionX.Value, ResolutionY.Value, DownscalingRate.Value, CaptureAlpha.Value);

                targetTr.position += targetTr.right * EyeSeparation.Value / 2;

                ToggleCameraControllers(targetTr, true);
                Time.timeScale = 1;

                var result = StitchImages(capture, capture2, ImageSeparationOffset.Value);

                //var filename = GetUniqueFilename("3D-Render");
                var filename = GetUniqueFilename("_RL");
                File.WriteAllBytes(filename, EncodeToFile(result));

                Logger.Log(ScreenshotMessage.Value ? LogLevel.Message : LogLevel.Info, $"3D Character screenshot saved to {filename}");

                Destroy(capture);
                Destroy(capture2);
                Destroy(result);
            }

            try { OnPostCapture?.Invoke(); }
            catch (Exception ex) { Logger.LogError(ex); }

            Utils.Sound.Play(SystemSE.photo);
        }
        private void Transparent()
        {
            try { OnPreCapture?.Invoke(); }
            catch (Exception ex) { Logger.LogError(ex); }

            Config.Reload();
            var width       = CaptureWidth.Value;
            var height      = CaptureHeight.Value;
            var downScaling = Downscaling.Value;

            var scaledWidth  = width * downScaling;
            var scaledHeight = height * downScaling;

            var cam = Camera.main.gameObject;
            var dof = cam.GetComponent <UnityStandardAssets.ImageEffects.DepthOfField>();
            var dof_prevBlurSize = dof?.maxBlurSize;

            if (dof != null)
            {
                var ratio = Screen.height / (float)scaledHeight; //Use larger of width/height?
                dof.maxBlurSize *= ratio * downScaling;
            }

            var colour = Capture(scaledWidth, scaledHeight, false);

            var ppl = cam.GetComponent <PostProcessLayer>();

            if (ppl != null)
            {
                ppl.enabled = false;
            }

            var m3D = SceneManager.GetActiveScene().GetRootGameObjects()[0].transform.Find("CustomControl/Map3D/p_ai_mi_createBG00_00")?.gameObject; //Disable background. Sinful, truly.

            m3D?.SetActive(false);

            if (dof != null)
            {
                dof.maxBlurSize = dof_prevBlurSize.Value;
                if (dof.enabled)
                {
                    dof.enabled = false;
                }
                else
                {
                    dof = null;
                }
            }

            var mask = Capture(scaledWidth, scaledHeight, true);

            if (ppl != null)
            {
                ppl.enabled = true;
            }
            if (dof != null)
            {
                dof.enabled = true;
            }

            m3D?.SetActive(true);

            var alpha = RenderTexture.GetTemporary(scaledWidth, scaledHeight, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default);

            _matComposite.SetTexture("_Overlay", mask);

            Graphics.Blit(colour, alpha, _matComposite);

            RenderTexture.ReleaseTemporary(mask);
            RenderTexture.ReleaseTemporary(colour);

            ScaleTex(ref alpha, width, height, downScaling);

            StartCoroutine(WriteTex(alpha, true));

            try { OnPostCapture?.Invoke(); }
            catch (Exception ex) { Logger.LogError(ex); }
        }