-
Notifications
You must be signed in to change notification settings - Fork 6
/
01_Strobosphere.fs
executable file
·92 lines (75 loc) · 1.46 KB
/
01_Strobosphere.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
//#SaturdayShader
//2015-01 StroboSphere
//Based on code from http://patriciogonzalezvivo.com/2015/thebookofshaders/07/
/*{
"CREDIT": "by vjzef",
"DESCRIPTION": "Stroboscopic sphere",
"CATEGORIES": [
"Generator"
],
"INPUTS": [
{
"NAME": "pos",
"TYPE": "point2D",
"DEFAULT": [
0.5,
0.5
]
},
{
"NAME": "speed",
"TYPE": "float",
"DEFAULT": 4.0,
"MIN": -3.0,
"MAX": 10.0
},
{
"NAME": "scale1",
"TYPE": "float",
"DEFAULT": 0.0,
"MIN": 0.0,
"MAX": 2.0
},
{
"NAME": "scale2",
"TYPE": "float",
"DEFAULT": 1.0,
"MIN": 0.0,
"MAX": 1.0
},
{
"NAME": "outline",
"TYPE": "float",
"DEFAULT": 0.99,
"MIN": 0.0,
"MAX": 0.99
},
{
"NAME": "roundness",
"TYPE": "float",
"DEFAULT": 0.0,
"MIN": 0.0,
"MAX": 1.0
}
]
}*/
void main(){
vec2 st = gl_FragCoord.xy/RENDERSIZE.xy;
st.x *= RENDERSIZE.x/RENDERSIZE.y;
//not sure how to go about centering this to match the point2D XY, (Y is not perfectly centered)
st.y+= 0.0;
st -= (pos*5.0)/RENDERSIZE;
//st.x += -0.5;
vec3 color = vec3(0.0);
float d = 0.0;
// Remap the space to -1. to 1.
//st = st * 2.-1.;
// Make the distance field
d = length( max(abs(st)-roundness,0.) );
d = smoothstep(scale1,scale2,d);
color = vec3(fract(d*sin(d+TIME*speed)));
if (outline > 0.0)
color = step(outline, color);
// Visualize the distance field
gl_FragColor = vec4(color,1.0);
}