[gtk/wip/baedert/gl-rework: 93/127] gl renderer: Compute final color in vertex shader



commit f0572ed0f2cb1dba7d35cfce8adfeedce0134873
Author: Timm Bäder <mail baedert org>
Date:   Tue Dec 17 15:55:24 2019 +0100

    gl renderer: Compute final color in vertex shader
    
    This is a very often used shader. No need to to do this for every
    fragment.

 gsk/resources/glsl/color.glsl       | 17 +++++++++++------
 gsk/resources/glsl/preamble.vs.glsl |  1 +
 2 files changed, 12 insertions(+), 6 deletions(-)
---
diff --git a/gsk/resources/glsl/color.glsl b/gsk/resources/glsl/color.glsl
index dcd65100a3..c80f501ac0 100644
--- a/gsk/resources/glsl/color.glsl
+++ b/gsk/resources/glsl/color.glsl
@@ -1,16 +1,21 @@
 // VERTEX_SHADER:
+uniform vec4 u_color;
+
+_OUT_ vec4 final_color;
+
 void main() {
   gl_Position = u_projection * u_modelview * vec4(aPosition, 0.0, 1.0);
+
+  final_color = u_color;
+  // Pre-multiply alpha
+  final_color.rgb *= final_color.a;
+  final_color *= u_alpha;
 }
 
 // FRAGMENT_SHADER:
-uniform vec4 u_color;
+_IN_ vec4 final_color;
 
 void main() {
-  vec4 color = u_color;
-
-  // Pre-multiply alpha
-  color.rgb *= color.a;
-  setOutputColor(color * u_alpha);
+  setOutputColor(final_color);
 }
 
diff --git a/gsk/resources/glsl/preamble.vs.glsl b/gsk/resources/glsl/preamble.vs.glsl
index 6b18bb7ce2..887482fee7 100644
--- a/gsk/resources/glsl/preamble.vs.glsl
+++ b/gsk/resources/glsl/preamble.vs.glsl
@@ -1,5 +1,6 @@
 uniform mat4 u_projection;
 uniform mat4 u_modelview;
+uniform float u_alpha;
 
 #if GSK_GLES
 #define _OUT_ varying


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]