Constant SHADER
Source const SHADER: &str = r#"
struct Uniforms {
progress: f32,
has_secondary: u32,
pad0: f32,
pad1: f32,
};
@group(0) @binding(0) var<uniform> u: Uniforms;
@group(0) @binding(1) var primary_tex: texture_2d<f32>;
@group(0) @binding(2) var secondary_tex: texture_2d<f32>;
@group(0) @binding(3) var samp: sampler;
struct VsOut {
@builtin(position) position: vec4<f32>,
@location(0) uv: vec2<f32>,
};
@vertex
fn vs_main(@builtin(vertex_index) idx: u32) -> VsOut {
let x = f32(idx & 1u) * 4.0 - 1.0;
let y = f32((idx >> 1u) & 1u) * 4.0 - 1.0;
var out: VsOut;
out.position = vec4<f32>(x, y, 0.0, 1.0);
out.uv = vec2<f32>((x + 1.0) * 0.5, 1.0 - (y + 1.0) * 0.5);
return out;
}
@fragment
fn fs_main(in: VsOut) -> @location(0) vec4<f32> {
let primary = textureSample(primary_tex, samp, in.uv);
if (u.has_secondary == 0u) {
return primary;
}
let secondary = textureSample(secondary_tex, samp, in.uv);
return mix(secondary, primary, u.progress);
}
"#;