gl renderer: Move more work to the vertex shaders
authorTimm Bäder <mail@baedert.org>
Tue, 17 Dec 2019 15:46:05 +0000 (16:46 +0100)
committerTimm Bäder <mail@baedert.org>
Tue, 7 Jan 2020 16:27:16 +0000 (17:27 +0100)
gsk/resources/glsl/inset_shadow.glsl
gsk/resources/glsl/unblurred_outset_shadow.glsl

index 1549800363d6df9e1a6fd1c1150fa2da769c9dc7..425b1403910417dcb1a6609ad091d25623da9a14 100644 (file)
@@ -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);
 }
index 27606f14761bb2a4cf71be849bde22cceb9c4ecb..f48288d05c575651f4fd0a117934c7a1b1772288 100644 (file)
@@ -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);
 }