forked from grigM/ISF-shaders-collection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path31_Twist.fs
executable file
·142 lines (121 loc) · 2.62 KB
/
31_Twist.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
//Based on "Twist" Shadertoy by fb39ca4 - https://www.shadertoy.com/view/XsXXDH
//Inspired by Matthew DiVito's gifs
//http://cargocollective.com/matthewdivito/Animated-Gifs-02
/*{
"CREDIT": "Joseph Fiola, Matthew DiVito, Shadertoy user fb39ca4",
"DESCRIPTION": "",
"CATEGORIES": [
"Generator"
],
"INPUTS": [
{
"NAME": "iterations",
"TYPE": "float",
"DEFAULT": 30.0,
"MIN": 0.0,
"MAX": 60.0
},
{
"NAME": "zoom",
"TYPE": "float",
"DEFAULT": 3.0,
"MIN": 0.125,
"MAX": 3.0
},
{
"NAME": "twist",
"TYPE": "float",
"DEFAULT": 0.51,
"MIN": 0.0,
"MAX": 1.0
},
{
"NAME": "offset",
"TYPE": "float",
"DEFAULT": 1.0,
"MIN": 0.0,
"MAX": 1.0
},
{
"NAME": "rotation",
"TYPE": "float",
"DEFAULT": 0.0,
"MIN": 0.0,
"MAX": 1.0
},
{
"NAME": "linesOffset",
"TYPE": "float",
"DEFAULT": 1.0,
"MIN": -10.0,
"MAX": 10.0
},
{
"NAME": "fade",
"TYPE": "float",
"DEFAULT": 1.0,
"MIN": 0.0,
"MAX": 1.0
},
{
"NAME": "stripes",
"TYPE": "bool",
"DEFAULT": true
},
{
"NAME": "invert",
"TYPE": "bool",
"DEFAULT": false
},
{
"NAME": "pos",
"TYPE": "point2D",
"DEFAULT": [
0.5,
0.5
],
"MIN": [
0.0,
0.0
],
"MAX": [
1.0,
1.0
]
}
]
}*/
const float PI = 3.14159265;
vec2 rotate(vec2 v, float a) {
float sinA = sin(a);
float cosA = cos(a);
return vec2(v.x * cosA - v.y * sinA, v.y * cosA + v.x * sinA);
}
float square(vec2 uv, float d) {
return max(abs(uv.x), abs(uv.y)) - d;
}
void main()
{
vec2 uv = gl_FragCoord.xy / RENDERSIZE.xy;
uv -= vec2(pos);
uv.x *= RENDERSIZE.x / RENDERSIZE.y;
uv *= zoom;
uv = rotate(uv, rotation * PI);
float blurAmount = -5.0 / RENDERSIZE.y * (zoom * 0.5);
float time = twist;
gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);
for (int i = 0; i < 60; i++) {
float n = float(i);
float size = 1.0 - n / iterations;
float rotateAmount = (n * 0.5 + 0.25) * PI * 2.0;
gl_FragColor.rgb = mix(gl_FragColor.rgb, vec3(1.0), smoothstep(0.0, blurAmount, square(rotate(uv, -rotateAmount * time), size)));
float blackOffset = mix(linesOffset / 4.0, linesOffset / 2.0, n / (iterations * offset)) / (iterations * offset);
gl_FragColor.rgb = mix(gl_FragColor.rgb, vec3(0.0), smoothstep(0.0, blurAmount, square(rotate(uv, -(rotateAmount + PI / 2.0) * time), size - blackOffset)));
if (stripes) {
gl_FragColor.rgb = vec3(gl_FragColor.rgb * -1.0 + 1.0) * fade;
} else {
gl_FragColor.rgb = gl_FragColor.rgb * fade;
}
}
if (invert) gl_FragColor.rgb = vec3(gl_FragColor.rgb *-1.0 + 1.0);
}