summaryrefslogtreecommitdiff
path: root/gsk/gl/resources/color_matrix.glsl
diff options
context:
space:
mode:
Diffstat (limited to 'gsk/gl/resources/color_matrix.glsl')
-rw-r--r--gsk/gl/resources/color_matrix.glsl25
1 files changed, 25 insertions, 0 deletions
diff --git a/gsk/gl/resources/color_matrix.glsl b/gsk/gl/resources/color_matrix.glsl
new file mode 100644
index 0000000000..79cb36434e
--- /dev/null
+++ b/gsk/gl/resources/color_matrix.glsl
@@ -0,0 +1,25 @@
+// VERTEX_SHADER:
+void main() {
+ gl_Position = u_projection * u_modelview * vec4(aPosition, 0.0, 1.0);
+
+ vUv = vec2(aUv.x, aUv.y);
+}
+
+// FRAGMENT_SHADER:
+uniform mat4 u_color_matrix;
+uniform vec4 u_color_offset;
+
+void main() {
+ vec4 color = GskTexture(u_source, vUv);
+
+ // Un-premultilpy
+ if (color.a != 0.0)
+ color.rgb /= color.a;
+
+ color = u_color_matrix * color + u_color_offset;
+ color = clamp(color, 0.0, 1.0);
+
+ color.rgb *= color.a;
+
+ gskSetOutputColor(color * u_alpha);
+}