Post processing shader screen overlay issues

I am trying to make a post processing shader that creates a post processing effect, right now my shader just makes my camera effect display the current screen but slightly brighter when the post processing shader is enabled. What I am trying to do is duplicate the screen, blur that image, then apply as overlay to make the camera have a dreamy like effect, where the edges of objects are slightly glowing. For a good reference if you duplicate a image in photoshop, then apply a slight guassian blur to the top image and use overlay. Below is the script I made but the blur part of the effect is not showing for some reason.

Shader "Hidden/Custom/ScreenOverlayNew"
{
    HLSLINCLUDE

#include "Packages/com.unity.postprocessing/PostProcessing/Shaders/StdLib.hlsl"

    TEXTURE2D_SAMPLER2D(_MainTex, sampler_MainTex);
    float _Opacity;
    float _BlurSize = 0.5f;
    float4 texelSize = 0.5f;

    float4 Frag(VaryingsDefault i) : SV_Target{
        float4 base = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.texcoord);
 
        // Add the blur by sampling the texture in a kernel
        base += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.texcoord + texelSize.xy * float2(-_BlurSize, -_BlurSize)) * 0.05;
        base += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.texcoord + texelSize.xy * float2(-_BlurSize, 0)) * 0.09;
        base += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.texcoord + texelSize.xy * float2(-_BlurSize, _BlurSize)) * 0.05;
        base += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.texcoord + texelSize.xy * float2(0, -_BlurSize)) * 0.09;
        base += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.texcoord + texelSize.xy * float2(0, 0)) * 0.16;
        base += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.texcoord + texelSize.xy * float2(0, _BlurSize)) * 0.09;
        base += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.texcoord + texelSize.xy * float2(_BlurSize, -_BlurSize)) * 0.05;
        base += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.texcoord + texelSize.xy * float2(_BlurSize, 0)) * 0.09;
        base += SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.texcoord + texelSize.xy * float2(_BlurSize, _BlurSize)) * 0.05;
        base /= 1.6;

        float4 calculateBase = (1 - (1 - base)*(1 - base));
        return lerp(calculateBase, base, 0.75f);
    }

        ENDHLSL

        SubShader {
        Cull Off ZWrite Off ZTest Always

        Pass
        {
            HLSLPROGRAM
            #pragma vertex VertDefault
            #pragma fragment Frag
            ENDHLSL
        }
    }
}

Can anyone please help? I have not been able to resolve this issue

The “texel size” needs to be in normalize UV space. 0.5 is half the entire texture. If you’re rendering at 1920x1080 then the xy values need to be 1.0/1920.0 and 1.0/1080.0 respectively. Or you can use:

float4 _MainTex_TexelSize;

And Unity will fill in those values automatically.

1 Like