diff options
author | David Thompson <dthompson2@worcester.edu> | 2021-09-07 20:12:35 -0400 |
---|---|---|
committer | David Thompson <dthompson2@worcester.edu> | 2021-09-08 07:24:43 -0400 |
commit | b63ce7f900ee6a4631eacd1db07b2c9c9be12780 (patch) | |
tree | 853f02e690a84de7de46382cf68f0788a84d2691 /data/shaders/path-fill-frag.glsl | |
parent | de3be995ed26f9ea78f7462095919ba08df2cd25 (diff) |
graphics: path: Add support for linear/radial gradient fills.
Diffstat (limited to 'data/shaders/path-fill-frag.glsl')
-rw-r--r-- | data/shaders/path-fill-frag.glsl | 28 |
1 files changed, 27 insertions, 1 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))); + } } |