summaryrefslogtreecommitdiff
path: root/Assets/Bundle/Shaders/Common/Image/common_img_motionblur.shader
blob: 6219bdac63aaf89f4f4e7a049b8b3f6a708c9f44 (plain)
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
// 高斯模糊

Shader "Erika/Common/Image/MotionBlur" 
{
	Properties
	{
		_MainTex("Texture", 2D) = "white" {}
		_Angle("Angle", float) = 0
		_Distance("Distance", float) = 0
		_TileOffset("TileOffset", Vector) = (1,1,0,0)
		_Iterate("Iterate Count", float) = 1
	}

	SubShader
	{
		Tags { "RenderType" = "Opaque" "Queue" = "Transparent-1"}
		LOD 100

		ZWrite Off
		ZTest LEqual

		Blend SrcAlpha OneMinusSrcAlpha

		Pass
		{
			CGPROGRAM
			#pragma vertex vert
			#pragma fragment frag

			#include "UnityCG.cginc"

			#include "Assets/Bundle/Shaders/Include/ImageEffect.cginc"

			struct v2f
			{
				float2 uv : TEXCOORD0;
				float4 vertex : SV_POSITION;
			};

			sampler2D _MainTex;
			float4 _MainTex_ST;

			float _Angle;

			float4 _TileOffset; // 角色的范围

			fixed _Distance;

			float _Iterate; // 迭代次数

            float _AlphaMultiplier; //

			v2f vert(appdata_img v)
			{
				v2f o;
				o.vertex = UnityObjectToClipPos(v.vertex);
				o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
				return o;
			}

			fixed4 frag(v2f i) : SV_Target
			{
			    _Distance = 0.1;

				fixed2 uv0 = i.uv;
				
				//fixed4 color = blur(_MainTex, _ScreenParams.xy, uv);
                fixed4 color = fixed4(0,0,0,0);
                const float count = 20;
                float step = _Distance / count;
                for(int i = 0; i < count; ++i) 
                {
                    fixed2 uv = uv0 + step * i * fixed2(cos(radians(_Angle)), sin(radians(_Angle)));
                    if(uv.x > 1) continue;
                    if(uv.x < 0) continue;
                    float weight =  0.15 - 0.15 * ((float)i / (float)count);
                    color += tex2D(_MainTex, uv) * weight;
                }

                color.a *= _AlphaMultiplier;

				return color;
			}
			ENDCG
		}
	}

} // shader