vulkan: Update texture shader to do AA
authorBenjamin Otte <otte@redhat.com>
Mon, 15 May 2023 00:25:41 +0000 (02:25 +0200)
committerBenjamin Otte <otte@redhat.com>
Sun, 4 Jun 2023 17:42:01 +0000 (19:42 +0200)
gsk/vulkan/resources/texture.frag
gsk/vulkan/resources/texture.vert

index ee9eb459a9156dc0100b666766e2adc8871be4ff..557a63746aa845a10925992c98923deefc5736f0 100644 (file)
@@ -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);
 }
index 443d6ecae9453f51eeefea1c478b743902c7ea9a..49d30e2e471be814875a19544e20fe0356c80f91 100644 (file)
@@ -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);
 }