[Unity 5.6.3] Blur shader not working on UWP Black screen

If play in unity editor (WSA player) work good.
Create uwp app and run black screen.(other platform work fine).
I understand this is a shader compiled(UWP) so works.
asdas

View Blur Overlay:

   solidWhite = new Color(1, 1, 1, 1);
        invisibleWhite = new Color(1, 1, 1, 0);
        gameGrabCamera.enabled = false;
        shapeGrabCamera.enabled = false;
        renderGUICamera.enabled = false;

        gameTexture = new Texture2D(gameGrabCamera.targetTexture.width, gameGrabCamera.targetTexture.height, TextureFormat.ARGB32, false);
        gameGrab.GetComponent<Renderer>().material.mainTexture = gameTexture;

        shapeTexture = new Texture2D(shapeGrabCamera.targetTexture.width, shapeGrabCamera.targetTexture.height, TextureFormat.ARGB32, false);
        shapeGrab.GetComponent<Renderer>().material.mainTexture = shapeTexture;

        blurGUITexture = new Texture2D(renderGUICamera.targetTexture.width, renderGUICamera.targetTexture.height, TextureFormat.ARGB32, false);
        darkenGUIGrab.GetComponent<Renderer>().material.mainTexture = blurGUITexture;

.......

    public IEnumerator FadeIn(float duration, Camera grabCamera, GameObject grabObject, Texture2D grabTexture)
    {

        // turn on camera to take (non blurred) grab of the game o rmain menu shape
        grabCamera.enabled = true;

        grabCamera.targetTexture.DiscardContents();

        // wait for it to render
        yield return new WaitForEndOfFrame();

        // grab the pixels from the render texture & put on a quad that the GUI View layer can see
        GetRTPixels(grabCamera.targetTexture, grabTexture);

        // File.WriteAllBytes("game.png", grabTexture.EncodeToPNG()); // write to file for debugging

        // turn off 3d grabbing camera now we have the texture
        grabCamera.enabled = false;

        // show the screen grab
        grabObject.SetActive(true);

        // turn on the blur / darken
        darkenLayer.SetActive(true);

        // turn on camera to render combined, blurred image
        renderGUICamera.enabled = true;

        // wait for it to render
        yield return new WaitForEndOfFrame();

        // get pixel and show that
        GetRTPixels(renderGUICamera.targetTexture, blurGUITexture);
        darkenGUIGrab.SetActive(true);

        // turn off gui blur camera
        renderGUICamera.enabled = false;

        // turn off working layers
        darkenLayer.SetActive(false);
        grabObject.SetActive(false);

        // fade the combined, blurred image in
        darkenGUIGrab.GetComponent<Renderer>().material.color = invisibleWhite;


        var gui = darkenGUIGrab.GetComponent<Renderer>();
        DOTween.To(() => gui.material.color, x => gui.material.color = x, solidWhite, duration).OnComplete(onShowComplete).SetUpdate(true);
    }

    RenderTexture currentActiveRT;
    private void GetRTPixels(RenderTexture rt, Texture2D tex)
    {
        currentActiveRT = RenderTexture.active;
        RenderTexture.active = rt;
        tex.ReadPixels(new Rect(0, 0, tex.width, tex.height), 0, 0);
        tex.Apply();
        RenderTexture.active = currentActiveRT;
    }

Blur shader:

// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'

Shader "Custom/SimpleGrabPassBlur" {
    Properties {
        _Color ("Main Color", Color) = (1,1,1,1)
        _BumpAmt  ("Distortion", Range (0,128)) = 10
        _MainTex ("Tint Color (RGB)", 2D) = "white" {}
        _BumpMap ("Normalmap", 2D) = "bump" {}
        _Size ("Size", Range(0, 20)) = 1
    }

    Category {

        // We must be transparent, so other objects are drawn before this one.
        Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Opaque" }


        SubShader {
 
            // Horizontal blur
            GrabPass {                
                Tags { "LightMode" = "Always" }
            }
            Pass {
                Tags { "LightMode" = "Always" }
         
                CGPROGRAM
                #pragma vertex vert
                #pragma fragment frag
                #pragma fragmentoption ARB_precision_hint_fastest
                #include "UnityCG.cginc"
         
                struct appdata_t {
                    float4 vertex : POSITION;
                    float2 texcoord: TEXCOORD0;
                };
         
                struct v2f {
                    float4 vertex : POSITION;
                    float4 uvgrab : TEXCOORD0;
                };
         
                v2f vert (appdata_t v) {
                    v2f o;
                    o.vertex = UnityObjectToClipPos(v.vertex);
                    #if UNITY_UV_STARTS_AT_TOP
                    float scale = -1.0;
                    #else
                    float scale = 1.0;
                    #endif
                    o.uvgrab.xy = (float2(o.vertex.x, o.vertex.y*scale) + o.vertex.w) * 0.5;
                    o.uvgrab.zw = o.vertex.zw;
                    return o;
                }
         
                sampler2D _GrabTexture;
                float4 _GrabTexture_TexelSize;
                float _Size;
         
                half4 frag( v2f i ) : COLOR {
//                  half4 col = tex2Dproj( _GrabTexture, UNITY_PROJ_COORD(i.uvgrab));
//                  return col;
             
                    half4 sum = half4(0,0,0,0);
                    #define GRABPIXEL(weight,kernelx) tex2Dproj( _GrabTexture, UNITY_PROJ_COORD(float4(i.uvgrab.x + _GrabTexture_TexelSize.x * kernelx*_Size, i.uvgrab.y, i.uvgrab.z, i.uvgrab.w))) * weight
                    sum += GRABPIXEL(0.05, -4.0);
                    sum += GRABPIXEL(0.09, -3.0);
                    sum += GRABPIXEL(0.12, -2.0);
                    sum += GRABPIXEL(0.15, -1.0);
                    sum += GRABPIXEL(0.18,  0.0);
                    sum += GRABPIXEL(0.15, +1.0);
                    sum += GRABPIXEL(0.12, +2.0);
                    sum += GRABPIXEL(0.09, +3.0);
                    sum += GRABPIXEL(0.05, +4.0);
             
                    return sum;
                }
                ENDCG
            }
            // Vertical blur
            GrabPass {                    
                Tags { "LightMode" = "Always" }
            }
            Pass {
                Tags { "LightMode" = "Always" }
         
                CGPROGRAM
                #pragma vertex vert
                #pragma fragment frag
                #pragma fragmentoption ARB_precision_hint_fastest
                #include "UnityCG.cginc"
         
                struct appdata_t {
                    float4 vertex : POSITION;
                    float2 texcoord: TEXCOORD0;
                };
         
                struct v2f {
                    float4 vertex : POSITION;
                    float4 uvgrab : TEXCOORD0;
                };
         
                v2f vert (appdata_t v) {
                    v2f o;
                    o.vertex = UnityObjectToClipPos(v.vertex);
                    #if UNITY_UV_STARTS_AT_TOP
                    float scale = -1.0;
                    #else
                    float scale = 1.0;
                    #endif
                    o.uvgrab.xy = (float2(o.vertex.x, o.vertex.y*scale) + o.vertex.w) * 0.5;
                    o.uvgrab.zw = o.vertex.zw;
                    return o;
                }
         
                sampler2D _GrabTexture;
                float4 _GrabTexture_TexelSize;
                float _Size;
         
                half4 frag( v2f i ) : COLOR {
//                  half4 col = tex2Dproj( _GrabTexture, UNITY_PROJ_COORD(i.uvgrab));
//                  return col;
             
                    half4 sum = half4(0,0,0,0);
                    #define GRABPIXEL(weight,kernely) tex2Dproj( _GrabTexture, UNITY_PROJ_COORD(float4(i.uvgrab.x, i.uvgrab.y + _GrabTexture_TexelSize.y * kernely*_Size, i.uvgrab.z, i.uvgrab.w))) * weight
                    //G(X) = (1/(sqrt(2*PI*deviation*deviation))) * exp(-(x*x / (2*deviation*deviation)))
             
                    sum += GRABPIXEL(0.05, -4.0);
                    sum += GRABPIXEL(0.09, -3.0);
                    sum += GRABPIXEL(0.12, -2.0);
                    sum += GRABPIXEL(0.15, -1.0);
                    sum += GRABPIXEL(0.18,  0.0);
                    sum += GRABPIXEL(0.15, +1.0);
                    sum += GRABPIXEL(0.12, +2.0);
                    sum += GRABPIXEL(0.09, +3.0);
                    sum += GRABPIXEL(0.05, +4.0);
             
                    return sum;
                }
                ENDCG
            }
     
            // Distortion
            GrabPass {                    
                Tags { "LightMode" = "Always" }
            }
            Pass {
                Tags { "LightMode" = "Always" }
         
                CGPROGRAM
                #pragma vertex vert
                #pragma fragment frag
                #pragma fragmentoption ARB_precision_hint_fastest
                #include "UnityCG.cginc"
         
                struct appdata_t {
                    float4 vertex : POSITION;
                    float2 texcoord: TEXCOORD0;
                };
         
                struct v2f {
                    float4 vertex : POSITION;
                    float4 uvgrab : TEXCOORD0;
                    float2 uvbump : TEXCOORD1;
                    float2 uvmain : TEXCOORD2;
                };
         
                float _BumpAmt;
                float4 _BumpMap_ST;
                float4 _MainTex_ST;
         
                v2f vert (appdata_t v) {
                    v2f o;
                    o.vertex = UnityObjectToClipPos(v.vertex);
                    #if UNITY_UV_STARTS_AT_TOP
                    float scale = -1.0;
                    #else
                    float scale = 1.0;
                    #endif
                    o.uvgrab.xy = (float2(o.vertex.x, o.vertex.y*scale) + o.vertex.w) * 0.5;
                    o.uvgrab.zw = o.vertex.zw;
                    o.uvbump = TRANSFORM_TEX( v.texcoord, _BumpMap );
                    o.uvmain = TRANSFORM_TEX( v.texcoord, _MainTex );
                    return o;
                }
         
                fixed4 _Color;
                sampler2D _GrabTexture;
                float4 _GrabTexture_TexelSize;
                sampler2D _BumpMap;
                sampler2D _MainTex;
         
                half4 frag( v2f i ) : COLOR {
                    // calculate perturbed coordinates
                    half2 bump = UnpackNormal(tex2D( _BumpMap, i.uvbump )).rg; // we could optimize this by just reading the x  y without reconstructing the Z
                    float2 offset = bump * _BumpAmt * _GrabTexture_TexelSize.xy;
                    i.uvgrab.xy = offset * i.uvgrab.z + i.uvgrab.xy;
             
                    half4 col = tex2Dproj( _GrabTexture, UNITY_PROJ_COORD(i.uvgrab));
                    half4 tint = tex2D( _MainTex, i.uvmain ) * _Color;
             
                    return col * tint;
                }
                ENDCG
            }
        }
    }
}

Can you share a complete sample project where this reproduces? The scripts are missing some parts.

I recommend to edit your post and add code-tags , as this makes it easier for people to read.

it turned out that problem with DarkenAndBlur shader

Shader "Preloaded/DarkenAndBlur" { 
// originally from here http://forum.unity3d.com/threads/185327-Simple-Optimized-Blur-Shader, but modified to remove bump map and main texture
// added darken

    Properties {
        _Size ("BlurPower", Range(0, 20)) = 1
        _Darken ("Darken Amount", Float) = 0.5;
        _Alpha ("Alpha", Float) = 1.0
    }
    Category {
        // We must be transparent, so other objects are drawn before this one.
        Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }

        SubShader {

        Blend SrcAlpha OneMinusSrcAlpha
       
            // Horizontal blur
            GrabPass {                     
                Tags { "LightMode" = "Always" } //Grabpass is different from a rendertexture in that it doesn't require to re-render the scene. It blits the contents of the framebuffer to a temporary texture, which isn't free but still much cheaper than rendering the scene multiple times.
            }

            Pass {
                Tags { "LightMode" = "Always" }
                CGPROGRAM

                #pragma vertex vert
                #pragma fragment frag
                #pragma fragmentoption ARB_precision_hint_fastest
                #include "UnityCG.cginc"
                struct appdata_t {
                    float4 vertex : POSITION;
                    float2 texcoord: TEXCOORD0;
                };

                struct v2f {
                    float4 vertex : POSITION;
                    float4 uvgrab : TEXCOORD0;
                };
               
                v2f vert (appdata_t v) {
                    v2f o;
                    o.vertex = UnityObjectToClipPos(v.vertex);
                    #if UNITY_UV_STARTS_AT_TOP
                    float scale = -1.0;
                    #else
                    float scale = 1.0;
                    #endif
                    o.uvgrab.xy = (float2(o.vertex.x, o.vertex.y*scale) + o.vertex.w) * 0.5;
                    o.uvgrab.zw = o.vertex.zw;
                    return o;
                }

                sampler2D _GrabTexture;
                float4 _GrabTexture_TexelSize;
                float _Size;
                float _Darken;
                float _Alpha;
               
                half4 frag( v2f i ) : COLOR {
//                  half4 col = tex2Dproj( _GrabTexture, UNITY_PROJ_COORD(i.uvgrab));  //unmodified pixel
//                  return col; //returns unmodified pixel
                    half4 sum = half4(0,0,0,0);
                    //this macro is the only line of code that is different from the other pass. Here the y coord remains the same and the x varies
                    #define GRABPIXEL(weight,kernelx) tex2Dproj( _GrabTexture, UNITY_PROJ_COORD(float4(i.uvgrab.x + _GrabTexture_TexelSize.x * kernelx*_Size, i.uvgrab.y, i.uvgrab.z, i.uvgrab.w))) * weight
                    sum += GRABPIXEL(0.05, -4.0);
                    sum += GRABPIXEL(0.09, -3.0);
                    sum += GRABPIXEL(0.12, -2.0);
                    sum += GRABPIXEL(0.15, -1.0);
                    sum += GRABPIXEL(0.18,  0.0);
                    sum += GRABPIXEL(0.15, +1.0);
                    sum += GRABPIXEL(0.12, +2.0);
                    sum += GRABPIXEL(0.09, +3.0);
                    sum += GRABPIXEL(0.05, +4.0);
                   
                    sum *= _Darken;
                    sum.a = _Alpha;
                    return sum;
                }
                ENDCG
            }

           
            // Vertical blur
            GrabPass {                         
                Tags { "LightMode" = "Always" }
            }

            Pass {
                Tags { "LightMode" = "Always" }

                CGPROGRAM
                #pragma vertex vert
                #pragma fragment frag
                #pragma fragmentoption ARB_precision_hint_fastest
                #include "UnityCG.cginc"

                struct appdata_t {
                    float4 vertex : POSITION;
                    float2 texcoord: TEXCOORD0;
                };

                struct v2f {
                    float4 vertex : POSITION;
                    float4 uvgrab : TEXCOORD0;
                };

                v2f vert (appdata_t v) {
                    v2f o;
                    o.vertex = UnityObjectToClipPos(v.vertex);
                    #if UNITY_UV_STARTS_AT_TOP
                    float scale = -1.0;
                    #else
                    float scale = 1.0;
                    #endif
                    o.uvgrab.xy = (float2(o.vertex.x, o.vertex.y*scale) + o.vertex.w) * 0.5;
                    o.uvgrab.zw = o.vertex.zw;
                    return o;
                }

                sampler2D _GrabTexture;
                float4 _GrabTexture_TexelSize;
                float _Size;
                float _Darken;
                float _Alpha;
                half4 frag( v2f i ) : COLOR {
//                  half4 col = tex2Dproj( _GrabTexture, UNITY_PROJ_COORD(i.uvgrab));
//                  return col;
                    half4 sum = half4(0,0,0,0);
                    //this macro is the only line of code that is different from the other pass. Here the x coord remains the same and the y varies
                    #define GRABPIXEL(weight,kernely) tex2Dproj( _GrabTexture, UNITY_PROJ_COORD(float4(i.uvgrab.x, i.uvgrab.y + _GrabTexture_TexelSize.y * kernely*_Size, i.uvgrab.z, i.uvgrab.w))) * weight
                    //G(X) = (1/(sqrt(2*PI*deviation*deviation))) * exp(-(x*x / (2*deviation*deviation)))
                    sum += GRABPIXEL(0.05, -4.0);
                    sum += GRABPIXEL(0.09, -3.0);
                    sum += GRABPIXEL(0.12, -2.0);
                    sum += GRABPIXEL(0.15, -1.0);
                    sum += GRABPIXEL(0.18,  0.0);
                    sum += GRABPIXEL(0.15, +1.0);
                    sum += GRABPIXEL(0.12, +2.0);
                    sum += GRABPIXEL(0.09, +3.0);
                    sum += GRABPIXEL(0.05, +4.0);
                   
                    sum *= _Darken;
                    sum.a = _Alpha;
                    return sum;
                }
                ENDCG
            }
        }
    }
}


it became clear that the error in the function.

 half4 frag( v2f i ) : COLOR {
//                  half4 col = tex2Dproj( _GrabTexture, UNITY_PROJ_COORD(i.uvgrab));  //unmodified pixel
//                  return col; //returns unmodified pixel
                    half4 sum = half4(0,0,0,0);
                    //this macro is the only line of code that is different from the other pass. Here the y coord remains the same and the x varies
                    #define GRABPIXEL(weight,kernelx) tex2Dproj( _GrabTexture, UNITY_PROJ_COORD(float4(i.uvgrab.x + _GrabTexture_TexelSize.x * kernelx*_Size, i.uvgrab.y, i.uvgrab.z, i.uvgrab.w))) * weight
                    sum += GRABPIXEL(0.05, -4.0);
                    sum += GRABPIXEL(0.09, -3.0);
                    sum += GRABPIXEL(0.12, -2.0);
                    sum += GRABPIXEL(0.15, -1.0);
                    sum += GRABPIXEL(0.18,  0.0);
                    sum += GRABPIXEL(0.15, +1.0);
                    sum += GRABPIXEL(0.12, +2.0);
                    sum += GRABPIXEL(0.09, +3.0);
                    sum += GRABPIXEL(0.05, +4.0);
                
                    sum *= _Darken;
                    sum.a = _Alpha;
                    return sum;
                }

If it is return from it

half4 col = tex2Dproj( _GrabTexture, UNITY_PROJ_COORD(i.uvgrab));  //unmodified pixel
 return col; //returns unmodified pixel

, the shader works fine.

is it possible to see how the shader looks like without the formation of the UWP project (in Unit it always shows me normally, although there are problems in uwp)

it is not entirely clear how to look for what gives zero

Yes, you can step through your shader as outlined here: Unity - Manual: Debugging shaders using Visual Studio

tried to debug in uwp but received an unhandled win32 exception.
there were assumptions, wrong take points: (change sign from minus to plus)

GRABPIXEL(weight,kernelx) tex2Dproj( _GrabTexture, UNITY_PROJ_COORD(float4(i.uvgrab.x - _GrabTexture_TexelSize.x * kernelx*_Size, i.uvgrab.y, i.uvgrab.z, i.uvgrab.w))) * weight

or

 sum += GRABPIXEL(0.05, -4.0);
                    sum += GRABPIXEL(-0.09, -3.0);
                    sum += GRABPIXEL(-0.12, -2.0);
                    sum += GRABPIXEL(-0.15, -1.0);
                    sum += GRABPIXEL(-0.18,  0.0);
                    sum += GRABPIXEL(-0.15, +1.0);
                    sum += GRABPIXEL(-0.12, +2.0);
                    sum += GRABPIXEL(-0.09, +3.0);
                    sum += GRABPIXEL(-0.05, +4.0);

but it did not give a positive result:(

I not have ideas over why it can be zero. I need help

Can you attach a sample project that I could build & run that demonstrates the issue? The scripts in your original post aren’t complete.

Debug UWP shader Exeption

D3D11 ERROR: ID3D11DeviceContext::CopySubresourceRegion: Cannot invoke CopySubresourceRegion when the Formats of each Resource are not the same or at least castable to each other, unless one format is compressed (DXGI_FORMAT_R9G9B9E5_SHAREDEXP, or DXGI_FORMAT_BC[1,2,3,4,5]_* ) and the source format is similar to the dest according to: BC[1|4] ~= R16G16B16A16|R32G32, BC[2|3|5] ~= R32G32B32A32, R9G9B9E5_SHAREDEXP ~= R32. [ RESOURCE_MANIPULATION ERROR #281: COPYSUBRESOURCEREGION_INVALIDSOURCE]
D3D11: **BREAK** enabled for the previous message, which was: [ ERROR RESOURCE_MANIPULATION #281: COPYSUBRESOURCEREGION_INVALIDSOURCE ]
Exception thrown at 0x00007FFFF1EC3C58 (KernelBase.dll) in Crafty Cut.exe: 0x0000087A (parameters: 0x0000000000000001, 0x0000009E173F5CF8, 0x0000009E173F7BF0).
Unhandled exception at 0x00007FFFF1EC3C58 (KernelBase.dll) in Crafty Cut.exe: 0x0000087A (parameters: 0x0000000000000001, 0x0000009E173F5CF8, 0x0000009E173F7BF0).

I can not attach the example of the project unfortunately.
problem in shader, the shader code is executed good in uwp (look above).

if you execute the following code. Unmodified pixel image.(in UWP good result without blur effect)

half4 frag( v2f i ) : COLOR {
               half4 col = tex2Dproj( _GrabTexture, UNITY_PROJ_COORD(i.uvgrab));  //unmodified pixel
                  return col; //returns unmodified pixel
}

if you execute the following code. Black screen.(in UWP bad result but Unity Editor good result wit blur effect.)

half4 frag( v2f i ) : COLOR {
                    half4 sum = half4(0,0,0,0);
                    //this macro is the only line of code that is different from the other pass. Here the y coord remains the same and the x varies
                    #define GRABPIXEL(weight,kernelx) tex2Dproj( _GrabTexture, UNITY_PROJ_COORD(float4(i.uvgrab.x + _GrabTexture_TexelSize.x * kernelx*_Size, i.uvgrab.y, i.uvgrab.z, i.uvgrab.w))) * weight
                    sum += GRABPIXEL(0.05, -4.0);
                    sum += GRABPIXEL(0.09, -3.0);
                    sum += GRABPIXEL(0.12, -2.0);
                    sum += GRABPIXEL(0.15, -1.0);
                    sum += GRABPIXEL(0.18,  0.0);
                    sum += GRABPIXEL(0.15, +1.0);
                    sum += GRABPIXEL(0.12, +2.0);
                    sum += GRABPIXEL(0.09, +3.0);
                    sum += GRABPIXEL(0.05, +4.0);
           
                    sum *= _Darken;
                    sum.a = _Alpha;
                    return sum;
                }

From this all we can assert that the texture to the input is correct (not black), the shader does not crash in uwp executes normally, but the function returns zeros of black color.

Init texture :

  void Awake()
    {
        darkenLayer = transform.Find("DarkenLayer").gameObject;
        darkenLayer.SetActive(false);

        gameGrab = transform.Find("GameGrab").gameObject;
        gameGrab.SetActive(false);

        shapeGrab = transform.Find("ShapeGrab").gameObject;
        shapeGrab.SetActive(false);

        darkenGUIGrab = transform.Find("DarkenGUIGrab").gameObject;
        darkenGUIGrab.SetActive(false);

        solidWhite = new Color(1, 1, 1, 1);
        invisibleWhite = new Color(1, 1, 1, 0);
        gameGrabCamera.enabled = false;
        shapeGrabCamera.enabled = false;
        renderGUICamera.enabled = false;

        gameTexture = new Texture2D(gameGrabCamera.targetTexture.width, gameGrabCamera.targetTexture.height, TextureFormat.ARGB32, false);
        gameGrab.GetComponent<Renderer>().material.mainTexture = gameTexture;

        shapeTexture = new Texture2D(shapeGrabCamera.targetTexture.width, shapeGrabCamera.targetTexture.height, TextureFormat.ARGB32, false);
        shapeGrab.GetComponent<Renderer>().material.mainTexture = shapeTexture;

        blurGUITexture = new Texture2D(renderGUICamera.targetTexture.width, renderGUICamera.targetTexture.height, TextureFormat.ARGB32, false);
        darkenGUIGrab.GetComponent<Renderer>().material.mainTexture = blurGUITexture;
    }

 protected override void onShowStart (object data)
    {

        if ((string)data == ViewMainMenu.LOCATION)
        {

            StartCoroutine(FadeIn(0.5f, shapeGrabCamera, shapeGrab, shapeTexture));
        }
        else
        {
            StartCoroutine(FadeIn(0.5f, gameGrabCamera, gameGrab, gameTexture));
        }

    }

    protected override void onHideStart ()
    {
        FadeOut(0.5f);
    }

    public IEnumerator FadeIn(float duration, Camera grabCamera, GameObject grabObject, Texture2D grabTexture)
    {

        // turn on camera to take (non blurred) grab of the game o rmain menu shape
        grabCamera.enabled = true;

        grabCamera.targetTexture.DiscardContents();

        // wait for it to render
        yield return new WaitForEndOfFrame();

        // grab the pixels from the render texture & put on a quad that the GUI View layer can see
        GetRTPixels(grabCamera.targetTexture, grabTexture);

        // File.WriteAllBytes("game.png", grabTexture.EncodeToPNG()); // write to file for debugging

        // turn off 3d grabbing camera now we have the texture
        grabCamera.enabled = false;

        // show the screen grab
        grabObject.SetActive(true);

        // turn on the blur / darken
        darkenLayer.SetActive(true);

        // turn on camera to render combined, blurred image
        renderGUICamera.enabled = true;

        // wait for it to render
        yield return new WaitForEndOfFrame();

        // get pixel and show that
        GetRTPixels(renderGUICamera.targetTexture, blurGUITexture);
        darkenGUIGrab.SetActive(true);

        // turn off gui blur camera
        renderGUICamera.enabled = false;

        // turn off working layers
        darkenLayer.SetActive(false);
        grabObject.SetActive(false);

        // fade the combined, blurred image in
        darkenGUIGrab.GetComponent<Renderer>().material.color = invisibleWhite;

#if USE_DOTWEEN

        var gui = darkenGUIGrab.GetComponent<Renderer>();
        DOTween.To(() => gui.material.color, x => gui.material.color = x, solidWhite, duration).OnComplete(onShowComplete).SetUpdate(true);
#else

        TweenParms tweenParams = new TweenParms();
        tweenParams.Prop("color", solidWhite);
        tweenParams.UpdateType(UpdateType.TimeScaleIndependentUpdate);
        tweenParams.OnComplete(onShowComplete);
        HOTween.To(darkenGUIGrab.GetComponent<Renderer>().material, duration, tweenParams);
#endif
    }

  private void GetRTPixels(RenderTexture rt, Texture2D tex)
    {
        currentActiveRT = RenderTexture.active;
        RenderTexture.active = rt;
        tex.ReadPixels(new Rect(0, 0, tex.width, tex.height), 0, 0);
        tex.Apply();
        RenderTexture.active = currentActiveRT;


        // Graphics.Blit(tex, rt );
    }

Shader attached.

3224143–247255–DarkenAndBlur.shader (6.16 KB)

and error:

D3D11 ERROR: ID3D11DeviceContext::CopySubresourceRegion: Cannot invoke CopySubresourceRegion when the Formats of each Resource are not the same or at least castable to each other, unless one format is compressed (DXGI_FORMAT_R9G9B9E5_SHAREDEXP, or DXGI_FORMAT_BC[1,2,3,4,5]_* ) and the source format is similar to the dest according to: BC[1|4] ~= R16G16B16A16|R32G32, BC[2|3|5] ~= R32G32B32A32, R9G9B9E5_SHAREDEXP ~= R32. [ RESOURCE_MANIPULATION ERROR #281: COPYSUBRESOURCEREGION_INVALIDSOURCE]
D3D11 ERROR: ID3D11DeviceContext::CopySubresourceRegion: Cannot invoke CopySubresourceRegion when the Formats of each Resource are not the same or at least castable to each other, unless one format is compressed (DXGI_FORMAT_R9G9B9E5_SHAREDEXP, or DXGI_FORMAT_BC[1,2,3,4,5]_* ) and the source format is similar to the dest according to: BC[1|4] ~= R16G16B16A16|R32G32, BC[2|3|5] ~= R32G32B32A32, R9G9B9E5_SHAREDEXP ~= R32. [ RESOURCE_MANIPULATION ERROR #281: COPYSUBRESOURCEREGION_INVALIDSOURCE]
Exception thrown at 0x00007FFFF1EC3C58 in MyApp.exe: Microsoft C++ exception: _com_error at memory location 0x000000B7F44F9090.
Exception thrown at 0x00007FFFF1EC3C58 in MyApp.exe: Microsoft C++ exception: _com_error at memory location 0x000000B7F44F9090.
D3D11 ERROR: ID3D11DeviceContext::CopySubresourceRegion: Cannot invoke CopySubresourceRegion when the Formats of each Resource are not the same or at least castable to each other, unless one format is compressed (DXGI_FORMAT_R9G9B9E5_SHAREDEXP, or DXGI_FORMAT_BC[1,2,3,4,5]_* ) and the source format is similar to the dest according to: BC[1|4] ~= R16G16B16A16|R32G32, BC[2|3|5] ~= R32G32B32A32, R9G9B9E5_SHAREDEXP ~= R32. [ RESOURCE_MANIPULATION ERROR #281: COPYSUBRESOURCEREGION_INVALIDSOURCE]
D3D11 ERROR: ID3D11DeviceContext::CopySubresourceRegion: Cannot invoke CopySubresourceRegion when the Formats of each Resource are not the same or at least castable to each other, unless one format is compressed (DXGI_FORMAT_R9G9B9E5_SHAREDEXP, or DXGI_FORMAT_BC[1,2,3,4,5]_* ) and the source format is similar to the dest according to: BC[1|4] ~= R16G16B16A16|R32G32, BC[2|3|5] ~= R32G32B32A32, R9G9B9E5_SHAREDEXP ~= R32. [ RESOURCE_MANIPULATION ERROR #281: COPYSUBRESOURCEREGION_INVALIDSOURCE]

Does this happen during “Apply” call? Perhaps the texture you’re trying to copy stuff into is wrong format?

the texture format is the same ARGB32. This error occurs without calling GetRTPixels.

I revised all the textures in the unit editor (gameGrab, shapeGrab, renderGUI …) format ARGB32.

Did you try RenderTextureFormat.Default instead?

If save to file texture (call SaveToFile) in Unity Editor (image blur effect).
If save to file texture (call SaveToFile) in UWP app (image black).

 public IEnumerator FadeIn(float duration, Camera grabCamera, GameObject grabObject, Texture2D grabTexture)
    {

        // turn on camera to take (non blurred) grab of the game o rmain menu shape
        grabCamera.enabled = true;

        grabCamera.targetTexture.DiscardContents();

        // wait for it to render
        yield return new WaitForEndOfFrame();

        // grab the pixels from the render texture & put on a quad that the GUI View layer can see
        GetRTPixels(grabCamera.targetTexture, grabTexture);

        // File.WriteAllBytes("game.png", grabTexture.EncodeToPNG()); // write to file for debugging

        // turn off 3d grabbing camera now we have the texture
        grabCamera.enabled = false;

        // show the screen grab
        grabObject.SetActive(true);

        // turn on the blur / darken
        darkenLayer.SetActive(true);

        // turn on camera to render combined, blurred image
        renderGUICamera.enabled = true;

        // wait for it to render
        yield return new WaitForEndOfFrame();

  SaveToFile(renderGUICamera.targetTexture, "renderGUICamera.png");
      
        GetRTPixels(renderGUICamera.targetTexture, blurGUITexture);
 private void SaveToFile(RenderTexture renderTexture, string name)
    {
        RenderTexture currentActiveRT = RenderTexture.active;
        RenderTexture.active = renderTexture;
        Texture2D tex = new Texture2D(renderTexture.width, renderTexture.height);
        tex.ReadPixels(new Rect(0, 0, tex.width, tex.height), 0, 0);
        var bytes = tex.EncodeToPNG();

        string path = Application.persistentDataPath + "/" + name;
        using (Stream file_stream = File.Open(path, FileMode.Create))
        {
            file_stream.Write(bytes, 0, bytes.Length);
        }
        UnityEngine.Object.Destroy(tex);
        RenderTexture.active = currentActiveRT;
    }