summaryrefslogtreecommitdiff
path: root/src/vector/shaders/cover.frag
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-30 21:34:41 -0300
committerGabriel Schneider <[email protected]>2026-11-12 13:22:02 -0300
commit2348776791e9dd17afeb12a06ba42a4a71917bcf (patch)
tree780c4b12b76c8b97a28408dd40944d65f159fdc7 /src/vector/shaders/cover.frag
parent590ba7b9b579b97e34b51ab7e3460ebc85713343 (diff)
downloadsketchbook-2348776791e9dd17afeb12a06ba42a4a71917bcf.tar.gz
sketchbook-2348776791e9dd17afeb12a06ba42a4a71917bcf.zip
sketchbook: a drawing layer on top, host fixes for replay and migration
Diffstat (limited to 'src/vector/shaders/cover.frag')
-rw-r--r--src/vector/shaders/cover.frag65
1 files changed, 0 insertions, 65 deletions
diff --git a/src/vector/shaders/cover.frag b/src/vector/shaders/cover.frag
deleted file mode 100644
index a57a916..0000000
--- a/src/vector/shaders/cover.frag
+++ /dev/null
@@ -1,65 +0,0 @@
-#version 450
-#extension GL_GOOGLE_include_directive : require
-// Paints the covered pixels. Mirrors vector/Paint.zig: `param` gives the
-// gradient parameter, `stop_color` the color at it. The uniform block is
-// generated from vector/layouts.zig.
-layout(location = 0) out vec4 out_color;
-
-#include "Paint.glsl"
-
-float offset_at(int i) {
- return paint.offsets[i / 4][i % 4];
-}
-
-vec4 premultiply(vec4 c) {
- return vec4(c.rgb * c.a, c.a);
-}
-
-float param(vec2 q) {
- vec2 g = vec2(dot(paint.row0.xyz, vec3(q, 1.0)), dot(paint.row1.xyz, vec3(q, 1.0)));
- vec2 p0 = paint.points.xy;
- vec2 p1 = paint.points.zw;
- float t = 0.0;
- if (paint.row0.w < 1.5) {
- vec2 dir = p1 - p0;
- float len2 = dot(dir, dir);
- t = len2 > 0.0 ? dot(g - p0, dir) / len2 : 0.0;
- } else {
- // Where the ray from the focus through g meets the circle.
- vec2 dq = g - p1;
- vec2 cf = p1 - p0;
- float a = dot(dq, dq);
- if (a > 0.0) {
- float b = dot(dq, cf);
- float c = dot(cf, cf) - paint.extra.x * paint.extra.x;
- float s = (-b + sqrt(max(b * b - a * c, 0.0))) / a;
- t = s > 0.0 ? 1.0 / s : 1.0;
- }
- }
- if (paint.row1.w < 0.5) return clamp(t, 0.0, 1.0);
- if (paint.row1.w < 1.5) {
- float r = mod(t, 2.0);
- return r > 1.0 ? 2.0 - r : r;
- }
- return t - floor(t);
-}
-
-vec4 stop_color(float t) {
- int count = int(paint.extra.z);
- if (count == 0) return vec4(0.0);
- if (t <= offset_at(0)) return premultiply(paint.colors[0]);
- for (int i = 1; i < count; i++) {
- float b = offset_at(i);
- if (t <= b) {
- float a = offset_at(i - 1);
- float u = b > a ? (t - a) / (b - a) : 1.0;
- return premultiply(mix(paint.colors[i - 1], paint.colors[i], u));
- }
- }
- return premultiply(paint.colors[count - 1]);
-}
-
-void main() {
- vec4 c = paint.row0.w < 0.5 ? paint.color : stop_color(param(gl_FragCoord.xy));
- out_color = c * paint.extra.y;
-}