2024-05-14 10:50:37 +00:00
|
|
|
// NOTE: The `common.wgsl` source is prepended to this before compilation.
|
2023-01-06 22:17:42 +00:00
|
|
|
|
2022-12-23 22:06:19 +00:00
|
|
|
struct VertexOutput {
|
|
|
|
@builtin(position) position: vec4<f32>,
|
|
|
|
@location(0) uv: vec2<f32>,
|
|
|
|
};
|
|
|
|
|
2024-05-14 10:50:37 +00:00
|
|
|
@group(1) @binding(0) var<uniform> transforms: common__Transforms;
|
2024-01-23 20:28:12 +00:00
|
|
|
@group(2) @binding(0) var parent_texture: texture_2d<f32>;
|
|
|
|
@group(2) @binding(1) var current_texture: texture_2d<f32>;
|
|
|
|
@group(2) @binding(2) var texture_sampler: sampler;
|
2023-01-06 22:17:42 +00:00
|
|
|
|
2022-12-23 22:06:19 +00:00
|
|
|
@vertex
|
2024-05-14 10:50:37 +00:00
|
|
|
fn main_vertex(in: common__VertexInput) -> VertexOutput {
|
|
|
|
let pos = common__globals.view_matrix * transforms.world_matrix * vec4<f32>(in.position.x, in.position.y, 1.0, 1.0);
|
2022-12-23 22:06:19 +00:00
|
|
|
let uv = vec2<f32>((pos.x + 1.0) / 2.0, -((pos.y - 1.0) / 2.0));
|
|
|
|
return VertexOutput(pos, uv);
|
|
|
|
}
|
|
|
|
|
|
|
|
@fragment
|
|
|
|
fn main_fragment(in: VertexOutput) -> @location(0) vec4<f32> {
|
|
|
|
// dst is the parent pixel we're blending onto
|
|
|
|
var dst: vec4<f32> = textureSample(parent_texture, texture_sampler, in.uv);
|
|
|
|
// src is the pixel that we want to apply
|
|
|
|
var src: vec4<f32> = textureSample(current_texture, texture_sampler, in.uv);
|
|
|
|
|
|
|
|
if (src.a > 0.0) {
|
|
|
|
return vec4<f32>(dst.rgb * src.a, src.a * dst.a);
|
|
|
|
} else {
|
|
|
|
if (true) {
|
|
|
|
// This needs to be in a branch because... reasons. Bug in naga.
|
|
|
|
// https://github.com/gfx-rs/naga/issues/2168
|
|
|
|
discard;
|
|
|
|
}
|
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
}
|