-
Notifications
You must be signed in to change notification settings - Fork 6
/
08_TilePattern.fs
executable file
·101 lines (85 loc) · 1.81 KB
/
08_TilePattern.fs
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
89
90
91
92
93
94
95
96
97
98
99
100
101
// #SaturdayShader Week 7 : GradientEdges
// by Joseph Fiola (http://www.joefiola.com)
// 2015-10-03
// Based on Apply Matrices Inside Patterns example by Patricio Gonzalez Vivo on http://patriciogonzalezvivo.com/2015/thebookofshaders/09/
// Author @patriciogv ( patriciogonzalezvivo.com ) - 2015
/*{
"CREDIT": "Joseph Fiola",
"DESCRIPTION": "",
"CATEGORIES": [
"Generator", "Patterns", "Squares"
],
"INPUTS": [
{
"NAME": "Rotate",
"TYPE": "float",
"DEFAULT": 0.25,
"MIN": 0.0,
"MAX": 2.0
},
{
"NAME": "Offset",
"TYPE": "float",
"DEFAULT": 0.5,
"MIN": 0.0,
"MAX": 2.0
},
{
"NAME": "Tiles",
"TYPE": "float",
"DEFAULT": 4.0,
"MIN": -20.0,
"MAX": 20.0
},
{
"NAME": "pos",
"TYPE": "point2D",
"DEFAULT": [
0.5,
0.5
],
"MIN": [
0.0,
0.0
],
"MAX": [
1.0,
1.0
]
}
]
}*/
#ifdef GL_ES
precision mediump float;
#endif
#define PI 3.14159265358979323846
vec2 rotate2D(vec2 _st, float _angle){
_st -= pos;
_st = mat2(cos(_angle),-sin(_angle),
sin(_angle),cos(_angle)) * _st;
_st += Offset;
return _st;
}
vec2 tile(vec2 _st, float _zoom){
_st *= _zoom;
return fract(_st);
}
float box(vec2 _st, vec2 _size, float _smoothEdges){
_size = vec2(0.5)-_size*0.5;
vec2 aa = vec2(_smoothEdges*0.5);
vec2 uv = smoothstep(_size,_size+aa,_st);
uv *= smoothstep(_size,_size+aa,vec2(2.0)-_st);
return uv.x*uv.y;
}
void main(void){
vec2 st = gl_FragCoord.xy/RENDERSIZE.xy;
vec3 color = vec3(0.0);
// Divide the space in 4
st = tile(st,Tiles);
// Use a matrix to rotate the space 45 degrees
st = rotate2D(st,PI*Rotate);
// Draw a square
color = vec3(box(st,vec2(0.7),0.01));
// color = vec3(st,0.0);
gl_FragColor = vec4(color,1.0);
}