From 0c4a79dd8da6f002220533281abc3d45ebfd391d Mon Sep 17 00:00:00 2001 From: David Thompson Date: Wed, 8 Sep 2021 07:38:07 -0400 Subject: graphics: path: Move gradient matrix multiplication to vertex shader. *Much* cheaper to do this per-vertex than per-fragment. --- data/shaders/path-fill-frag.glsl | 8 +++----- data/shaders/path-fill-vert.glsl | 3 ++- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/data/shaders/path-fill-frag.glsl b/data/shaders/path-fill-frag.glsl index e336e76..ba9c5a6 100644 --- a/data/shaders/path-fill-frag.glsl +++ b/data/shaders/path-fill-frag.glsl @@ -15,7 +15,6 @@ in vec2 fragPosition; uniform int mode; uniform vec4 color; uniform vec4 endColor; -uniform mat3 gradientMatrix; uniform vec2 gradientRange; uniform float radialGradientRatio; @@ -34,10 +33,9 @@ void main(void) { if(mode == 0) { // solid color fragColor = color; } else if(mode == 1) { // linear gradient - float x = (gradientMatrix * vec3(fragPosition, 1.0)).x; - fragColor = gradientMix(x); + fragColor = gradientMix(fragPosition.x); } else if(mode == 2) { // radial gradient - vec2 p = (gradientMatrix * vec3(fragPosition, 1.0)).xy; - fragColor = gradientMix(length(p * vec2(1.0, radialGradientRatio))); + vec2 p = fragPosition * vec2(1.0, radialGradientRatio); + fragColor = gradientMix(length(p)); } } diff --git a/data/shaders/path-fill-vert.glsl b/data/shaders/path-fill-vert.glsl index 1752978..d66bb14 100644 --- a/data/shaders/path-fill-vert.glsl +++ b/data/shaders/path-fill-vert.glsl @@ -16,6 +16,7 @@ out vec2 fragPosition; uniform mat4 mvp; uniform vec4 color; +uniform mat3 gradientMatrix; void main(void) { // Short-circuit because the fragments will just be discarded @@ -23,7 +24,7 @@ void main(void) { if (color.a <= 0.0) { gl_Position = vec4(0.0, 0.0, 0.0, 1.0); } else { - fragPosition = position; + fragPosition = (gradientMatrix * vec3(position, 1.0)).xy; gl_Position = mvp * vec4(position, 0.0, 1.0); } } -- cgit v1.2.3