From c9510db551893775d3233340dd114d971e24323a Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Mon, 7 Oct 2019 03:56:16 +0200 Subject: Render colored quads --- wgpu/src/shader/quad.frag | 9 +++++++++ wgpu/src/shader/quad.frag.spv | Bin 0 -> 372 bytes wgpu/src/shader/quad.vert | 24 ++++++++++++++++++++++++ wgpu/src/shader/quad.vert.spv | Bin 0 -> 2188 bytes 4 files changed, 33 insertions(+) create mode 100644 wgpu/src/shader/quad.frag create mode 100644 wgpu/src/shader/quad.frag.spv create mode 100644 wgpu/src/shader/quad.vert create mode 100644 wgpu/src/shader/quad.vert.spv (limited to 'wgpu/src/shader') diff --git a/wgpu/src/shader/quad.frag b/wgpu/src/shader/quad.frag new file mode 100644 index 00000000..1aca250f --- /dev/null +++ b/wgpu/src/shader/quad.frag @@ -0,0 +1,9 @@ +#version 450 + +layout(location = 0) in vec4 v_Color; + +layout(location = 0) out vec4 o_Color; + +void main() { + o_Color = v_Color; +} diff --git a/wgpu/src/shader/quad.frag.spv b/wgpu/src/shader/quad.frag.spv new file mode 100644 index 00000000..33218c83 Binary files /dev/null and b/wgpu/src/shader/quad.frag.spv differ diff --git a/wgpu/src/shader/quad.vert b/wgpu/src/shader/quad.vert new file mode 100644 index 00000000..3392d43d --- /dev/null +++ b/wgpu/src/shader/quad.vert @@ -0,0 +1,24 @@ +#version 450 + +layout(location = 0) in vec2 v_Pos; +layout(location = 1) in vec2 i_Pos; +layout(location = 2) in vec2 i_Scale; +layout(location = 3) in vec4 i_Color; + +layout (set = 0, binding = 0) uniform Globals { + mat4 u_Transform; +}; + +layout(location = 0) out vec4 o_Color; + +void main() { + mat4 i_Transform = mat4( + vec4(i_Scale.x, 0.0, 0.0, 0.0), + vec4(0.0, i_Scale.y, 0.0, 0.0), + vec4(0.0, 0.0, 1.0, 0.0), + vec4(i_Pos, 0.0, 1.0) + ); + + o_Color = i_Color; + gl_Position = u_Transform * i_Transform * vec4(v_Pos, 0.0, 1.0); +} diff --git a/wgpu/src/shader/quad.vert.spv b/wgpu/src/shader/quad.vert.spv new file mode 100644 index 00000000..d517796b Binary files /dev/null and b/wgpu/src/shader/quad.vert.spv differ -- cgit From a0234d5bcea5b25f575af01d3a8e0296b2d0395c Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 8 Oct 2019 00:14:11 +0200 Subject: Draft fragment shader for rounded rectangles --- wgpu/src/shader/quad.frag | 26 +++++++++++++++++++++++++- wgpu/src/shader/quad.frag.spv | Bin 372 -> 2900 bytes wgpu/src/shader/quad.vert | 5 +++++ wgpu/src/shader/quad.vert.spv | Bin 2188 -> 2364 bytes 4 files changed, 30 insertions(+), 1 deletion(-) (limited to 'wgpu/src/shader') diff --git a/wgpu/src/shader/quad.frag b/wgpu/src/shader/quad.frag index 1aca250f..1fc28bc1 100644 --- a/wgpu/src/shader/quad.frag +++ b/wgpu/src/shader/quad.frag @@ -1,9 +1,33 @@ #version 450 layout(location = 0) in vec4 v_Color; +layout(location = 1) in vec2 v_Pos; +layout(location = 2) in vec2 v_Scale; layout(location = 0) out vec4 o_Color; +float rounded(in vec2 frag_coord, in vec2 position, in vec2 size, float radius, float s) +{ + vec2 inner_size = size - vec2(radius, radius) * 2.0; + vec2 top_left = position + vec2(radius, radius); + vec2 bottom_right = top_left + inner_size; + + vec2 top_left_distance = top_left - frag_coord; + vec2 bottom_right_distance = frag_coord - bottom_right; + + vec2 distance = vec2( + max(max(top_left_distance.x, bottom_right_distance.x), 0), + max(max(top_left_distance.y, bottom_right_distance.y), 0) + ); + + float d = sqrt(distance.x * distance.x + distance.y * distance.y); + + return 1.0 - smoothstep(radius - s, radius + s, d); +} + void main() { - o_Color = v_Color; + o_Color = vec4( + v_Color.xyz, + v_Color.w * rounded(gl_FragCoord.xy, v_Pos, v_Scale, 5.0, 1.0) + ); } diff --git a/wgpu/src/shader/quad.frag.spv b/wgpu/src/shader/quad.frag.spv index 33218c83..19733ecf 100644 Binary files a/wgpu/src/shader/quad.frag.spv and b/wgpu/src/shader/quad.frag.spv differ diff --git a/wgpu/src/shader/quad.vert b/wgpu/src/shader/quad.vert index 3392d43d..87f6cc53 100644 --- a/wgpu/src/shader/quad.vert +++ b/wgpu/src/shader/quad.vert @@ -10,6 +10,8 @@ layout (set = 0, binding = 0) uniform Globals { }; layout(location = 0) out vec4 o_Color; +layout(location = 1) out vec2 o_Pos; +layout(location = 2) out vec2 o_Scale; void main() { mat4 i_Transform = mat4( @@ -20,5 +22,8 @@ void main() { ); o_Color = i_Color; + o_Pos = i_Pos; + o_Scale = i_Scale; + gl_Position = u_Transform * i_Transform * vec4(v_Pos, 0.0, 1.0); } diff --git a/wgpu/src/shader/quad.vert.spv b/wgpu/src/shader/quad.vert.spv index d517796b..0d13df6c 100644 Binary files a/wgpu/src/shader/quad.vert.spv and b/wgpu/src/shader/quad.vert.spv differ -- cgit From 10e10e5e06841574425d2633f1c2916733f7b4ff Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 8 Oct 2019 03:13:41 +0200 Subject: Make `iced_core::Button` customizable Now it supports: - Any kind of content - Custom border radius - Custom background --- wgpu/src/shader/quad.frag | 12 ++++++++---- wgpu/src/shader/quad.frag.spv | Bin 2900 -> 3196 bytes wgpu/src/shader/quad.vert | 3 +++ wgpu/src/shader/quad.vert.spv | Bin 2364 -> 2544 bytes 4 files changed, 11 insertions(+), 4 deletions(-) (limited to 'wgpu/src/shader') diff --git a/wgpu/src/shader/quad.frag b/wgpu/src/shader/quad.frag index 1fc28bc1..987744db 100644 --- a/wgpu/src/shader/quad.frag +++ b/wgpu/src/shader/quad.frag @@ -3,6 +3,7 @@ layout(location = 0) in vec4 v_Color; layout(location = 1) in vec2 v_Pos; layout(location = 2) in vec2 v_Scale; +layout(location = 3) in flat uint v_BorderRadius; layout(location = 0) out vec4 o_Color; @@ -26,8 +27,11 @@ float rounded(in vec2 frag_coord, in vec2 position, in vec2 size, float radius, } void main() { - o_Color = vec4( - v_Color.xyz, - v_Color.w * rounded(gl_FragCoord.xy, v_Pos, v_Scale, 5.0, 1.0) - ); + float radius_alpha = 1.0; + + if(v_BorderRadius > 0.0) { + radius_alpha = rounded(gl_FragCoord.xy, v_Pos, v_Scale, v_BorderRadius, 1.0); + } + + o_Color = vec4(v_Color.xyz, v_Color.w * radius_alpha); } diff --git a/wgpu/src/shader/quad.frag.spv b/wgpu/src/shader/quad.frag.spv index 19733ecf..063287b3 100644 Binary files a/wgpu/src/shader/quad.frag.spv and b/wgpu/src/shader/quad.frag.spv differ diff --git a/wgpu/src/shader/quad.vert b/wgpu/src/shader/quad.vert index 87f6cc53..b7c5cf3e 100644 --- a/wgpu/src/shader/quad.vert +++ b/wgpu/src/shader/quad.vert @@ -4,6 +4,7 @@ layout(location = 0) in vec2 v_Pos; layout(location = 1) in vec2 i_Pos; layout(location = 2) in vec2 i_Scale; layout(location = 3) in vec4 i_Color; +layout(location = 4) in uint i_BorderRadius; layout (set = 0, binding = 0) uniform Globals { mat4 u_Transform; @@ -12,6 +13,7 @@ layout (set = 0, binding = 0) uniform Globals { layout(location = 0) out vec4 o_Color; layout(location = 1) out vec2 o_Pos; layout(location = 2) out vec2 o_Scale; +layout(location = 3) out uint o_BorderRadius; void main() { mat4 i_Transform = mat4( @@ -24,6 +26,7 @@ void main() { o_Color = i_Color; o_Pos = i_Pos; o_Scale = i_Scale; + o_BorderRadius = i_BorderRadius; gl_Position = u_Transform * i_Transform * vec4(v_Pos, 0.0, 1.0); } diff --git a/wgpu/src/shader/quad.vert.spv b/wgpu/src/shader/quad.vert.spv index 0d13df6c..f62a160c 100644 Binary files a/wgpu/src/shader/quad.vert.spv and b/wgpu/src/shader/quad.vert.spv differ -- cgit From afacb35f9bf87ae10f59091b18b001a4c114a589 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 12 Oct 2019 05:07:00 +0200 Subject: Draw sliders in `iced_wgpu` --- wgpu/src/shader/quad.frag | 2 +- wgpu/src/shader/quad.frag.spv | Bin 3196 -> 3212 bytes 2 files changed, 1 insertion(+), 1 deletion(-) (limited to 'wgpu/src/shader') diff --git a/wgpu/src/shader/quad.frag b/wgpu/src/shader/quad.frag index 987744db..849f581e 100644 --- a/wgpu/src/shader/quad.frag +++ b/wgpu/src/shader/quad.frag @@ -30,7 +30,7 @@ void main() { float radius_alpha = 1.0; if(v_BorderRadius > 0.0) { - radius_alpha = rounded(gl_FragCoord.xy, v_Pos, v_Scale, v_BorderRadius, 1.0); + radius_alpha = rounded(gl_FragCoord.xy, v_Pos, v_Scale, v_BorderRadius, 0.5); } o_Color = vec4(v_Color.xyz, v_Color.w * radius_alpha); diff --git a/wgpu/src/shader/quad.frag.spv b/wgpu/src/shader/quad.frag.spv index 063287b3..71b91b44 100644 Binary files a/wgpu/src/shader/quad.frag.spv and b/wgpu/src/shader/quad.frag.spv differ -- cgit From 38b6c84e7761c049b17d178deb9c866386a53946 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 23 Oct 2019 01:21:23 +0200 Subject: Implement basic image rendering in `iced_wgpu` --- wgpu/src/shader/image.frag | 12 ++++++++++++ wgpu/src/shader/image.frag.spv | Bin 0 -> 684 bytes wgpu/src/shader/image.vert | 24 ++++++++++++++++++++++++ wgpu/src/shader/image.vert.spv | Bin 0 -> 2136 bytes 4 files changed, 36 insertions(+) create mode 100644 wgpu/src/shader/image.frag create mode 100644 wgpu/src/shader/image.frag.spv create mode 100644 wgpu/src/shader/image.vert create mode 100644 wgpu/src/shader/image.vert.spv (limited to 'wgpu/src/shader') diff --git a/wgpu/src/shader/image.frag b/wgpu/src/shader/image.frag new file mode 100644 index 00000000..e35e455a --- /dev/null +++ b/wgpu/src/shader/image.frag @@ -0,0 +1,12 @@ +#version 450 + +layout(location = 0) in vec2 v_Uv; + +layout(set = 0, binding = 1) uniform sampler u_Sampler; +layout(set = 1, binding = 0) uniform texture2D u_Texture; + +layout(location = 0) out vec4 o_Color; + +void main() { + o_Color = texture(sampler2D(u_Texture, u_Sampler), v_Uv); +} diff --git a/wgpu/src/shader/image.frag.spv b/wgpu/src/shader/image.frag.spv new file mode 100644 index 00000000..ebee82ac Binary files /dev/null and b/wgpu/src/shader/image.frag.spv differ diff --git a/wgpu/src/shader/image.vert b/wgpu/src/shader/image.vert new file mode 100644 index 00000000..688c2311 --- /dev/null +++ b/wgpu/src/shader/image.vert @@ -0,0 +1,24 @@ +#version 450 + +layout(location = 0) in vec2 v_Pos; +layout(location = 1) in vec2 i_Pos; +layout(location = 2) in vec2 i_Scale; + +layout (set = 0, binding = 0) uniform Globals { + mat4 u_Transform; +}; + +layout(location = 0) out vec2 o_Uv; + +void main() { + o_Uv = v_Pos; + + mat4 i_Transform = mat4( + vec4(i_Scale.x, 0.0, 0.0, 0.0), + vec4(0.0, i_Scale.y, 0.0, 0.0), + vec4(0.0, 0.0, 1.0, 0.0), + vec4(i_Pos, 0.0, 1.0) + ); + + gl_Position = u_Transform * i_Transform * vec4(v_Pos, 0.0, 1.0); +} diff --git a/wgpu/src/shader/image.vert.spv b/wgpu/src/shader/image.vert.spv new file mode 100644 index 00000000..9ba702bc Binary files /dev/null and b/wgpu/src/shader/image.vert.spv differ -- cgit