summaryrefslogtreecommitdiff
path: root/rust/crates/compositor/src/shaders/mask.wgsl
blob: 6bbfeccc1d330ef9401db95de4548608e181a3a9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
struct VertexOutput {
    @builtin(position) position: vec4f,
    @location(0) tex_coord: vec2f,
}

struct MaskUniforms {
    inverted: f32,
    _pad0: f32,
    _pad1: f32,
    _pad2: f32,
}

@group(0) @binding(0) var layer_texture: texture_2d<f32>;
@group(0) @binding(1) var layer_sampler: sampler;
@group(1) @binding(0) var mask_texture: texture_2d<f32>;
@group(1) @binding(1) var mask_sampler: sampler;
@group(2) @binding(0) var<uniform> uniforms: MaskUniforms;

@fragment
fn fragment_main(input: VertexOutput) -> @location(0) vec4f {
    let layer = textureSample(layer_texture, layer_sampler, input.tex_coord);
    let mask = textureSample(mask_texture, mask_sampler, input.tex_coord).a;
    let alpha = select(mask, 1.0 - mask, uniforms.inverted > 0.5);
    return vec4f(layer.rgb, layer.a * alpha);
}