Skip to content

Commit dd6eab9

Browse files
authored
Create Matrix.shader
1 parent 8e6159b commit dd6eab9

File tree

1 file changed

+105
-0
lines changed

1 file changed

+105
-0
lines changed

Matrix.shader

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
Shader "Custom/Matrix"
2+
{
3+
Properties
4+
{
5+
_Grid ("Grid", range(1, 50.)) = 30.
6+
_SpeedMax ("Speed Max", range(0, 30.)) = 20.
7+
_SpeedMin ("Speed Min", range(0, 10.)) = 2.
8+
_Density ("Density", range(0, 30.)) = 5.
9+
}
10+
11+
SubShader
12+
{
13+
Tags { "RenderType"="Opaque" }
14+
15+
Pass
16+
{
17+
CGPROGRAM
18+
#pragma vertex vert_img
19+
#pragma fragment frag
20+
#include "UnityCG.cginc"
21+
22+
float noise(float x)
23+
{
24+
return frac(sin(x) * 43758.5453);
25+
}
26+
27+
float noise(float2 vect)
28+
{
29+
return frac(sin(dot(vect, float2(5372.156, 8452.751))) * 1643.268);
30+
}
31+
32+
float texelValue(float2 ipos, float n){
33+
for(float i = 0.; i < 5.; i++){
34+
for(float j = 0.; j < 3.; j++)
35+
{
36+
if (i == ipos.y && j == ipos.x ) {
37+
return step(1., fmod(n, 2.));
38+
}
39+
40+
n = ceil(n / 2.);
41+
}
42+
}
43+
return 0.;
44+
}
45+
46+
float _Density;
47+
48+
float char(float2 st, float n){
49+
st.x = st.x * 2. - .5;
50+
st.y = st.y * 1.2 - .1;
51+
52+
float2 ipos = floor(st * float2(3., 5.));
53+
54+
n = floor(fmod(n, 20. + _Density));
55+
56+
float digit = 0.0;
57+
58+
if (n < 1. ) { digit = 9712.; }
59+
else if (n < 2. ) { digit = 21158.0; }
60+
else if (n < 3. ) { digit = 25231.0; }
61+
else if (n < 4. ) { digit = 23187.0; }
62+
else if (n < 5. ) { digit = 23498.0; }
63+
else if (n < 6. ) { digit = 31702.0; }
64+
else if (n < 7. ) { digit = 25202.0; }
65+
else if (n < 8. ) { digit = 30163.0; }
66+
else if (n < 9. ) { digit = 18928.0; }
67+
else if (n < 10. ) { digit = 23531.0; }
68+
else if (n < 11. ) { digit = 29128.0; }
69+
else if (n < 12. ) { digit = 17493.0; }
70+
else if (n < 13. ) { digit = 7774.0; }
71+
else if (n < 14. ) { digit = 31141.0; }
72+
else if (n < 15. ) { digit = 29264.0; }
73+
else if (n < 16. ) { digit = 3641.0; }
74+
else if (n < 17. ) { digit = 31315.0; }
75+
else if (n < 18. ) { digit = 31406.0; }
76+
else if (n < 19. ) { digit = 30864.0; }
77+
else if (n < 20. ) { digit = 31208.0; }
78+
else { digit = 1.0; }
79+
80+
float tex = texelValue(ipos, digit);
81+
82+
float2 borders = float2(1., 1.);
83+
borders *= step(0., st) * step(0., 1. - st);
84+
85+
return step(.1, 1. - tex) * borders.x * borders.y;
86+
}
87+
88+
float _Grid;
89+
float _SpeedMax;
90+
float _SpeedMin;
91+
92+
fixed4 frag (v2f_img i) : SV_Target
93+
{
94+
float2 ipos = floor(i.uv * _Grid);
95+
float2 fpos = frac(i.uv * _Grid);
96+
97+
ipos.y += floor(_Time.y * max(_SpeedMin, _SpeedMax * noise(ipos.x)));
98+
float charNum = noise(ipos);
99+
float val = char(fpos, (20. + _Density) * charNum);
100+
return fixed4(0, val, 0, 1.0);
101+
}
102+
ENDCG
103+
}
104+
}
105+
}

0 commit comments

Comments
 (0)