aboutsummaryrefslogtreecommitdiffstats
path: root/examples/shaders/rect.vert
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2020-12-11 18:05:26 +0100
committerDavid Robillard <d@drobilla.net>2020-12-11 18:05:26 +0100
commitf829cfa6306c5c6dae0d0a885664fe0fe5a1b0b7 (patch)
tree14e963b9feac2b3135eb1f800e716abbd08e0581 /examples/shaders/rect.vert
parent07c8253c2621daab8a08713aae557ae1fdea5df0 (diff)
downloadpugl-f829cfa6306c5c6dae0d0a885664fe0fe5a1b0b7.tar.gz
pugl-f829cfa6306c5c6dae0d0a885664fe0fe5a1b0b7.tar.bz2
pugl-f829cfa6306c5c6dae0d0a885664fe0fe5a1b0b7.zip
Make demo programs work from any directory, and install them
Diffstat (limited to 'examples/shaders/rect.vert')
-rw-r--r--examples/shaders/rect.vert35
1 files changed, 35 insertions, 0 deletions
diff --git a/examples/shaders/rect.vert b/examples/shaders/rect.vert
new file mode 100644
index 0000000..09f1917
--- /dev/null
+++ b/examples/shaders/rect.vert
@@ -0,0 +1,35 @@
+/* The vertex shader is trivial, but forwards scaled UV coordinates (in pixels)
+ to the fragment shader for drawing the border. */
+
+UBO(binding = 0) uniform UniformBufferObject
+{
+ mat4 projection;
+} ubo;
+
+layout(location = 0) in vec2 v_position;
+layout(location = 1) in vec2 v_origin;
+layout(location = 2) in vec2 v_size;
+layout(location = 3) in vec4 v_fillColor;
+
+INTER(location = 0) noperspective out vec2 f_uv;
+INTER(location = 1) noperspective out vec2 f_size;
+INTER(location = 2) noperspective out vec4 f_fillColor;
+
+void
+main()
+{
+ // clang-format off
+ mat4 m = mat4(v_size[0], 0.0, 0.0, 0.0,
+ 0.0, v_size[1], 0.0, 0.0,
+ 0.0, 0.0, 1.0, 0.0,
+ v_origin[0], v_origin[1], 0.0, 1.0);
+ // clang-format on
+
+ mat4 MVP = ubo.projection * m;
+
+ f_uv = v_position * v_size;
+ f_size = v_size;
+ f_fillColor = v_fillColor;
+
+ gl_Position = MVP * vec4(v_position, 0.0, 1.0);
+}