-
Notifications
You must be signed in to change notification settings - Fork 1
/
20.frag
68 lines (50 loc) · 1.21 KB
/
20.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
precision mediump float;
uniform vec2 resolution;
float PI = 3.14159265;
// 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 triSDF(vec2 uv){
return max(abs(uv.x) * .866025 + uv.y * .5,
-uv.y * .5);
}
float rhombSDF(vec2 uv){
return max(triSDF(uv),
triSDF(vec2(uv.x, -uv.y)));
}
float circleSDF(vec2 uv){
return length(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;
uv = rotate(uv, PI/4.);
color += fill(rectSDF(uv, vec2(1.)), .5);
color -= stroke(uv.x, 0., .05);
color -= stroke(uv.y, 0., .05);
gl_FragColor = vec4(color, 1.);
}