-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathGaussianBlurBilinear2.shader
108 lines (88 loc) · 2.59 KB
/
GaussianBlurBilinear2.shader
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
//使用3个采样点,实际进行5个采样的基于gpu双线性插值的高斯模糊
Shader "LX/GaussianBlurBilinear2"
{
Properties
{
_MainTex ("Base (RGB)", 2D) = "white" {}
_BlurSize ("Blur Size", Float) = 1.0
}
SubShader
{
CGINCLUDE
#include "UnityCG.cginc"
sampler2D _MainTex;
half4 _MainTex_TexelSize;
float _BlurSize;
struct v2f
{
float4 pos : SV_POSITION;
half2 uv[3]: TEXCOORD0;
};
v2f vertBlurVertical(appdata_img v)
{
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
half2 uv = v.texcoord;
o.uv[0] = uv + float2(0, _MainTex_TexelSize.y * -1.087) * _BlurSize;
o.uv[1] = uv;
o.uv[2] = uv + float2(0, _MainTex_TexelSize.y * 1.087) * _BlurSize;;
return o;
}
v2f vertBlurHorizontal(appdata_img v)
{
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
half2 uv = v.texcoord;
o.uv[0] = uv + float2(_MainTex_TexelSize.x * -1.087, 0) * _BlurSize;
o.uv[1] = uv;
o.uv[2] = uv + float2(_MainTex_TexelSize.x * 1.087, 0) * _BlurSize;;
return o;
}
fixed4 fragBlur(v2f i) : SV_Target
{
float weight[3] = {
0.2504,
0.4992,
0.2504
};
fixed3 sum = 0;
for (int index = 0; index < 3; index++)
{
sum += tex2D(_MainTex, i.uv[index]).rgb * weight[index];
}
return fixed4(sum, 1);
}
struct VertexInput
{
float4 vertex : POSITION;
half2 texcoord : TEXCOORD0;
};
struct VertexOutput_DownSmpl
{
float4 pos : SV_POSITION;
half2 uv20 : TEXCOORD0;
half2 uv21 : TEXCOORD1;
half2 uv22 : TEXCOORD2;
half2 uv23 : TEXCOORD3;
};
ENDCG
ZTest Always Cull Off ZWrite Off
Pass
{
NAME "GAUSSIAN_BLUR_VERTICAL"
CGPROGRAM
#pragma vertex vertBlurVertical
#pragma fragment fragBlur
ENDCG
}
Pass
{
NAME "GAUSSIAN_BLUR_HORIZONTAL"
CGPROGRAM
#pragma vertex vertBlurHorizontal
#pragma fragment fragBlur
ENDCG
}
}
FallBack Off
}