summaryrefslogtreecommitdiffstats
path: root/wgpu/src/shader
diff options
context:
space:
mode:
Diffstat (limited to 'wgpu/src/shader')
-rw-r--r--wgpu/src/shader/quad.frag37
-rw-r--r--wgpu/src/shader/quad.frag.spvbin0 -> 3196 bytes
-rw-r--r--wgpu/src/shader/quad.vert32
-rw-r--r--wgpu/src/shader/quad.vert.spvbin0 -> 2544 bytes
4 files changed, 69 insertions, 0 deletions
diff --git a/wgpu/src/shader/quad.frag b/wgpu/src/shader/quad.frag
new file mode 100644
index 00000000..987744db
--- /dev/null
+++ b/wgpu/src/shader/quad.frag
@@ -0,0 +1,37 @@
+#version 450
+
+layout(location = 0) in vec4 v_Color;
+layout(location = 1) in vec2 v_Pos;
+layout(location = 2) in vec2 v_Scale;
+layout(location = 3) in flat uint v_BorderRadius;
+
+layout(location = 0) out vec4 o_Color;
+
+float rounded(in vec2 frag_coord, in vec2 position, in vec2 size, float radius, float s)
+{
+ vec2 inner_size = size - vec2(radius, radius) * 2.0;
+ vec2 top_left = position + vec2(radius, radius);
+ vec2 bottom_right = top_left + inner_size;
+
+ vec2 top_left_distance = top_left - frag_coord;
+ vec2 bottom_right_distance = frag_coord - bottom_right;
+
+ vec2 distance = vec2(
+ max(max(top_left_distance.x, bottom_right_distance.x), 0),
+ max(max(top_left_distance.y, bottom_right_distance.y), 0)
+ );
+
+ float d = sqrt(distance.x * distance.x + distance.y * distance.y);
+
+ return 1.0 - smoothstep(radius - s, radius + s, d);
+}
+
+void main() {
+ float radius_alpha = 1.0;
+
+ if(v_BorderRadius > 0.0) {
+ radius_alpha = rounded(gl_FragCoord.xy, v_Pos, v_Scale, v_BorderRadius, 1.0);
+ }
+
+ o_Color = vec4(v_Color.xyz, v_Color.w * radius_alpha);
+}
diff --git a/wgpu/src/shader/quad.frag.spv b/wgpu/src/shader/quad.frag.spv
new file mode 100644
index 00000000..063287b3
--- /dev/null
+++ b/wgpu/src/shader/quad.frag.spv
Binary files differ
diff --git a/wgpu/src/shader/quad.vert b/wgpu/src/shader/quad.vert
new file mode 100644
index 00000000..b7c5cf3e
--- /dev/null
+++ b/wgpu/src/shader/quad.vert
@@ -0,0 +1,32 @@
+#version 450
+
+layout(location = 0) in vec2 v_Pos;
+layout(location = 1) in vec2 i_Pos;
+layout(location = 2) in vec2 i_Scale;
+layout(location = 3) in vec4 i_Color;
+layout(location = 4) in uint i_BorderRadius;
+
+layout (set = 0, binding = 0) uniform Globals {
+ mat4 u_Transform;
+};
+
+layout(location = 0) out vec4 o_Color;
+layout(location = 1) out vec2 o_Pos;
+layout(location = 2) out vec2 o_Scale;
+layout(location = 3) out uint o_BorderRadius;
+
+void main() {
+ mat4 i_Transform = mat4(
+ vec4(i_Scale.x, 0.0, 0.0, 0.0),
+ vec4(0.0, i_Scale.y, 0.0, 0.0),
+ vec4(0.0, 0.0, 1.0, 0.0),
+ vec4(i_Pos, 0.0, 1.0)
+ );
+
+ o_Color = i_Color;
+ o_Pos = i_Pos;
+ o_Scale = i_Scale;
+ o_BorderRadius = i_BorderRadius;
+
+ gl_Position = u_Transform * i_Transform * vec4(v_Pos, 0.0, 1.0);
+}
diff --git a/wgpu/src/shader/quad.vert.spv b/wgpu/src/shader/quad.vert.spv
new file mode 100644
index 00000000..f62a160c
--- /dev/null
+++ b/wgpu/src/shader/quad.vert.spv
Binary files differ