[gtk/wip/baedert/gl-rework: 14/47] gl renderer: Move work to the gradient vertex shader
- From: Timm Bäder <baedert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/baedert/gl-rework: 14/47] gl renderer: Move work to the gradient vertex shader
- Date: Sun, 22 Dec 2019 05:43:06 +0000 (UTC)
commit 8afd39c3143859e7ba202a9b639ffdfbd48b3ff3
Author: Timm Bäder <mail baedert org>
Date: Tue Dec 17 12:20:18 2019 +0100
gl renderer: Move work to the gradient vertex shader
No need to do this stuff once per fragment.
gsk/resources/glsl/linear_gradient.glsl | 35 ++++++++++++++++++++++-----------
1 file changed, 23 insertions(+), 12 deletions(-)
---
diff --git a/gsk/resources/glsl/linear_gradient.glsl b/gsk/resources/glsl/linear_gradient.glsl
index f0ba46517f..0b5fefce83 100644
--- a/gsk/resources/glsl/linear_gradient.glsl
+++ b/gsk/resources/glsl/linear_gradient.glsl
@@ -1,16 +1,35 @@
-// VERTEX_SHADER:
+// VERTEX_SHADER
+uniform vec2 u_start_point;
+uniform vec2 u_end_point;
+
+_OUT_ vec2 startPoint;
+_OUT_ vec2 endPoint;
+_OUT_ float maxDist;
+_OUT_ vec2 gradient;
+_OUT_ float gradientLength;
+
void main() {
gl_Position = u_projection * u_modelview * vec4(aPosition, 0.0, 1.0);
- vUv = vec2(aUv.x, aUv.y);
+ startPoint = (u_modelview * vec4(u_start_point, 0, 1)).xy;
+ endPoint = (u_modelview * vec4(u_end_point, 0, 1)).xy;
+ maxDist = length(endPoint - startPoint);
+
+ // Gradient direction
+ gradient = endPoint - startPoint;
+ gradientLength = length(gradient);
}
// FRAGMENT_SHADER:
uniform vec4 u_color_stops[8];
uniform float u_color_offsets[8];
uniform int u_num_color_stops;
-uniform vec2 u_start_point;
-uniform vec2 u_end_point;
+
+_IN_ vec2 startPoint;
+_IN_ vec2 endPoint;
+_IN_ float maxDist;
+_IN_ vec2 gradient;
+_IN_ float gradientLength;
vec4 fragCoord() {
vec4 f = gl_FragCoord;
@@ -20,17 +39,9 @@ vec4 fragCoord() {
}
void main() {
- vec2 startPoint = (u_modelview * vec4(u_start_point, 0, 1)).xy;
- vec2 endPoint = (u_modelview * vec4(u_end_point, 0, 1)).xy;
- float maxDist = length(endPoint - startPoint);
-
// Position relative to startPoint
vec2 pos = fragCoord().xy - startPoint;
- // Gradient direction
- vec2 gradient = endPoint - startPoint;
- float gradientLength = length(gradient);
-
// Current pixel, projected onto the line between the start point and the end point
// The projection will be relative to the start point!
vec2 proj = (dot(gradient, pos) / (gradientLength * gradientLength)) * gradient;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]