summaryrefslogtreecommitdiffstats
path: root/wgpu/src/shader
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón <hector@hecrj.dev>2024-05-03 13:51:57 +0200
committerLibravatar GitHub <noreply@github.com>2024-05-03 13:51:57 +0200
commita94984d681875146d7af9f568bf8713503c1ca96 (patch)
treec0a4eef3b5ab5fc3450b21b37df99542c178f6e0 /wgpu/src/shader
parent38cf87cb45484c7e52ddf775fb3abd7edbecc652 (diff)
parentafb4cb99b92a196bf4dd15a09a8f9bd191293fdd (diff)
downloadiced-a94984d681875146d7af9f568bf8713503c1ca96.tar.gz
iced-a94984d681875146d7af9f568bf8713503c1ca96.tar.bz2
iced-a94984d681875146d7af9f568bf8713503c1ca96.zip
Merge pull request #2424 from iced-rs/feature/image-opacity
Introduce dynamic `opacity` support for `Image` and `Svg`
Diffstat (limited to 'wgpu/src/shader')
-rw-r--r--wgpu/src/shader/image.wgsl11
1 files changed, 7 insertions, 4 deletions
diff --git a/wgpu/src/shader/image.wgsl b/wgpu/src/shader/image.wgsl
index 71bf939c..accefc17 100644
--- a/wgpu/src/shader/image.wgsl
+++ b/wgpu/src/shader/image.wgsl
@@ -12,15 +12,17 @@ struct VertexInput {
@location(1) center: vec2<f32>,
@location(2) scale: vec2<f32>,
@location(3) rotation: f32,
- @location(4) atlas_pos: vec2<f32>,
- @location(5) atlas_scale: vec2<f32>,
- @location(6) layer: i32,
+ @location(4) opacity: f32,
+ @location(5) atlas_pos: vec2<f32>,
+ @location(6) atlas_scale: vec2<f32>,
+ @location(7) layer: i32,
}
struct VertexOutput {
@builtin(position) position: vec4<f32>,
@location(0) uv: vec2<f32>,
@location(1) layer: f32, // this should be an i32, but naga currently reads that as requiring interpolation.
+ @location(2) opacity: f32,
}
@vertex
@@ -33,6 +35,7 @@ fn vs_main(input: VertexInput) -> VertexOutput {
// Map the vertex position to the atlas texture.
out.uv = vec2<f32>(v_pos * input.atlas_scale + input.atlas_pos);
out.layer = f32(input.layer);
+ out.opacity = input.opacity;
// Calculate the vertex position and move the center to the origin
v_pos = input.pos + v_pos * input.scale - input.center;
@@ -56,5 +59,5 @@ fn vs_main(input: VertexInput) -> VertexOutput {
@fragment
fn fs_main(input: VertexOutput) -> @location(0) vec4<f32> {
// Sample the texture at the given UV coordinate and layer.
- return textureSample(u_texture, u_sampler, input.uv, i32(input.layer));
+ return textureSample(u_texture, u_sampler, input.uv, i32(input.layer)) * vec4<f32>(1.0, 1.0, 1.0, input.opacity);
}