From a73530f95274fdc394fd7a501841d531f95b8ef7 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Mon, 15 May 2023 02:25:41 +0200 Subject: [PATCH] vulkan: Update texture shader to do AA --- gsk/vulkan/resources/texture.frag | 7 +++++-- gsk/vulkan/resources/texture.vert | 26 ++++++++------------------ 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/gsk/vulkan/resources/texture.frag b/gsk/vulkan/resources/texture.frag index ee9eb459a9..557a63746a 100644 --- a/gsk/vulkan/resources/texture.frag +++ b/gsk/vulkan/resources/texture.frag @@ -1,9 +1,11 @@ #version 420 core #include "clip.frag.glsl" +#include "rect.frag.glsl" layout(location = 0) in vec2 inPos; -layout(location = 1) in vec2 inTexCoord; +layout(location = 1) in Rect inRect; +layout(location = 2) in vec2 inTexCoord; layout(set = 0, binding = 0) uniform sampler2D inTexture; @@ -11,5 +13,6 @@ layout(location = 0) out vec4 color; void main() { - color = clip (inPos, texture (inTexture, inTexCoord)); + float alpha = rect_coverage (inRect, inPos); + color = clip_scaled (inPos, texture (inTexture, inTexCoord) * alpha); } diff --git a/gsk/vulkan/resources/texture.vert b/gsk/vulkan/resources/texture.vert index 443d6ecae9..49d30e2e47 100644 --- a/gsk/vulkan/resources/texture.vert +++ b/gsk/vulkan/resources/texture.vert @@ -1,30 +1,20 @@ #version 420 core -#include "clip.vert.glsl" +#include "common.vert.glsl" +#include "rect.vert.glsl" layout(location = 0) in vec4 inRect; layout(location = 1) in vec4 inTexRect; layout(location = 0) out vec2 outPos; -layout(location = 1) out vec2 outTexCoord; - -vec2 offsets[6] = { vec2(0.0, 0.0), - vec2(1.0, 0.0), - vec2(0.0, 1.0), - vec2(0.0, 1.0), - vec2(1.0, 0.0), - vec2(1.0, 1.0) }; +layout(location = 1) out flat Rect outRect; +layout(location = 2) out vec2 outTexCoord; void main() { - vec4 rect = clip (inRect); - vec2 pos = rect.xy + rect.zw * offsets[gl_VertexIndex]; - gl_Position = push.mvp * vec4 (push.scale * pos, 0.0, 1.0); + Rect r = rect_from_gsk (inRect); + vec2 pos = set_position_from_rect (r); outPos = pos; - - vec4 texrect = vec4((rect.xy - inRect.xy) / inRect.zw, - rect.zw / inRect.zw); - texrect = vec4(inTexRect.xy + inTexRect.zw * texrect.xy, - inTexRect.zw * texrect.zw); - outTexCoord = texrect.xy + texrect.zw * offsets[gl_VertexIndex]; + outRect = r; + outTexCoord = scale_tex_coord (pos, r, inTexRect); } -- 2.30.2