mirror of
https://github.com/italicsjenga/vello.git
synced 2025-01-09 20:31:29 +11:00
Address review feedback
* Add comment about avoiding NaNs to inverse alpha divisions * Change inverse alpha computations to use max(a, epsilon) rather than + * Emit alpha component in blit fragment shader (enables support for partially transparent windows)
This commit is contained in:
parent
4fea305883
commit
923765aff9
|
@ -282,8 +282,9 @@ fn main(
|
|||
let coords = xy_uint + vec2(i, 0u);
|
||||
if coords.x < config.target_width && coords.y < config.target_height {
|
||||
let fg = rgba[i];
|
||||
let a_inv = 1.0 / (fg.a + 1e-6);
|
||||
let rgba_sep = vec4(fg.r * a_inv, fg.g * a_inv, fg.b * a_inv, fg.a);
|
||||
// Max with a small epsilon to avoid NaNs
|
||||
let a_inv = 1.0 / max(fg.a, 1e-6);
|
||||
let rgba_sep = vec4(fg.rgb * a_inv, fg.a);
|
||||
textureStore(output, vec2<i32>(coords), rgba_sep);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -318,10 +318,10 @@ fn blend_mix_compose(backdrop: vec4<f32>, src: vec4<f32>, mode: u32) -> vec4<f32
|
|||
// Both normal+src_over blend and clip case
|
||||
return backdrop * (1.0 - src.a) + src;
|
||||
}
|
||||
// Un-premultiply colors for blending
|
||||
let inv_src_a = 1.0 / (src.a + EPSILON);
|
||||
// Un-premultiply colors for blending. Max with a small epsilon to avoid NaNs.
|
||||
let inv_src_a = 1.0 / max(src.a, EPSILON);
|
||||
var cs = src.rgb * inv_src_a;
|
||||
let inv_backdrop_a = 1.0 / (backdrop.a + EPSILON);
|
||||
let inv_backdrop_a = 1.0 / max(backdrop.a, EPSILON);
|
||||
let cb = backdrop.rgb * inv_backdrop_a;
|
||||
let mix_mode = mode >> 8u;
|
||||
let mixed = blend_mix(cb, cs, mix_mode);
|
||||
|
|
|
@ -205,7 +205,7 @@ impl BlitPipeline {
|
|||
@fragment
|
||||
fn fs_main(@builtin(position) pos: vec4<f32>) -> @location(0) vec4<f32> {
|
||||
let rgba_sep = textureLoad(fine_output, vec2<i32>(pos.xy), 0);
|
||||
return vec4(rgba_sep.rgb * rgba_sep.a, 1.0);
|
||||
return vec4(rgba_sep.rgb * rgba_sep.a, rgba_sep.a);
|
||||
}
|
||||
"#;
|
||||
|
||||
|
|
Loading…
Reference in a new issue