[gtk/wip/baedert/gl-rework: 25/47] gl renderer: Move more work to the vertex shaders



commit 80f32cecd6872f98b7f90c292e7f3ee907a6c8b5
Author: Timm Bäder <mail baedert org>
Date:   Tue Dec 17 16:46:05 2019 +0100

    gl renderer: Move more work to the vertex shaders

 gsk/resources/glsl/inset_shadow.glsl            | 21 +++++++++++++++------
 gsk/resources/glsl/unblurred_outset_shadow.glsl | 23 +++++++++++++++--------
 2 files changed, 30 insertions(+), 14 deletions(-)
---
diff --git a/gsk/resources/glsl/inset_shadow.glsl b/gsk/resources/glsl/inset_shadow.glsl
index 1549800363..425b140391 100644
--- a/gsk/resources/glsl/inset_shadow.glsl
+++ b/gsk/resources/glsl/inset_shadow.glsl
@@ -1,25 +1,34 @@
 // 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;
+  final_color.rgb *= final_color.a;
+  final_color *= u_alpha;
 }
 
 // FRAGMENT_SHADER:
 uniform float u_spread;
-uniform vec4 u_color;
 uniform vec2 u_offset;
 uniform vec4[3] u_outline_rect;
 
+_IN_ vec4 final_color;
+
 void main() {
   vec4 f = gl_FragCoord;
+  vec4 color;
 
   f.x += u_viewport.x;
   f.y = (u_viewport.y + u_viewport.w) - f.y;
 
   RoundedRect outside = create_rect(u_outline_rect);
   RoundedRect inside = rounded_rect_shrink(outside, vec4(u_spread));
-  vec4 color = vec4(u_color.rgb * u_color.a, u_color.a);
-  color = color * clamp (rounded_rect_coverage (outside, f.xy) -
-                         rounded_rect_coverage (inside, f.xy - u_offset),
-                         0.0, 1.0);
-  setOutputColor(color * u_alpha);
+  color = final_color * clamp (rounded_rect_coverage (outside, f.xy) -
+                               rounded_rect_coverage (inside, f.xy - u_offset),
+                               0.0, 1.0);
+  setOutputColor(color);
 }
diff --git a/gsk/resources/glsl/unblurred_outset_shadow.glsl b/gsk/resources/glsl/unblurred_outset_shadow.glsl
index 27606f1476..f48288d05c 100644
--- a/gsk/resources/glsl/unblurred_outset_shadow.glsl
+++ b/gsk/resources/glsl/unblurred_outset_shadow.glsl
@@ -1,27 +1,34 @@
 // 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;
+  final_color.rgb *= final_color.a;
+  final_color *= u_alpha;
 }
 
 // FRAGMENT_SHADER:
 uniform float u_spread;
-uniform vec4 u_color;
 uniform vec2 u_offset;
 uniform vec4[3] u_outline_rect;
 
+_IN_ vec4 final_color;
+
 void main() {
   vec4 f = gl_FragCoord;
+  vec4 color;
 
   f.x += u_viewport.x;
   f.y = (u_viewport.y + u_viewport.w) - f.y;
 
-
   RoundedRect inside = create_rect(u_outline_rect);
   RoundedRect outside = rounded_rect_shrink(inside, vec4(- u_spread));
-
-  vec4 color = vec4(u_color.rgb * u_color.a, u_color.a);
-  color = color * clamp (rounded_rect_coverage (outside, f.xy - u_offset) -
-                         rounded_rect_coverage (inside, f.xy),
-                         0.0, 1.0);
-  setOutputColor(color * u_alpha);
+  color = final_color * clamp (rounded_rect_coverage (outside, f.xy - u_offset) -
+                               rounded_rect_coverage (inside, f.xy),
+                               0.0, 1.0);
+  setOutputColor(color);
 }


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