[gtk/wip/baedert/for-master: 7/7] gl shaders: unify frag coord handling
- From: Timm Bäder <baedert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/baedert/for-master: 7/7] gl shaders: unify frag coord handling
- Date: Sun, 10 May 2020 07:32:53 +0000 (UTC)
commit 52ae384bfdfa17c7211dbc103287d4fd580e790f
Author: Timm Bäder <mail baedert org>
Date: Sun May 10 09:20:53 2020 +0200
gl shaders: unify frag coord handling
gsk/resources/glsl/border.glsl | 8 +++-----
gsk/resources/glsl/inset_shadow.glsl | 9 +++------
gsk/resources/glsl/linear_gradient.glsl | 10 +---------
gsk/resources/glsl/outset_shadow.glsl | 7 ++-----
gsk/resources/glsl/preamble.fs.glsl | 25 +++++++++++++++++++------
gsk/resources/glsl/unblurred_outset_shadow.glsl | 9 +++------
6 files changed, 31 insertions(+), 37 deletions(-)
---
diff --git a/gsk/resources/glsl/border.glsl b/gsk/resources/glsl/border.glsl
index 812d365431..894843cc50 100644
--- a/gsk/resources/glsl/border.glsl
+++ b/gsk/resources/glsl/border.glsl
@@ -32,12 +32,10 @@ _IN_ _ROUNDED_RECT_UNIFORM_ transformed_outside_outline;
_IN_ _ROUNDED_RECT_UNIFORM_ transformed_inside_outline;
void main() {
- vec4 f = gl_FragCoord;
- f.x += u_viewport.x;
- f.y = (u_viewport.y + u_viewport.w) - f.y;
+ vec2 frag = get_frag_coord();
- float alpha = clamp(rounded_rect_coverage(decode_rect(transformed_outside_outline), f.xy) -
- rounded_rect_coverage(decode_rect(transformed_inside_outline), f.xy),
+ float alpha = clamp(rounded_rect_coverage(decode_rect(transformed_outside_outline), frag) -
+ rounded_rect_coverage(decode_rect(transformed_inside_outline), frag),
0.0, 1.0);
setOutputColor(final_color * alpha);
diff --git a/gsk/resources/glsl/inset_shadow.glsl b/gsk/resources/glsl/inset_shadow.glsl
index b3ba05a41f..238540c731 100644
--- a/gsk/resources/glsl/inset_shadow.glsl
+++ b/gsk/resources/glsl/inset_shadow.glsl
@@ -33,13 +33,10 @@ _IN_ _ROUNDED_RECT_UNIFORM_ transformed_outside_outline;
_IN_ _ROUNDED_RECT_UNIFORM_ transformed_inside_outline;
void main() {
- vec4 f = gl_FragCoord;
+ vec2 frag = get_frag_coord();
- f.x += u_viewport.x;
- f.y = (u_viewport.y + u_viewport.w) - f.y;
-
- float alpha = clamp (rounded_rect_coverage(decode_rect(transformed_outside_outline), f.xy) -
- rounded_rect_coverage(decode_rect(transformed_inside_outline), f.xy),
+ float alpha = clamp (rounded_rect_coverage(decode_rect(transformed_outside_outline), frag) -
+ rounded_rect_coverage(decode_rect(transformed_inside_outline), frag),
0.0, 1.0);
setOutputColor(final_color * alpha);
diff --git a/gsk/resources/glsl/linear_gradient.glsl b/gsk/resources/glsl/linear_gradient.glsl
index 6814eed53f..cffe39294d 100644
--- a/gsk/resources/glsl/linear_gradient.glsl
+++ b/gsk/resources/glsl/linear_gradient.glsl
@@ -47,17 +47,9 @@ _IN_ float gradientLength;
_IN_ vec4 color_stops[8];
_IN_ float color_offsets[8];
-
-vec4 fragCoord() {
- vec4 f = gl_FragCoord;
- f.x += u_viewport.x;
- f.y = (u_viewport.y + u_viewport.w) - f.y;
- return f;
-}
-
void main() {
// Position relative to startPoint
- vec2 pos = fragCoord().xy - startPoint;
+ vec2 pos = get_frag_coord() - startPoint;
// Current pixel, projected onto the line between the start point and the end point
// The projection will be relative to the start point!
diff --git a/gsk/resources/glsl/outset_shadow.glsl b/gsk/resources/glsl/outset_shadow.glsl
index 4111ddcea8..40ef45f648 100644
--- a/gsk/resources/glsl/outset_shadow.glsl
+++ b/gsk/resources/glsl/outset_shadow.glsl
@@ -25,13 +25,10 @@ _IN_ vec4 final_color;
_IN_ _ROUNDED_RECT_UNIFORM_ transformed_outline;
void main() {
- vec4 f = gl_FragCoord;
-
- f.x += u_viewport.x;
- f.y = (u_viewport.y + u_viewport.w) - f.y;
+ vec2 frag = get_frag_coord();
float alpha = Texture(u_source, vUv).a;
- alpha *= (1.0 - clamp(rounded_rect_coverage(decode_rect(transformed_outline), f.xy), 0.0, 1.0));
+ alpha *= (1.0 - clamp(rounded_rect_coverage(decode_rect(transformed_outline), frag), 0.0, 1.0));
vec4 color = final_color * alpha;
diff --git a/gsk/resources/glsl/preamble.fs.glsl b/gsk/resources/glsl/preamble.fs.glsl
index 5107470e00..cadbaf1331 100644
--- a/gsk/resources/glsl/preamble.fs.glsl
+++ b/gsk/resources/glsl/preamble.fs.glsl
@@ -84,19 +84,32 @@ vec4 Texture(sampler2D sampler, vec2 texCoords) {
#endif
}
-void setOutputColor(vec4 color) {
- vec4 f = gl_FragCoord;
+#ifdef GSK_GL3
+layout(origin_upper_left) in vec4 gl_FragCoord;
+#endif
+
+vec2 get_frag_coord() {
+ vec2 fc = gl_FragCoord.xy;
+
+#ifdef GSK_GL3
+ fc += u_viewport.xy;
+#else
+ fc.x += u_viewport.x;
+ fc.y = (u_viewport.y + u_viewport.w) - fc.y;
+#endif
- f.x += u_viewport.x;
- f.y = (u_viewport.y + u_viewport.w) - f.y;
+ return fc;
+}
+void setOutputColor(vec4 color) {
+ vec2 f = get_frag_coord();
// We do *NOT* transform the clip rect here since we already
// need to do that on the CPU.
#if defined(GSK_GLES) || defined(GSK_LEGACY)
- gl_FragColor = color * rounded_rect_coverage(create_rect(u_clip_rect), f.xy);
+ gl_FragColor = color * rounded_rect_coverage(create_rect(u_clip_rect), f);
#else
- outputColor = color * rounded_rect_coverage(create_rect(u_clip_rect), f.xy);
+ outputColor = color * rounded_rect_coverage(create_rect(u_clip_rect), f);
#endif
/*outputColor = color;*/
}
diff --git a/gsk/resources/glsl/unblurred_outset_shadow.glsl b/gsk/resources/glsl/unblurred_outset_shadow.glsl
index 77c02be8e1..419605e092 100644
--- a/gsk/resources/glsl/unblurred_outset_shadow.glsl
+++ b/gsk/resources/glsl/unblurred_outset_shadow.glsl
@@ -33,13 +33,10 @@ _IN_ _ROUNDED_RECT_UNIFORM_ transformed_outside_outline;
_IN_ _ROUNDED_RECT_UNIFORM_ transformed_inside_outline;
void main() {
- vec4 f = gl_FragCoord;
+ vec2 frag = get_frag_coord();
- f.x += u_viewport.x;
- f.y = (u_viewport.y + u_viewport.w) - f.y;
-
- float alpha = clamp(rounded_rect_coverage(decode_rect(transformed_outside_outline), f.xy) -
- rounded_rect_coverage(decode_rect(transformed_inside_outline), f.xy),
+ float alpha = clamp(rounded_rect_coverage(decode_rect(transformed_outside_outline), frag) -
+ rounded_rect_coverage(decode_rect(transformed_inside_outline), frag),
0.0, 1.0);
setOutputColor(final_color * alpha);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]