diff options
| author | Andrés Cuervo <andrescuervor@gmail.com> | 2023-10-27 16:50:16 +0000 |
|---|---|---|
| committer | Andrés Cuervo <andrescuervor@gmail.com> | 2023-10-27 16:50:16 +0000 |
| commit | ccbcc1e7bf7dbf3fb118a4a06371fe4d0f2147ff (patch) | |
| tree | 9980a884f927312bf6e64a28f3066fb1dd146ce6 /virtual-programs/display/stroke.folk | |
| parent | Remove extraneous debug info (diff) | |
| parent | outline: Slight optimization (diff) | |
| download | folk-ccbcc1e7bf7dbf3fb118a4a06371fe4d0f2147ff.tar.gz folk-ccbcc1e7bf7dbf3fb118a4a06371fe4d0f2147ff.zip | |
Merge branch 'main' into ac/editor
Diffstat (limited to 'virtual-programs/display/stroke.folk')
| -rw-r--r-- | virtual-programs/display/stroke.folk | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/virtual-programs/display/stroke.folk b/virtual-programs/display/stroke.folk new file mode 100644 index 00000000..f212f471 --- /dev/null +++ b/virtual-programs/display/stroke.folk @@ -0,0 +1,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 +} |
