92 lines
2.1 KiB
Plaintext
92 lines
2.1 KiB
Plaintext
Shader "Unlit/Blur"
|
|
{
|
|
|
|
SubShader
|
|
{
|
|
ZTest Always Cull Off ZWrite Off
|
|
|
|
HLSLINCLUDE
|
|
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
|
|
sampler2D _MainTex;
|
|
half4 _MainTex_TexelSize;
|
|
float _BlurSize;
|
|
|
|
struct v2f {
|
|
float4 pos : SV_POSITION;
|
|
half2 uv[5]: TEXCOORD0;
|
|
};
|
|
|
|
//垂直方向的模糊
|
|
v2f vertBlurVertical(uint vertexID: SV_VertexID)
|
|
{
|
|
v2f o;
|
|
o.pos = GetFullScreenTriangleVertexPosition(vertexID);
|
|
|
|
half2 uv = GetFullScreenTriangleTexCoord(vertexID);
|
|
|
|
o.uv[0] = uv;
|
|
o.uv[1] = uv + float2(0.0, _MainTex_TexelSize.y * 1.0) * _BlurSize;
|
|
o.uv[2] = uv - float2(0.0, _MainTex_TexelSize.y * 1.0) * _BlurSize;
|
|
o.uv[3] = uv + float2(0.0, _MainTex_TexelSize.y * 2.0) * _BlurSize;
|
|
o.uv[4] = uv - float2(0.0, _MainTex_TexelSize.y * 2.0) * _BlurSize;
|
|
|
|
return o;
|
|
}
|
|
//水平方向的模糊
|
|
v2f vertBlurHorizontal(uint vertexID: SV_VertexID)
|
|
{
|
|
v2f o;
|
|
o.pos = GetFullScreenTriangleVertexPosition(vertexID);
|
|
|
|
half2 uv = GetFullScreenTriangleTexCoord(vertexID);
|
|
|
|
o.uv[0] = uv;
|
|
o.uv[1] = uv + float2(_MainTex_TexelSize.x * 1.0, 0.0) * _BlurSize;
|
|
o.uv[2] = uv - float2(_MainTex_TexelSize.x * 1.0, 0.0) * _BlurSize;
|
|
o.uv[3] = uv + float2(_MainTex_TexelSize.x * 2.0, 0.0) * _BlurSize;
|
|
o.uv[4] = uv - float2(_MainTex_TexelSize.x * 2.0, 0.0) * _BlurSize;
|
|
|
|
return o;
|
|
}
|
|
|
|
half4 fragBlur(v2f i) : SV_Target {
|
|
float weight[3] = {0.4026, 0.2442, 0.0545};
|
|
|
|
half3 sum = tex2D(_MainTex, i.uv[0]).rgb * weight[0];
|
|
|
|
for (int it = 1; it < 3; it++) {
|
|
sum += tex2D(_MainTex, i.uv[it*2-1]).rgb * weight[it];
|
|
sum += tex2D(_MainTex, i.uv[it*2]).rgb * weight[it];
|
|
}
|
|
|
|
return half4(sum, 1.0);
|
|
}
|
|
|
|
ENDHLSL
|
|
Pass
|
|
{
|
|
NAME "GAUSSIAN_BLUR_VERTICAL"
|
|
|
|
HLSLPROGRAM
|
|
|
|
#pragma vertex vertBlurVertical
|
|
#pragma fragment fragBlur
|
|
|
|
ENDHLSL
|
|
}
|
|
|
|
Pass
|
|
{
|
|
NAME "GAUSSIAN_BLUR_HORIZONTAL"
|
|
|
|
HLSLPROGRAM
|
|
|
|
#pragma vertex vertBlurHorizontal
|
|
#pragma fragment fragBlur
|
|
|
|
ENDHLSL
|
|
}
|
|
}
|
|
}
|