-
Notifications
You must be signed in to change notification settings - Fork 1
/
34.frag
92 lines (71 loc) · 1.82 KB
/
34.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
84
85
86
87
88
89
90
91
92
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 vesicaSDF(vec2 uv, float w){
vec2 offset = vec2(w*.5, 0.);
return max(circleSDF(uv+offset),
circleSDF(uv-offset));
}
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));
}
float heartSDF(vec2 uv){
uv -= vec2(0, .3);
float r = length(uv)*5.;
uv = normalize(uv);
return r - ((uv.y*pow(abs(uv.x), 0.67))/
(uv.y+1.5)-(2.)*uv.y+1.26);
}
//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;
float heart = heartSDF(uv);
color += fill(heart, 1.0);
color *= 1. - stroke(polySDF(uv, 3), .075, .03);
gl_FragColor = vec4(color, 1.);
}