Exemplo n.º 1
0
        public void RequestUpdate(Action OnFirstRendered = null)
        {
            InvokeOnCaptured();

            onFirstRender = OnFirstRendered;

            step = BlurStep.Requested;
        }
Exemplo n.º 2
0
 private void OnPostRender()
 {
     if (!allowScreenGrabToRt && step == BlurStep.Requested)
     {
         step = BlurStep.ReturnedFromCamera;
         var tex = ScreenReadTexture2D;
         tex.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0, false);
         tex.Apply();
     }
 }
Exemplo n.º 3
0
        public void Update()
        {
            switch (step)
            {
            case BlurStep.ReturnedFromCamera:

                BlitRt(_screenTexture, copyShader);
                step          = BlurStep.Blurring;
                blurIteration = 0;

                if (command == ProcessCommand.Nothing)
                {
                    try
                    {
                        _onUpdated?.Invoke();
                    }
                    catch (Exception ex)
                    {
                        Debug.LogError(ex);
                    }

                    step = BlurStep.Off;
                }

                break;

            case BlurStep.Blurring:

                if (blurIteration == 0)
                {
                    try
                    {
                        _onUpdated?.Invoke();
                    }
                    catch (Exception ex)
                    {
                        Debug.LogError(ex);
                    }
                }

                blurIteration++;

                BlitRt(postProcessShader);

                if (blurIteration > postProcessIteration)
                {
                    step = BlurStep.Off;
                }
                break;
            }
        }
Exemplo n.º 4
0
 public void Reset() => step = BlurStep.Off;
Exemplo n.º 5
0
 void Reset()
 {
     MyCamera = GetComponent <Camera>();
     step     = BlurStep.Off;
 }
Exemplo n.º 6
0
        public void Update()
        {
            switch (step)
            {
            case BlurStep.Requested:

                if (allowScreenGrabToRt)
                {
                    step = BlurStep.ReturnedFromCamera;

                    MyCamera.enabled       = false;
                    MyCamera.targetTexture = ScreenReadRenderTexture;

                    MyCamera.Render();
                    MyCamera.targetTexture = null;
                    MyCamera.enabled       = true;

                    if (useSecondBufferForRenderTextureScreenGrab)
                    {
                        Blit(ScreenReadRenderTexture, ScreenReadSecondBufferRt, copyShader);
                    }

                    goto case BlurStep.ReturnedFromCamera;
                }
                break;

            case BlurStep.ReturnedFromCamera:

                BlitToEffectBuffer(CurrentScreenReadTexture, copyShader);

                screenGradTexture.GlobalValue      = CurrentScreenReadTexture;
                processedScreenTexture.GlobalValue = CurrentScreenReadTexture;

                step          = BlurStep.Blurring;
                blurIteration = 0;

                InvokeOnCaptured();

                if (command == ProcessCommand.Nothing)
                {
                    step = BlurStep.Off;
                }

                break;

            case BlurStep.Blurring:

                blurIteration++;

                BlitBetweenEffectBuffers(postProcessShader);

                if (blurIteration > postProcessIteration)
                {
                    step = BlurStep.Off;
                }

                if (blurIteration == 1)
                {
                    InvokeOnCaptured();
                }

                break;
            }

            #region Press Position

            if (mousePositionToShader)
            {
                bool down = Input.GetMouseButton(0);

                if (down || mouseDownStrength > 0)
                {
                    bool downThisFrame = Input.GetMouseButtonDown(0);

                    if (downThisFrame)
                    {
                        mouseDownStrength = 0;
                        mouseDownStrengthOneDirectional = 0;
                        downClickFullyShown             = false;
                    }

                    mouseDownStrengthOneDirectional = LerpUtils.LerpBySpeed(mouseDownStrengthOneDirectional,
                                                                            down ? 0 : 1,
                                                                            down ? 4f : (3f - mouseDownStrengthOneDirectional * 3f));

                    mouseDownStrength = LerpUtils.LerpBySpeed(mouseDownStrength,
                                                              downClickFullyShown ? 0 :
                                                              (down ? 0.9f : 1f),
                                                              (down) ? 5 : (downClickFullyShown ? 0.75f : 2.5f));

                    if (mouseDownStrength > 0.99f)
                    {
                        downClickFullyShown = true;
                    }

                    if (down)
                    {
                        mouseDownPosition = Input.mousePosition.XY() / new Vector2(Screen.width, Screen.height);
                    }

                    mousePosition.GlobalValue = mouseDownPosition.ToVector4(mouseDownStrength, ((float)Screen.width) / Screen.height);
                }
            }
            #endregion
        }