Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

fix(gpu): match CPU Dissolve coverage for adjustment, clipping and effects

Nigel Ihza Firdausy61724b49f0fa
diff --git a/crates/gpu/src/compose.wgsl b/crates/gpu/src/compose.wgsl
index 6457b1192..8aeea51d4 100644
--- a/crates/gpu/src/compose.wgsl
+++ b/crates/gpu/src/compose.wgsl
@@ -833,6 +833,9 @@ fn fs_atop(in: VOut) -> @location(0) vec4<f32> {
let base = textureLoad(tex_a, p, 0);
if (base.a <= 0.0) { return base; }
let s = textureLoad(tex_b, p, 0);
+ if (op.mode == M_DISSOLVE) {
+ return select(base, vec4(s.rgb, base.a), dissolve_noise(doc_px(p)) < s.a * op.opacity);
+ }
let r = composite_g(op.mode, vec4(base.rgb, 1.0), s, op.opacity, (op.flags & F_TEXT_GAMMA) != 0u);
return vec4(r.rgb, base.a);
}
@@ -855,6 +858,9 @@ fn fs_adjmix(in: VOut) -> @location(0) vec4<f32> {
let k = op.opacity * mask_value(doc_px(p));
if (k <= 0.0) { return b; }
let a = textureLoad(tex_b, p, 0);
+ if (op.mode == M_DISSOLVE) {
+ return select(b, vec4(a.rgb, b.a), dissolve_noise(doc_px(p)) < k);
+ }
let bl = blend_rgb(op.mode, b.rgb, a.rgb);
return vec4(b.rgb + (bl - b.rgb) * k, b.a);
}
@@ -1174,7 +1180,9 @@ fn fs_fxmerge(in: VOut) -> @location(0) vec4<f32> {
let atop = (op.flags & F_ATOP) != 0u;
var before = c;
if (atop) { before = vec4(c.rgb, 1.0); }
- let o = mix_premul(before, w, op.opacity);
+ let o = select(mix_premul(before, w, op.opacity),
+ select(before, w, dissolve_noise(doc_px(p)) < op.opacity),
+ op.mode == M_DISSOLVE);
if (atop) {
if (c.a > 0.0) { return vec4(o.rgb, c.a); }
return c;