diff options
author | Benjamin Otte <otte@redhat.com> | 2023-05-13 03:14:16 +0200 |
---|---|---|
committer | Benjamin Otte <otte@redhat.com> | 2023-05-17 02:25:32 +0200 |
commit | 31b17d78f44b0722f3cac06b46750f14dd192f77 (patch) | |
tree | 212fa734cf91023544ee2e74dfc87771f9889daf /gsk | |
parent | 12c8802979ab83dd5d3a5c2f5cb8cd9b79a27dea (diff) | |
download | gtk+-31b17d78f44b0722f3cac06b46750f14dd192f77.tar.gz |
vulkan: Rewrite AA shaders to respect scale
The border and color shaders - the ones that do AA - now multiply their
coordinates by the scale factor, which gives them better rounding
capabilities.
This in particular improves the case where they are used in fractional
scaling situations, where the scale is defined at the root element.
Diffstat (limited to 'gsk')
-rw-r--r-- | gsk/vulkan/resources/border.frag | 8 | ||||
-rw-r--r-- | gsk/vulkan/resources/border.vert | 14 | ||||
-rw-r--r-- | gsk/vulkan/resources/clip.frag.glsl | 24 | ||||
-rw-r--r-- | gsk/vulkan/resources/color.frag | 2 | ||||
-rw-r--r-- | gsk/vulkan/resources/color.vert | 2 | ||||
-rw-r--r-- | gsk/vulkan/resources/rect.glsl | 2 | ||||
-rw-r--r-- | gsk/vulkan/resources/rounded-rect.glsl | 10 |
7 files changed, 42 insertions, 20 deletions
diff --git a/gsk/vulkan/resources/border.frag b/gsk/vulkan/resources/border.frag index 193ccfa6eb..460d8262ff 100644 --- a/gsk/vulkan/resources/border.frag +++ b/gsk/vulkan/resources/border.frag @@ -5,20 +5,18 @@ layout(location = 0) in vec2 inPos; layout(location = 1) in vec4 inColor; -layout(location = 2) in vec4 inRect; -layout(location = 3) in vec4 inCornerWidths; -layout(location = 4) in vec4 inCornerHeights; +layout(location = 2) in RoundedRect inRect; layout(location = 5) in vec4 inBorderWidths; layout(location = 0) out vec4 color; void main() { - RoundedRect routside = RoundedRect (vec4(inRect.xy, inRect.xy + inRect.zw), inCornerWidths, inCornerHeights); + RoundedRect routside = inRect; RoundedRect rinside = rounded_rect_shrink (routside, inBorderWidths); float alpha = clamp (rounded_rect_coverage (routside, inPos) - rounded_rect_coverage (rinside, inPos), 0.0, 1.0); - color = clip (inPos, vec4(inColor.rgb * inColor.a, inColor.a) * alpha); + color = clip_scaled (inPos, vec4(inColor.rgb * inColor.a, inColor.a) * alpha); } diff --git a/gsk/vulkan/resources/border.vert b/gsk/vulkan/resources/border.vert index 56dfd1292d..95f0b24645 100644 --- a/gsk/vulkan/resources/border.vert +++ b/gsk/vulkan/resources/border.vert @@ -1,6 +1,7 @@ #version 420 core #include "clip.vert.glsl" +#include "rounded-rect.glsl" layout(location = 0) in vec4 inRect; layout(location = 1) in vec4 inCornerWidths; @@ -10,9 +11,7 @@ layout(location = 4) in mat4 inBorderColors; layout(location = 0) out vec2 outPos; layout(location = 1) out flat vec4 outColor; -layout(location = 2) out flat vec4 outRect; -layout(location = 3) out flat vec4 outCornerWidths; -layout(location = 4) out flat vec4 outCornerHeights; +layout(location = 2) out flat RoundedRect outRect; layout(location = 5) out flat vec4 outBorderWidths; vec2 offsets[6] = { vec2(0.0, 0.0), @@ -97,11 +96,10 @@ void main() { pos = mix (rect.bounds.xy, rect.bounds.zw, offsets[vert_index]); else pos = mix (rect.bounds.zy, rect.bounds.xw, offsets[vert_index]); - gl_Position = push.mvp * vec4 (push.scale * pos, 0.0, 1.0); + gl_Position = push.mvp * vec4 (pos, 0.0, 1.0); outColor = inBorderColors[((gl_VertexIndex / 3 + 15) / 4) % 4]; outPos = pos; - outRect = inRect; - outCornerWidths = inCornerWidths; - outCornerHeights = inCornerHeights; - outBorderWidths = inBorderWidths; + outRect = RoundedRect(inRect.xyxy + vec4(0,0,inRect.zw), inCornerWidths, inCornerHeights); + outRect = rounded_rect_scale (outRect, push.scale); + outBorderWidths = inBorderWidths * push.scale.yxyx; } diff --git a/gsk/vulkan/resources/clip.frag.glsl b/gsk/vulkan/resources/clip.frag.glsl index 4f4755c5bb..5ab526de86 100644 --- a/gsk/vulkan/resources/clip.frag.glsl +++ b/gsk/vulkan/resources/clip.frag.glsl @@ -5,25 +5,41 @@ #define _CLIP_ #ifdef CLIP_ROUNDED_RECT -vec4 clip(vec2 pos, vec4 color) + +vec4 +clip_scaled (vec2 pos, vec4 color) { RoundedRect r = RoundedRect(vec4(push.clip_bounds.xy, push.clip_bounds.xy + push.clip_bounds.zw), push.clip_widths, push.clip_heights); + r = rounded_rect_scale (r, push.scale); + return color * rounded_rect_coverage (r, pos); } + #elif defined(CLIP_RECT) -vec4 clip(vec2 pos, vec4 color) + +vec4 +clip_scaled (vec2 pos, vec4 color) { - /* clipped in vertex shader already */ return color; } + #elif defined(CLIP_NONE) -vec4 clip(vec2 pos, vec4 color) + +vec4 +clip_scaled (vec2 pos, vec4 color) { return color; } + #else #error "No clipping define given. Need CLIP_NONE, CLIP_RECT or CLIP_ROUNDED_RECT" #endif +vec4 +clip (vec2 pos, vec4 color) +{ + return clip_scaled (pos * push.scale, color); +} + #endif diff --git a/gsk/vulkan/resources/color.frag b/gsk/vulkan/resources/color.frag index 1f988b6517..e0371362a1 100644 --- a/gsk/vulkan/resources/color.frag +++ b/gsk/vulkan/resources/color.frag @@ -12,5 +12,5 @@ layout(location = 0) out vec4 color; void main() { float alpha = inColor.a * rect_coverage (inRect, inPos); - color = clip (inPos, vec4(inColor.rgb, 1) * alpha); + color = clip_scaled (inPos, vec4(inColor.rgb, 1) * alpha); } diff --git a/gsk/vulkan/resources/color.vert b/gsk/vulkan/resources/color.vert index 6a09ff5f99..cc2a853b5c 100644 --- a/gsk/vulkan/resources/color.vert +++ b/gsk/vulkan/resources/color.vert @@ -21,7 +21,7 @@ void main() { Rect rect = rect_round_larger (clip_rect (rect_from_gsk (inRect))); vec2 pos = mix (rect.bounds.xy, rect.bounds.zw, offsets[gl_VertexIndex]); - gl_Position = push.mvp * vec4 (push.scale * pos, 0.0, 1.0); + gl_Position = push.mvp * vec4 (pos, 0.0, 1.0); outPos = pos; outRect = rect_from_gsk (inRect); outColor = inColor; diff --git a/gsk/vulkan/resources/rect.glsl b/gsk/vulkan/resources/rect.glsl index 31c8d476f9..51a116c412 100644 --- a/gsk/vulkan/resources/rect.glsl +++ b/gsk/vulkan/resources/rect.glsl @@ -11,7 +11,7 @@ struct Rect Rect rect_from_gsk (vec4 xywh) { - return Rect(xywh.xyxy + vec4(0,0,xywh.zw)); + return Rect((xywh.xyxy + vec4(0,0,xywh.zw)) * push.scale.xyxy); } float diff --git a/gsk/vulkan/resources/rounded-rect.glsl b/gsk/vulkan/resources/rounded-rect.glsl index 38e8cad941..0f7a13e119 100644 --- a/gsk/vulkan/resources/rounded-rect.glsl +++ b/gsk/vulkan/resources/rounded-rect.glsl @@ -43,6 +43,16 @@ rounded_rect_distance (RoundedRect r, vec2 p) } RoundedRect +rounded_rect_scale (RoundedRect r, vec2 scale) +{ + r.bounds *= scale.xyxy; + r.corner_widths *= scale.xxxx; + r.corner_heights *= scale.yyyy; + + return r; +} + +RoundedRect rounded_rect_shrink (RoundedRect r, vec4 amount) { vec4 new_bounds = r.bounds + vec4(1.0,1.0,-1.0,-1.0) * amount.wxyz; |