t1 / TFDContents / Assets / Resources / BlurShader3.shader @ 9
이력 | 보기 | 이력해설 | 다운로드 (4.08 KB)
1 | 3 | KTH | // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)' |
---|---|---|---|
2 | |||
3 | Shader "Custom/BlurShader3" { |
||
4 | Properties { |
||
5 | _MainTex ("Base (RGB)", 2D) = "white" {} |
||
6 | _BlurSizeXY("BlurSizeXY", Range(0,10)) = 0 |
||
7 | } |
||
8 | |||
9 | SubShader { |
||
10 | |||
11 | // Render the object with the texture generated above |
||
12 | Pass { |
||
13 | |||
14 | CGPROGRAM |
||
15 | #pragma vertex vert1 |
||
16 | #pragma fragment frag1 |
||
17 | #pragma target 3.0 |
||
18 | |||
19 | sampler2D _MainTex; |
||
20 | float _BlurSizeXY; |
||
21 | |||
22 | struct data { |
||
23 | float4 vertex : POSITION; |
||
24 | float3 normal : NORMAL; |
||
25 | }; |
||
26 | |||
27 | struct v2f { |
||
28 | float4 position : POSITION; |
||
29 | float4 screenPos : TEXCOORD0; |
||
30 | }; |
||
31 | |||
32 | v2f vert1(data i) |
||
33 | { |
||
34 | v2f o; |
||
35 | o.position = UnityObjectToClipPos(i.vertex); |
||
36 | o.screenPos = o.position; |
||
37 | |||
38 | return o; |
||
39 | } |
||
40 | |||
41 | half4 frag1( v2f i ) : COLOR |
||
42 | { |
||
43 | float2 screenPos = i.screenPos.xy / i.screenPos.w; |
||
44 | float depth = _BlurSizeXY * 0.0005; |
||
45 | |||
46 | screenPos.x = (screenPos.x + 1) * 0.5; |
||
47 | screenPos.y = 1 - (screenPos.y + 1) * 0.5; |
||
48 | |||
49 | //horizontal |
||
50 | half4 sum = half4(0.0h,0.0h,0.0h,0.0h); |
||
51 | |||
52 | sum += tex2D( _MainTex, float2(screenPos.x-5.0 * depth, screenPos.y )) * 0.025; |
||
53 | sum += tex2D( _MainTex, float2(screenPos.x+5.0 * depth, screenPos.y )) * 0.025; |
||
54 | |||
55 | sum += tex2D( _MainTex, float2(screenPos.x-4.0 * depth, screenPos.y)) * 0.05; |
||
56 | sum += tex2D( _MainTex, float2(screenPos.x+4.0 * depth, screenPos.y)) * 0.05; |
||
57 | |||
58 | |||
59 | sum += tex2D( _MainTex, float2(screenPos.x-3.0 * depth, screenPos.y)) * 0.09; |
||
60 | sum += tex2D( _MainTex, float2(screenPos.x+3.0 * depth, screenPos.y)) * 0.09; |
||
61 | |||
62 | sum += tex2D( _MainTex, float2(screenPos.x-2.0 * depth, screenPos.y)) * 0.12; |
||
63 | sum += tex2D( _MainTex, float2(screenPos.x+2.0 * depth, screenPos.y)) * 0.12; |
||
64 | |||
65 | sum += tex2D( _MainTex, float2(screenPos.x-1.0 * depth, screenPos.y)) * 0.15; |
||
66 | sum += tex2D( _MainTex, float2(screenPos.x+1.0 * depth, screenPos.y)) * 0.15; |
||
67 | |||
68 | sum += tex2D( _MainTex, float2(screenPos.x, screenPos.y)) * 0.16; |
||
69 | |||
70 | return sum / 2; |
||
71 | } |
||
72 | |||
73 | ENDCG |
||
74 | } |
||
75 | |||
76 | Pass { |
||
77 | Blend One One |
||
78 | |||
79 | CGPROGRAM |
||
80 | #pragma vertex vert2 |
||
81 | #pragma fragment frag2 |
||
82 | #pragma target 3.0 |
||
83 | |||
84 | sampler2D _MainTex; |
||
85 | float _BlurSizeXY; |
||
86 | |||
87 | struct data { |
||
88 | float4 vertex : POSITION; |
||
89 | float3 normal : NORMAL; |
||
90 | }; |
||
91 | |||
92 | struct v2f { |
||
93 | float4 position : POSITION; |
||
94 | float4 screenPos : TEXCOORD0; |
||
95 | }; |
||
96 | |||
97 | v2f vert2(data i) |
||
98 | { |
||
99 | v2f o; |
||
100 | o.position = UnityObjectToClipPos(i.vertex); |
||
101 | o.screenPos = o.position; |
||
102 | |||
103 | return o; |
||
104 | } |
||
105 | |||
106 | half4 frag2( v2f i ) : COLOR |
||
107 | { |
||
108 | float2 screenPos = i.screenPos.xy / i.screenPos.w; |
||
109 | float depth = _BlurSizeXY * 0.0005; |
||
110 | |||
111 | screenPos.x = (screenPos.x + 1) * 0.5; |
||
112 | screenPos.y = 1 - (screenPos.y + 1) * 0.5; |
||
113 | |||
114 | //vertical |
||
115 | half4 sum = half4(0.0h,0.0h,0.0h,0.0h); |
||
116 | |||
117 | sum += tex2D( _MainTex, float2(screenPos.x, screenPos.y+5.0 * depth)) * 0.025; |
||
118 | sum += tex2D( _MainTex, float2(screenPos.x, screenPos.y-5.0 * depth)) * 0.025; |
||
119 | |||
120 | sum += tex2D( _MainTex, float2(screenPos.x, screenPos.y+4.0 * depth)) * 0.05; |
||
121 | sum += tex2D( _MainTex, float2(screenPos.x, screenPos.y-4.0 * depth)) * 0.05; |
||
122 | |||
123 | sum += tex2D( _MainTex, float2(screenPos.x, screenPos.y+3.0 * depth)) * 0.09; |
||
124 | sum += tex2D( _MainTex, float2(screenPos.x, screenPos.y-3.0 * depth)) * 0.09; |
||
125 | |||
126 | sum += tex2D( _MainTex, float2(screenPos.x, screenPos.y+2.0 * depth)) * 0.12; |
||
127 | sum += tex2D( _MainTex, float2(screenPos.x, screenPos.y-2.0 * depth)) * 0.12; |
||
128 | |||
129 | sum += tex2D( _MainTex, float2(screenPos.x, screenPos.y+1.0 * depth)) * 0.15; |
||
130 | sum += tex2D( _MainTex, float2(screenPos.x, screenPos.y-1.0 * depth)) * 0.15; |
||
131 | |||
132 | sum += tex2D( _MainTex, float2(screenPos.x, screenPos.y)) * 0.16; |
||
133 | |||
134 | return sum / 2; |
||
135 | } |
||
136 | |||
137 | ENDCG |
||
138 | } |
||
139 | |||
140 | } |
||
141 | |||
142 | Fallback Off |
||
143 | } |