-
Notifications
You must be signed in to change notification settings - Fork 1
/
30.frag
83 lines (63 loc) · 1.7 KB
/
30.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
78
79
80
81
82
83
precision mediump float;
uniform vec2 resolution;
uniform float time;
float PI = 3.14159265;
float TAU = 6.28318;
// Signed Distance Fields
float rectSDF(vec2 st, vec2 size){
return max(abs(st).x * size.x, abs(st).y * size.y);
}
float crossSDF(vec2 st, float s){
vec2 size = vec2(.25, s);
return min(rectSDF(st, size.xy),
rectSDF(st, size.yx));
}
float circleSDF(vec2 uv){
return length(uv);
}
float raySDF(vec2 uv, int count){
return fract(atan(uv.x, uv.y)/TAU*float(count));
}
float polySDF(vec2 uv, int vertices){
float a = atan(uv.x, uv.y)+PI;
float r = length(uv);
float v = TAU / float(vertices);
return cos(floor(.5+a/v)*v-a)*r;
}
float starSDF(vec2 uv, int V, float s){
float a = atan(uv.y, uv.x)/TAU;
float seg = a * float(V);
a = ((floor(seg) + .5)/float(V) +
mix(s, -s, step(.5, fract(seg)))) * TAU;
return abs(dot(vec2(cos(a), sin(a)),uv));
}
//ENDSDF
//STEPPERS
float fill(float x, float size){
return 1.-step(size, x);
}
float stroke(float x, float s, float w){
float d = step(s, x+w*.5) -
step(s, x-w*.5);
return clamp(d, 0., 1.);
}
float flip(float v, float pct){
return mix(v, 1.-v, pct);
}
vec2 rotate(vec2 uv, float angle){
return mat2(cos(angle), -sin(angle),
sin(angle), cos(angle)) * uv;
}
//ENDSTEPPERS
void main(){
vec3 color = vec3(0.);
vec2 uv = (gl_FragCoord.xy * 2.0 - resolution) / resolution.y;
color += fill(raySDF(rotate(uv, PI/5.), 6), .2);
float star = starSDF(rotate(uv, PI/2.), 6, .1);
float small_star = starSDF(uv, 6, .1);
color += fill(star, .3);
color *= 1. - stroke(star, .26, .03);
color *= 1. - stroke(small_star, .11, .03);
color *= 1. - stroke(star, .31, .03);
gl_FragColor = vec4(color, 1.);
}