summaryrefslogtreecommitdiff
path: root/data/shaders
diff options
context:
space:
mode:
Diffstat (limited to 'data/shaders')
-rw-r--r--data/shaders/path-fill-frag.glsl28
-rw-r--r--data/shaders/path-fill-vert.glsl9
2 files changed, 35 insertions, 2 deletions
diff --git a/data/shaders/path-fill-frag.glsl b/data/shaders/path-fill-frag.glsl
index 3af191f..e336e76 100644
--- a/data/shaders/path-fill-frag.glsl
+++ b/data/shaders/path-fill-frag.glsl
@@ -6,12 +6,38 @@ out vec4 fragColor;
#define fragColor gl_FragColor
#endif
+#ifdef GLSL120
+attribute vec2 fragPosition;
+#else
+in vec2 fragPosition;
+#endif
+
+uniform int mode;
uniform vec4 color;
+uniform vec4 endColor;
+uniform mat3 gradientMatrix;
+uniform vec2 gradientRange;
+uniform float radialGradientRatio;
+
+vec4 gradientMix(float x) {
+ float start = gradientRange.x;
+ float end = gradientRange.y;
+ float t = clamp((x - start) / (end - start), 0.0, 1.0);
+ return mix(color, endColor, t);
+}
void main(void) {
if (color.a <= 0.0) {
discard;
}
- fragColor = color;
+ if(mode == 0) { // solid color
+ fragColor = color;
+ } else if(mode == 1) { // linear gradient
+ float x = (gradientMatrix * vec3(fragPosition, 1.0)).x;
+ fragColor = gradientMix(x);
+ } else if(mode == 2) { // radial gradient
+ vec2 p = (gradientMatrix * vec3(fragPosition, 1.0)).xy;
+ fragColor = gradientMix(length(p * vec2(1.0, radialGradientRatio)));
+ }
}
diff --git a/data/shaders/path-fill-vert.glsl b/data/shaders/path-fill-vert.glsl
index d95b71b..1752978 100644
--- a/data/shaders/path-fill-vert.glsl
+++ b/data/shaders/path-fill-vert.glsl
@@ -8,6 +8,12 @@ in vec2 position;
attribute vec2 position;
#endif
+#ifdef GLSL120
+varying vec2 fragPosition;
+#else
+out vec2 fragPosition;
+#endif
+
uniform mat4 mvp;
uniform vec4 color;
@@ -17,6 +23,7 @@ void main(void) {
if (color.a <= 0.0) {
gl_Position = vec4(0.0, 0.0, 0.0, 1.0);
} else {
- gl_Position = mvp * vec4(position.xy, 0.0, 1.0);
+ fragPosition = position;
+ gl_Position = mvp * vec4(position, 0.0, 1.0);
}
}