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
|
Wish the GPU compiles pipeline "line" {
{vec2 from vec2 to float thickness vec4 color} {
vec2 vertices[4] = vec2[4](
min(from, to) - thickness,
vec2(max(from.x, to.x) + thickness, min(from.y, to.y) - thickness),
vec2(min(from.x, to.x) - thickness, max(from.y, to.y) + thickness),
max(from, to) + thickness
);
return vertices[gl_VertexIndex];
} {
float l = length(to - from);
vec2 d = (to - from) / l;
vec2 q = (gl_FragCoord.xy - (from + to)*0.5);
q = mat2(d.x, -d.y, d.y, d.x) * q;
q = abs(q) - vec2(l, thickness)*0.5;
float dist = length(max(q, 0.0)) + min(max(q.x, q.y), 0.0);
return dist < 0.0 ? color : vec4(0, 0, 0, 0);
}
}
When /someone/ wishes to draw a stroke with /...options/ {
set points [dict get $options points]
set width [dict get $options width]
set color [getColor [dict get $options color]]
set instances [list]
for {set i 0} {$i < [expr {[llength $points] - 1}]} {incr i} {
set from [lindex $points $i]
set to [lindex $points [expr $i+1]]
lappend instances [list $from $to $width $color]
}
Wish the GPU draws pipeline "line" with instances $instances
}
|