-
Notifications
You must be signed in to change notification settings - Fork 13
/
Pixelate.shader
57 lines (48 loc) · 1.2 KB
/
Pixelate.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
Shader "LX/Pixelate"
{
Properties
{
_MainTex ("Base (RGB)", 2D) = "white" {}
}
CGINCLUDE
#include "UnityCG.cginc"
sampler2D _MainTex;
int _PixelSize;
int _AddStrip;
half2 stitch(half2 uv)
{
half2 screenPos = floor(uv * _ScreenParams.xy);
half2 reminder;
reminder.y = (screenPos.y - screenPos.x) % _PixelSize;
reminder.x = (screenPos.y + screenPos.x) % _PixelSize;
return reminder;
}
half4 pixel(half2 uv)
{
half2 screenPos = floor(uv * _ScreenParams.xy / _PixelSize) * _PixelSize;
return tex2D(_MainTex, screenPos / _ScreenParams.xy);
}
half4 frag(v2f_img i) : SV_Target
{
half2 reminder = stitch(i.uv);
half4 color = pixel(i.uv);
return (reminder.y == 0 || reminder.x == 0)&&_AddStrip==1 ? half4(0, 0, 0, 1) : color;
}
ENDCG
SubShader
{
ZTest Always Cull Off ZWrite Off
Fog
{
Mode off
}
Pass
{
CGPROGRAM
#pragma vertex vert_img
#pragma fragment frag
ENDCG
}
}
FallBack off
}