Skip to content

FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust

GPU6: GPU effects match the CPU on AMD (gamma, extract, invert, color replace) (#30)

Manuel Camachof2fefeeb4b31
diff --git a/crates/gpu/src/composite.wgsl b/crates/gpu/src/composite.wgsl
index 5e897ba32..04796d282 100644
--- a/crates/gpu/src/composite.wgsl
+++ b/crates/gpu/src/composite.wgsl
@@ -45,7 +45,10 @@ fn vs(@builtin(vertex_index) vi: u32) -> VOut {
fn load4(t: texture_2d<f32>, p: vec2<f32>) -> vec4<f32> {
let d = vec2<i32>(textureDimensions(t));
- let q = p - 0.5;
+ var q = p - 0.5;
+ let rq = round(q);
+ if abs(q.x - rq.x) < 1e-4 { q.x = rq.x; }
+ if abs(q.y - rq.y) < 1e-4 { q.y = rq.y; }
let i = vec2<i32>(floor(q));
let f = q - floor(q);
let a = textureLoad(t, clamp(i, vec2(0), d - 1), 0);
diff --git a/crates/gpu/src/fx.wgsl b/crates/gpu/src/fx.wgsl
index e74dfe63c..410e69a68 100644
--- a/crates/gpu/src/fx.wgsl
+++ b/crates/gpu/src/fx.wgsl
@@ -442,7 +442,10 @@ fn pixel(op: u32, p: vec2<i32>) -> vec4<f32> {
let o = ld(p);
let a = o.a;
let na = 1.0 - a;
- let k = select(0.0, na / a, a > 1e-6);
+ var k = 0.0;
+ if a > 1e-4 {
+ k = na / a;
+ }
let blend = u.p0.x;
return vec4(o.rgb * k, na * (1.0 - blend) + a * blend);
}