-
Notifications
You must be signed in to change notification settings - Fork 7
/
11_Bricked.fs
executable file
·153 lines (129 loc) · 2.62 KB
/
11_Bricked.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
// SaturdayShader Week 11 : Bricked
// by Joseph Fiola (http://www.joefiola.com)
// 2015-10-31
// Based on Patricio Gonzalez Vivo's "Apply Matrices Inside Patterns" example
// on http://patriciogonzalezvivo.com/2015/thebookofshaders/09/ @patriciogv ( patriciogonzalezvivo.com ) - 2015
/*{
"CREDIT": "Joseph Fiola",
"DESCRIPTION": "",
"CATEGORIES": [
"Generator", "Patterns", "Squares", "Warp"
],
"INPUTS": [
{
"NAME": "invert",
"TYPE": "bool",
"DEFAULT": 0.0
},
{
"NAME": "tile",
"TYPE": "float",
"DEFAULT": 50.0,
"MIN": 0.0,
"MAX": 50.0
},
{
"NAME": "offset",
"TYPE": "float",
"DEFAULT": 0.5,
"MIN": 0.0,
"MAX": 1.0
},
{
"NAME": "strokeWidth",
"TYPE": "float",
"DEFAULT": 0.9,
"MIN": 0.0,
"MAX": 0.99
},
{
"NAME": "gradient",
"TYPE": "float",
"DEFAULT": 1e-4,
"MIN": 1e-4,
"MAX": 0.5
},
{
"NAME": "evenRows",
"TYPE": "float",
"DEFAULT": 1.0,
"MIN": 0.0,
"MAX": 5.0
},
{
"NAME": "oddRows",
"TYPE": "float",
"DEFAULT": 2.0,
"MIN": 0.0,
"MAX": 5.0
},
{
"NAME": "rotate",
"TYPE": "float",
"DEFAULT": 0.5,
"MIN": 0.0,
"MAX": 1.0
},
{
"NAME": "warp",
"TYPE": "float",
"DEFAULT": 1.0,
"MIN": 0.0,
"MAX": 2.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 -= 0.5;
_st = mat2(cos(_angle),-sin(_angle),
sin(_angle),cos(_angle)) * _st;
_st += 0.5;
return _st;
}
vec2 brickTile(vec2 _st, float _zoom){
_st *= _zoom;
// Here is where the offset is happening
_st.x += step(evenRows, mod(_st.y,oddRows)) * offset;
return fract(_st);
}
float box(vec2 _st, vec2 _size){
_size = vec2(0.5)-_size*0.5;
vec2 uv = smoothstep(_size,_size+vec2(gradient),_st);
uv *= smoothstep(_size,_size+vec2(gradient),vec2(1.0)-_st);
return uv.x*uv.y;
}
void main(void){
vec2 st = gl_FragCoord.xy/RENDERSIZE;
vec3 color = vec3(0.0);
st *= rotate2D(st,PI*warp);
st -= vec2(pos); // move the origin - vec2(0.5) will center it
st.x *= RENDERSIZE.x/RENDERSIZE.y; // make things 1:1 ratio regardless of canvas ratio
// Apply the brick tiling
st = brickTile(st,tile);
st = rotate2D(st,PI*rotate);
color = vec3(box(st,vec2(strokeWidth)));
// invert colors
if (invert)
{color = vec3(color *-1.0 + 1.0);}
gl_FragColor = vec4(color,1.0);
}