diff options
Diffstat (limited to 'gsk/resources/vulkan')
-rw-r--r-- | gsk/resources/vulkan/blend-clip-rounded.frag.glsl | 57 | ||||
-rw-r--r-- | gsk/resources/vulkan/blend-clip-rounded.frag.spv | bin | 0 -> 5180 bytes | |||
-rw-r--r-- | gsk/resources/vulkan/blend-clip-rounded.vert.glsl | 53 | ||||
-rw-r--r-- | gsk/resources/vulkan/blend-clip-rounded.vert.spv | bin | 0 -> 4940 bytes | |||
-rw-r--r-- | gsk/resources/vulkan/blend-clip.frag.glsl (renamed from gsk/resources/vulkan/blit.frag.glsl) | 2 | ||||
-rw-r--r-- | gsk/resources/vulkan/blend-clip.frag.spv (renamed from gsk/resources/vulkan/blit.frag.spv) | bin | 632 -> 632 bytes | |||
-rw-r--r-- | gsk/resources/vulkan/blend-clip.vert.glsl | 46 | ||||
-rw-r--r-- | gsk/resources/vulkan/blend-clip.vert.spv | bin | 0 -> 4604 bytes | |||
-rw-r--r-- | gsk/resources/vulkan/blend.frag.glsl | 12 | ||||
-rw-r--r-- | gsk/resources/vulkan/blend.frag.spv | bin | 0 -> 632 bytes | |||
-rw-r--r-- | gsk/resources/vulkan/blend.vert.glsl | 31 | ||||
-rw-r--r-- | gsk/resources/vulkan/blend.vert.spv | bin | 0 -> 1964 bytes | |||
-rw-r--r-- | gsk/resources/vulkan/blit.vert.glsl | 22 | ||||
-rw-r--r-- | gsk/resources/vulkan/blit.vert.spv | bin | 1252 -> 0 bytes |
14 files changed, 200 insertions, 23 deletions
diff --git a/gsk/resources/vulkan/blend-clip-rounded.frag.glsl b/gsk/resources/vulkan/blend-clip-rounded.frag.glsl new file mode 100644 index 0000000000..fb1c14808c --- /dev/null +++ b/gsk/resources/vulkan/blend-clip-rounded.frag.glsl @@ -0,0 +1,57 @@ +#version 420 core + +struct RoundedRect { + vec4 bounds; + vec4 corners; +}; + +layout(location = 0) in vec2 inPos; +layout(location = 1) in vec2 inTexCoord; +layout(location = 2) in flat vec4 inClipBounds; +layout(location = 3) in flat vec4 inClipWidths; + +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(inClipBounds.xy, inClipBounds.xy + inClipBounds.zw), inClipWidths); + + color = texture (inTexture, inTexCoord) * clip (inPos, r); +} diff --git a/gsk/resources/vulkan/blend-clip-rounded.frag.spv b/gsk/resources/vulkan/blend-clip-rounded.frag.spv Binary files differnew file mode 100644 index 0000000000..aa407c2d1b --- /dev/null +++ b/gsk/resources/vulkan/blend-clip-rounded.frag.spv diff --git a/gsk/resources/vulkan/blend-clip-rounded.vert.glsl b/gsk/resources/vulkan/blend-clip-rounded.vert.glsl new file mode 100644 index 0000000000..c680c65455 --- /dev/null +++ b/gsk/resources/vulkan/blend-clip-rounded.vert.glsl @@ -0,0 +1,53 @@ +#version 420 core + +layout(location = 0) in vec4 inRect; +layout(location = 1) in vec4 inTexRect; + +layout(push_constant) uniform PushConstants { + mat4 mvp; + vec4 clip_bounds; + vec4 clip_widths; + vec4 clip_heights; +} push; + +layout(location = 0) out vec2 outPos; +layout(location = 1) out vec2 outTexCoord; +layout(location = 2) out flat vec4 outClipBounds; +layout(location = 3) out flat vec4 outClipWidths; + +out gl_PerVertex { + vec4 gl_Position; +}; + +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) }; + +vec4 intersect(vec4 a, vec4 b) +{ + a = vec4(a.xy, a.xy + a.zw); + b = vec4(b.xy, b.xy + b.zw); + vec4 result = vec4(max(a.xy, b.xy), min(a.zw, b.zw)); + if (any (greaterThanEqual (result.xy, result.zw))) + return vec4(0.0,0.0,0.0,0.0); + return vec4(result.xy, result.zw - result.xy); +} + +void main() { + vec4 rect = intersect(inRect, push.clip_bounds); + vec2 pos = rect.xy + rect.zw * offsets[gl_VertexIndex]; + gl_Position = push.mvp * vec4 (pos, 0.0, 1.0); + + outPos = pos; + outClipBounds = push.clip_bounds; + outClipWidths = push.clip_widths; + + 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]; +} diff --git a/gsk/resources/vulkan/blend-clip-rounded.vert.spv b/gsk/resources/vulkan/blend-clip-rounded.vert.spv Binary files differnew file mode 100644 index 0000000000..0c27a6b096 --- /dev/null +++ b/gsk/resources/vulkan/blend-clip-rounded.vert.spv diff --git a/gsk/resources/vulkan/blit.frag.glsl b/gsk/resources/vulkan/blend-clip.frag.glsl index 5d7c81856a..4575c49848 100644 --- a/gsk/resources/vulkan/blit.frag.glsl +++ b/gsk/resources/vulkan/blend-clip.frag.glsl @@ -8,5 +8,5 @@ layout(location = 0) out vec4 color; void main() { - color = texture (inTexture, inTexCoord); + color = texture (inTexture, inTexCoord); } diff --git a/gsk/resources/vulkan/blit.frag.spv b/gsk/resources/vulkan/blend-clip.frag.spv Binary files differindex 9dcff6d120..9dcff6d120 100644 --- a/gsk/resources/vulkan/blit.frag.spv +++ b/gsk/resources/vulkan/blend-clip.frag.spv diff --git a/gsk/resources/vulkan/blend-clip.vert.glsl b/gsk/resources/vulkan/blend-clip.vert.glsl new file mode 100644 index 0000000000..0d66a2dcd7 --- /dev/null +++ b/gsk/resources/vulkan/blend-clip.vert.glsl @@ -0,0 +1,46 @@ +#version 420 core + +layout(location = 0) in vec4 inRect; +layout(location = 1) in vec4 inTexRect; + +layout(push_constant) uniform PushConstants { + mat4 mvp; + vec4 clip_bounds; + vec4 clip_widths; + vec4 clip_heights; +} push; + +layout(location = 0) out vec2 outTexCoord; + +out gl_PerVertex { + vec4 gl_Position; +}; + +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) }; + +vec4 intersect(vec4 a, vec4 b) +{ + a = vec4(a.xy, a.xy + a.zw); + b = vec4(b.xy, b.xy + b.zw); + vec4 result = vec4(max(a.xy, b.xy), min(a.zw, b.zw)); + if (any (greaterThanEqual (result.xy, result.zw))) + return vec4(0.0,0.0,0.0,0.0); + return vec4(result.xy, result.zw - result.xy); +} + +void main() { + vec4 rect = intersect(inRect, push.clip_bounds); + vec2 pos = rect.xy + rect.zw * offsets[gl_VertexIndex]; + gl_Position = push.mvp * vec4 (pos, 0.0, 1.0); + + 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]; +} diff --git a/gsk/resources/vulkan/blend-clip.vert.spv b/gsk/resources/vulkan/blend-clip.vert.spv Binary files differnew file mode 100644 index 0000000000..a12f3c8d9e --- /dev/null +++ b/gsk/resources/vulkan/blend-clip.vert.spv diff --git a/gsk/resources/vulkan/blend.frag.glsl b/gsk/resources/vulkan/blend.frag.glsl new file mode 100644 index 0000000000..4575c49848 --- /dev/null +++ b/gsk/resources/vulkan/blend.frag.glsl @@ -0,0 +1,12 @@ +#version 420 core + +layout(location = 0) in vec2 inTexCoord; + +layout(set = 0, binding = 0) uniform sampler2D inTexture; + +layout(location = 0) out vec4 color; + +void main() +{ + color = texture (inTexture, inTexCoord); +} diff --git a/gsk/resources/vulkan/blend.frag.spv b/gsk/resources/vulkan/blend.frag.spv Binary files differnew file mode 100644 index 0000000000..9dcff6d120 --- /dev/null +++ b/gsk/resources/vulkan/blend.frag.spv diff --git a/gsk/resources/vulkan/blend.vert.glsl b/gsk/resources/vulkan/blend.vert.glsl new file mode 100644 index 0000000000..30c1474f9c --- /dev/null +++ b/gsk/resources/vulkan/blend.vert.glsl @@ -0,0 +1,31 @@ +#version 420 core + +layout(location = 0) in vec4 inRect; +layout(location = 1) in vec4 inTexRect; + +layout(push_constant) uniform PushConstants { + mat4 mvp; + vec4 clip_bounds; + vec4 clip_widths; + vec4 clip_heights; +} push; + +layout(location = 0) out vec2 outTexCoord; + +out gl_PerVertex { + vec4 gl_Position; +}; + +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) }; + +void main() { + vec2 pos = inRect.xy + inRect.zw * offsets[gl_VertexIndex]; + gl_Position = push.mvp * vec4 (pos, 0.0, 1.0); + + outTexCoord = inTexRect.xy + inTexRect.zw * offsets[gl_VertexIndex]; +} diff --git a/gsk/resources/vulkan/blend.vert.spv b/gsk/resources/vulkan/blend.vert.spv Binary files differnew file mode 100644 index 0000000000..dafd915f8c --- /dev/null +++ b/gsk/resources/vulkan/blend.vert.spv diff --git a/gsk/resources/vulkan/blit.vert.glsl b/gsk/resources/vulkan/blit.vert.glsl deleted file mode 100644 index ca78688909..0000000000 --- a/gsk/resources/vulkan/blit.vert.glsl +++ /dev/null @@ -1,22 +0,0 @@ -#version 420 core - -layout(location = 0) in vec2 inPosition; -layout(location = 1) in vec2 inTexCoord; - -layout(push_constant) uniform PushConstants { - mat4 mvp; - vec4 clip_bounds; - vec4 clip_widths; - vec4 clip_heights; -} push; - -layout(location = 0) out vec2 outTexCoord; - -out gl_PerVertex { - vec4 gl_Position; -}; - -void main() { - gl_Position = push.mvp * vec4 (inPosition, 0.0, 1.0); - outTexCoord = inTexCoord; -} diff --git a/gsk/resources/vulkan/blit.vert.spv b/gsk/resources/vulkan/blit.vert.spv Binary files differdeleted file mode 100644 index 5ce7a27f29..0000000000 --- a/gsk/resources/vulkan/blit.vert.spv +++ /dev/null |