mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2025-01-13 05:50:10 +00:00
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.
This commit is contained in:
parent
76634cb68b
commit
87c9503293
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -42,6 +42,16 @@ rounded_rect_distance (RoundedRect r, vec2 p)
|
||||
return max (max2.x, max2.y);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user