-
Notifications
You must be signed in to change notification settings - Fork 0
/
13_CrossesTextureBackground.frag
77 lines (56 loc) · 1.58 KB
/
13_CrossesTextureBackground.frag
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
#ifdef GL_ES
precision highp float;
#endif
uniform vec2 u_resolution;
uniform vec2 u_mouse;
uniform float u_time;
uniform sampler2D t1;
uniform vec2 t1Resolution;
float plot(float y, float x, bool b){
if(b){
return step(y,x)-step(y,x-0.02);
}
return step(y,x);
}
float flip_x(float y, float x, bool b){
vec2 st0 = vec2(x,y);
st0-=0.5;
st0=mat2(1.,0.,0.,-1.)*st0;
st0+=0.5;
st0.y = st0.y-1.;
return plot(st0.y,st0.x,b);
}
vec2 rotateUV(vec2 uv, float rotation)
{
float mid = 0.5;
return vec2(
cos(rotation) * (uv.x - mid) + sin(rotation) * (uv.y - mid) + mid,
cos(rotation) * (uv.y - mid) - sin(rotation) * (uv.x - mid) + mid
);
}
const float PI = 3.1415926535;
const float alpha = PI/4.;
void main(){
vec2 st = gl_FragCoord.xy / u_resolution;
//Make 50 tiles
vec2 _st = st * 50.;
_st.x *= 2.;
_st = fract(_st);
//rotation matrix with positioning in the middle of each tile
mat2 rotate = mat2(
cos(alpha)*(_st.x - 0.5),sin(alpha)*(_st.y - 0.5),
-sin(alpha)*(_st.y - 0.5),cos(alpha)*(_st.x - 0.5));
_st = rotateUV(_st,alpha);
//Scale each tile
mat2 scale = mat2(0.7,0.,0.,0.7);
_st -= 0.5;
_st = scale * _st;
_st += 0.5;
float cr =
step(0.4,_st.x)*step(0.1,_st.y)*
step(0.4,1.-_st.x)*step(0.1,1.-_st.y)+
step(0.1,_st.x)*step(0.4,_st.y)*
step(0.1,1.-_st.x)*step(0.4,1.-_st.y);
vec4 tx = texture2D(t1,st);
gl_FragColor = vec4(cr*tx);
}