{
R"wgsl(@group(0) @binding(0) var inputTexture: texture_2d<f32>;
@group(0) @binding(1) var outputTexture: texture_storage_2d<rgba8unorm, write>;
@compute @workgroup_size(8, 8, 1)
fn cs_main(@builtin(global_invocation_id) gid: vec3<u32>) {
let extent = min(textureDimensions(inputTexture), textureDimensions(outputTexture));
if (any((gid.xy >= extent))) {
return;
}
let coords = vec2<i32>(gid.xy);
let premul = textureLoad(inputTexture, coords, 0i);
let r8 = u32(round((premul.x * 255f)));
let g8 = u32(round((premul.y * 255f)));
let b8 = u32(round((premul.z * 255f)));
let a8 = u32(round((premul.w * 255f)));
var sr: u32 = 0u;
var sg: u32 = 0u;
var sb: u32 = 0u;
if ((a8 != 0u)) {
let halfAlpha = (a8 >> 1u);
sr = min(255u, (((r8 * 255u) + halfAlpha) / a8));
sg = min(255u, (((g8 * 255u) + halfAlpha) / a8));
sb = min(255u, (((b8 * 255u) + halfAlpha) / a8));
}
let straight = vec4<f32>((f32(sr) / 255f), (f32(sg) / 255f), (f32(sb) / 255f), (f32(a8) / 255f));
textureStore(outputTexture, coords, straight);
}
)wgsl"}
Authoritative WGSL for the snapshot readback unpremultiply pass.