[gtk+] vulkan: Add a clip.frag.glsl include
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] vulkan: Add a clip.frag.glsl include
- Date: Tue, 17 Jan 2017 05:20:06 +0000 (UTC)
commit cf65443fb3102e7d128fbb22ce3187feb52b9b2c
Author: Benjamin Otte <otte redhat com>
Date: Tue Jan 17 05:36:03 2017 +0100
vulkan: Add a clip.frag.glsl include
This include is supposed to handle clipping for the different clipping
methods.
So far, we only use it in the rounded rect cases.
gsk/Makefile.am | 1 +
gsk/resources/vulkan/blend-clip-rounded.frag.glsl | 47 +------------------
gsk/resources/vulkan/blend-clip-rounded.frag.spv | Bin 5464 -> 8268 bytes
gsk/resources/vulkan/blend-clip.frag.spv | Bin 632 -> 632 bytes
gsk/resources/vulkan/clip.frag.glsl | 29 ++++++++++++
gsk/resources/vulkan/color-clip-rounded.frag.glsl | 48 +------------------
gsk/resources/vulkan/color-clip-rounded.frag.spv | Bin 5552 -> 8356 bytes
.../vulkan/color-matrix-clip-rounded.frag.glsl | 47 +------------------
.../vulkan/color-matrix-clip-rounded.frag.spv | Bin 6872 -> 9676 bytes
gsk/resources/vulkan/linear-clip-rounded.frag.glsl | 47 +------------------
gsk/resources/vulkan/linear-clip-rounded.frag.spv | Bin 7032 -> 9836 bytes
11 files changed, 42 insertions(+), 177 deletions(-)
---
diff --git a/gsk/Makefile.am b/gsk/Makefile.am
index 3814845..dd480bf 100644
--- a/gsk/Makefile.am
+++ b/gsk/Makefile.am
@@ -58,6 +58,7 @@ gsk_private_vulkan_source_c = \
gskvulkanrenderpass.c \
gskvulkanshader.c
gsk_private_vulkan_include_shaders = \
+ resources/vulkan/clip.frag.glsl \
resources/vulkan/constants.glsl \
resources/vulkan/rounded-rect.glsl
gsk_private_vulkan_shaders = \
diff --git a/gsk/resources/vulkan/blend-clip-rounded.frag.glsl
b/gsk/resources/vulkan/blend-clip-rounded.frag.glsl
index 23ef1c8..81bd003 100644
--- a/gsk/resources/vulkan/blend-clip-rounded.frag.glsl
+++ b/gsk/resources/vulkan/blend-clip-rounded.frag.glsl
@@ -1,11 +1,7 @@
#version 420 core
-#include "constants.glsl"
-
-struct RoundedRect {
- vec4 bounds;
- vec4 corners;
-};
+#define CLIP_ROUNDED_RECT
+#include "clip.frag.glsl"
layout(location = 0) in vec2 inPos;
layout(location = 1) in vec2 inTexCoord;
@@ -14,44 +10,7 @@ layout(set = 0, binding = 0) uniform sampler2D inTexture;
layout(location = 0) out vec4 color;
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-float clip(vec2 pos, RoundedRect r) {
- vec2 ref_tl = r.bounds.xy + vec2( r.corners.x, r.corners.x);
- vec2 ref_tr = r.bounds.zy + vec2(-r.corners.y, r.corners.y);
- vec2 ref_br = r.bounds.zw + vec2(-r.corners.z, -r.corners.z);
- vec2 ref_bl = r.bounds.xw + vec2( r.corners.w, -r.corners.w);
-
- float d_tl = distance(pos, ref_tl);
- float d_tr = distance(pos, ref_tr);
- float d_br = distance(pos, ref_br);
- float d_bl = distance(pos, ref_bl);
-
- float pixels_per_fragment = length(fwidth(pos.xy));
- float nudge = 0.5 * pixels_per_fragment;
- vec4 distances = vec4(d_tl, d_tr, d_br, d_bl) - r.corners + nudge;
-
- bvec4 is_out = bvec4(pos.x < ref_tl.x && pos.y < ref_tl.y,
- pos.x > ref_tr.x && pos.y < ref_tr.y,
- pos.x > ref_br.x && pos.y > ref_br.y,
- pos.x < ref_bl.x && pos.y > ref_bl.y);
-
- float distance_from_border = dot(vec4(is_out),
- max(vec4(0.0, 0.0, 0.0, 0.0), distances));
-
- // Move the distance back into pixels.
- distance_from_border /= pixels_per_fragment;
- // Apply a more gradual fade out to transparent.
- //distance_from_border -= 0.5;
-
- return 1.0 - smoothstep(0.0, 1.0, distance_from_border);
-}
-
void main()
{
- RoundedRect r = RoundedRect(vec4(push.clip_bounds.xy, push.clip_bounds.xy + push.clip_bounds.zw),
push.clip_widths);
-
- color = texture (inTexture, inTexCoord) * clip (inPos, r);
+ color = clip (inPos, texture (inTexture, inTexCoord));
}
diff --git a/gsk/resources/vulkan/blend-clip-rounded.frag.spv
b/gsk/resources/vulkan/blend-clip-rounded.frag.spv
index adaa02b..8b4b3b3 100644
Binary files a/gsk/resources/vulkan/blend-clip-rounded.frag.spv and
b/gsk/resources/vulkan/blend-clip-rounded.frag.spv differ
diff --git a/gsk/resources/vulkan/blend-clip.frag.spv b/gsk/resources/vulkan/blend-clip.frag.spv
index 9dcff6d..ef5dc6b 100644
Binary files a/gsk/resources/vulkan/blend-clip.frag.spv and b/gsk/resources/vulkan/blend-clip.frag.spv differ
diff --git a/gsk/resources/vulkan/clip.frag.glsl b/gsk/resources/vulkan/clip.frag.glsl
new file mode 100644
index 0000000..472dc6f
--- /dev/null
+++ b/gsk/resources/vulkan/clip.frag.glsl
@@ -0,0 +1,29 @@
+#include "constants.glsl"
+#include "rounded-rect.glsl"
+
+#ifndef _CLIP_
+#define _CLIP_
+
+#ifdef CLIP_ROUNDED_RECT
+vec4 clip(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);
+
+ return color * rounded_rect_coverage (r, pos);
+}
+#elif defined(CLIP_RECT)
+vec4 clip(vec2 pos, vec4 color)
+{
+ /* clipped in vertex shader already */
+ return color;
+}
+#elif defined(CLIP_NONE)
+vec4 clip(vec2 pos, vec4 color)
+{
+ return color;
+}
+#else
+#error "No clipping define given. Need CLIP_NONE, CLIP_RECT or CLIP_ROUNDED_RECT"
+#endif
+
+#endif
diff --git a/gsk/resources/vulkan/color-clip-rounded.frag.glsl
b/gsk/resources/vulkan/color-clip-rounded.frag.glsl
index c1fa503..b66001c 100644
--- a/gsk/resources/vulkan/color-clip-rounded.frag.glsl
+++ b/gsk/resources/vulkan/color-clip-rounded.frag.glsl
@@ -1,56 +1,14 @@
#version 420 core
-#include "constants.glsl"
+#define CLIP_ROUNDED_RECT
+#include "clip.frag.glsl"
layout(location = 0) in vec2 inPos;
layout(location = 1) in vec4 inColor;
layout(location = 0) out vec4 color;
-struct RoundedRect {
- vec4 bounds;
- vec4 corners;
-};
-
-
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-float clip(vec2 pos, RoundedRect r) {
- vec2 ref_tl = r.bounds.xy + vec2( r.corners.x, r.corners.x);
- vec2 ref_tr = r.bounds.zy + vec2(-r.corners.y, r.corners.y);
- vec2 ref_br = r.bounds.zw + vec2(-r.corners.z, -r.corners.z);
- vec2 ref_bl = r.bounds.xw + vec2( r.corners.w, -r.corners.w);
-
- float d_tl = distance(pos, ref_tl);
- float d_tr = distance(pos, ref_tr);
- float d_br = distance(pos, ref_br);
- float d_bl = distance(pos, ref_bl);
-
- float pixels_per_fragment = length(fwidth(pos.xy));
- float nudge = 0.5 * pixels_per_fragment;
- vec4 distances = vec4(d_tl, d_tr, d_br, d_bl) - r.corners + nudge;
-
- bvec4 is_out = bvec4(pos.x < ref_tl.x && pos.y < ref_tl.y,
- pos.x > ref_tr.x && pos.y < ref_tr.y,
- pos.x > ref_br.x && pos.y > ref_br.y,
- pos.x < ref_bl.x && pos.y > ref_bl.y);
-
- float distance_from_border = dot(vec4(is_out),
- max(vec4(0.0, 0.0, 0.0, 0.0), distances));
-
- // Move the distance back into pixels.
- distance_from_border /= pixels_per_fragment;
- // Apply a more gradual fade out to transparent.
- //distance_from_border -= 0.5;
-
- return 1.0 - smoothstep(0.0, 1.0, distance_from_border);
-}
-
void main()
{
- RoundedRect r = RoundedRect(vec4(push.clip_bounds.xy, push.clip_bounds.xy + push.clip_bounds.zw),
push.clip_widths);
-
- color = vec4(inColor.rgb * inColor.a, inColor.a) * clip (inPos, r);
+ color = clip (inPos, vec4(inColor.rgb * inColor.a, inColor.a));
}
diff --git a/gsk/resources/vulkan/color-clip-rounded.frag.spv
b/gsk/resources/vulkan/color-clip-rounded.frag.spv
index ce92576..74d6fb9 100644
Binary files a/gsk/resources/vulkan/color-clip-rounded.frag.spv and
b/gsk/resources/vulkan/color-clip-rounded.frag.spv differ
diff --git a/gsk/resources/vulkan/color-matrix-clip-rounded.frag.glsl
b/gsk/resources/vulkan/color-matrix-clip-rounded.frag.glsl
index 6015aee..88057c7 100644
--- a/gsk/resources/vulkan/color-matrix-clip-rounded.frag.glsl
+++ b/gsk/resources/vulkan/color-matrix-clip-rounded.frag.glsl
@@ -1,11 +1,7 @@
#version 420 core
-#include "constants.glsl"
-
-struct RoundedRect {
- vec4 bounds;
- vec4 corners;
-};
+#define CLIP_ROUNDED_RECT
+#include "clip.frag.glsl"
layout(location = 0) in vec2 inPos;
layout(location = 1) in vec2 inTexCoord;
@@ -16,41 +12,6 @@ layout(set = 0, binding = 0) uniform sampler2D inTexture;
layout(location = 0) out vec4 color;
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-float clip(vec2 pos, RoundedRect r) {
- vec2 ref_tl = r.bounds.xy + vec2( r.corners.x, r.corners.x);
- vec2 ref_tr = r.bounds.zy + vec2(-r.corners.y, r.corners.y);
- vec2 ref_br = r.bounds.zw + vec2(-r.corners.z, -r.corners.z);
- vec2 ref_bl = r.bounds.xw + vec2( r.corners.w, -r.corners.w);
-
- float d_tl = distance(pos, ref_tl);
- float d_tr = distance(pos, ref_tr);
- float d_br = distance(pos, ref_br);
- float d_bl = distance(pos, ref_bl);
-
- float pixels_per_fragment = length(fwidth(pos.xy));
- float nudge = 0.5 * pixels_per_fragment;
- vec4 distances = vec4(d_tl, d_tr, d_br, d_bl) - r.corners + nudge;
-
- bvec4 is_out = bvec4(pos.x < ref_tl.x && pos.y < ref_tl.y,
- pos.x > ref_tr.x && pos.y < ref_tr.y,
- pos.x > ref_br.x && pos.y > ref_br.y,
- pos.x < ref_bl.x && pos.y > ref_bl.y);
-
- float distance_from_border = dot(vec4(is_out),
- max(vec4(0.0, 0.0, 0.0, 0.0), distances));
-
- // Move the distance back into pixels.
- distance_from_border /= pixels_per_fragment;
- // Apply a more gradual fade out to transparent.
- //distance_from_border -= 0.5;
-
- return 1.0 - smoothstep(0.0, 1.0, distance_from_border);
-}
-
vec4
color_matrix (vec4 color, mat4 color_matrix, vec4 color_offset)
{
@@ -70,7 +31,5 @@ color_matrix (vec4 color, mat4 color_matrix, vec4 color_offset)
void main()
{
- RoundedRect r = RoundedRect(vec4(push.clip_bounds.xy, push.clip_bounds.xy + push.clip_bounds.zw),
push.clip_widths);
-
- color = color_matrix (texture (inTexture, inTexCoord), inColorMatrix, inColorOffset) * clip (inPos, r);
+ color = clip (inPos, color_matrix (texture (inTexture, inTexCoord), inColorMatrix, inColorOffset));
}
diff --git a/gsk/resources/vulkan/color-matrix-clip-rounded.frag.spv
b/gsk/resources/vulkan/color-matrix-clip-rounded.frag.spv
index f0a36e0..2025e85 100644
Binary files a/gsk/resources/vulkan/color-matrix-clip-rounded.frag.spv and
b/gsk/resources/vulkan/color-matrix-clip-rounded.frag.spv differ
diff --git a/gsk/resources/vulkan/linear-clip-rounded.frag.glsl
b/gsk/resources/vulkan/linear-clip-rounded.frag.glsl
index 4535a44..1fbf095 100644
--- a/gsk/resources/vulkan/linear-clip-rounded.frag.glsl
+++ b/gsk/resources/vulkan/linear-clip-rounded.frag.glsl
@@ -1,17 +1,13 @@
#version 420 core
-#include "constants.glsl"
+#define CLIP_ROUNDED_RECT
+#include "clip.frag.glsl"
struct ColorStop {
float offset;
vec4 color;
};
-struct RoundedRect {
- vec4 bounds;
- vec4 corners;
-};
-
layout(location = 0) in vec2 inPos;
layout(location = 1) in float inGradientPos;
layout(location = 2) in flat int inRepeating;
@@ -20,45 +16,8 @@ layout(location = 4) in flat ColorStop inStops[8];
layout(location = 0) out vec4 outColor;
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-float clip(vec2 pos, RoundedRect r) {
- vec2 ref_tl = r.bounds.xy + vec2( r.corners.x, r.corners.x);
- vec2 ref_tr = r.bounds.zy + vec2(-r.corners.y, r.corners.y);
- vec2 ref_br = r.bounds.zw + vec2(-r.corners.z, -r.corners.z);
- vec2 ref_bl = r.bounds.xw + vec2( r.corners.w, -r.corners.w);
-
- float d_tl = distance(pos, ref_tl);
- float d_tr = distance(pos, ref_tr);
- float d_br = distance(pos, ref_br);
- float d_bl = distance(pos, ref_bl);
-
- float pixels_per_fragment = length(fwidth(pos.xy));
- float nudge = 0.5 * pixels_per_fragment;
- vec4 distances = vec4(d_tl, d_tr, d_br, d_bl) - r.corners + nudge;
-
- bvec4 is_out = bvec4(pos.x < ref_tl.x && pos.y < ref_tl.y,
- pos.x > ref_tr.x && pos.y < ref_tr.y,
- pos.x > ref_br.x && pos.y > ref_br.y,
- pos.x < ref_bl.x && pos.y > ref_bl.y);
-
- float distance_from_border = dot(vec4(is_out),
- max(vec4(0.0, 0.0, 0.0, 0.0), distances));
-
- // Move the distance back into pixels.
- distance_from_border /= pixels_per_fragment;
- // Apply a more gradual fade out to transparent.
- //distance_from_border -= 0.5;
-
- return 1.0 - smoothstep(0.0, 1.0, distance_from_border);
-}
-
void main()
{
- RoundedRect r = RoundedRect(vec4(push.clip_bounds.xy, push.clip_bounds.xy + push.clip_bounds.zw),
push.clip_widths);
-
float pos;
if (inRepeating != 0)
pos = fract (inGradientPos);
@@ -74,5 +33,5 @@ void main()
}
//outColor = vec4(pos, pos, pos, 1.0);
- outColor = color * clip (inPos, r);
+ outColor = clip (inPos, color);
}
diff --git a/gsk/resources/vulkan/linear-clip-rounded.frag.spv
b/gsk/resources/vulkan/linear-clip-rounded.frag.spv
index 4a018c0..2610f33 100644
Binary files a/gsk/resources/vulkan/linear-clip-rounded.frag.spv and
b/gsk/resources/vulkan/linear-clip-rounded.frag.spv differ
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]