-
Notifications
You must be signed in to change notification settings - Fork 0
/
RadialBlur.shader
67 lines (55 loc) · 1.59 KB
/
RadialBlur.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
Shader "Hidden/RW/RadialBlur"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_BlurWidth("Blur Width", Range(0,1)) = 0.85
_Intensity("Intesity", Range(0,1)) = 1
_Center("Center", Vector) = (0.5,0.5,0,0)
}
SubShader
{
Blend One One
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
#define NUM_SAMPLES 100
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
return o;
}
sampler2D _MainTex;
float _BlurWidth;
float _Intensity;
float4 _Center;
fixed4 frag(v2f i) : SV_Target
{
fixed4 color = fixed4(0.0f, 0.0f, 0.0f, 1.0f);
float2 ray = i.uv - _Center.xy;
for (int i = 0; i < NUM_SAMPLES; i++)
{
float scale = 1.0f - _BlurWidth * (float(i) / float(NUM_SAMPLES - 1));
color.xyz += tex2D(_MainTex, (ray * scale) + _Center.xy).xyz / float(NUM_SAMPLES);
}
return color * _Intensity;
}
ENDCG
}
}
}