mirror of
https://github.com/storytold/effectcraft.git
synced 2026-11-16 15:22:43 +00:00
Merge remote-tracking branch 'origin/main' into fix/effect-gpu-integrated
This commit is contained in:
commit
600db3717f
170 files changed
+24940
-16818
No files matched your search
@@ -229,8 +229,11 @@ fn point(e: &mut Enc, id: &str, ctx: &EffectCtx, b: GBuf) -> Option<GBuf> {
|
||||
let rolloff = pr.f("highlightRolloff") as f32;
|
||||
let offset = |black: f32, white: f32| 10f32.powf((black - white) * 0.002 / 0.6);
|
||||
let knee = 1.0 - (rolloff / 100.0).clamp(0.0, 0.99);
|
||||
p.u[0] = [0, pr.e("conversionType"), 0, 0];
|
||||
p.f[0] = [offset(black, white), knee, white, pr.f("gamma") as f32];
|
||||
let version_2 = pr.f("version") >= 2.0;
|
||||
// Version 1 keeps the saved Gamma, where 1.7 gives linear output.
|
||||
let gamma = if version_2 { effectcraft_effects::cineon_gamma(pr) } else { pr.f("gamma") };
|
||||
p.u[0] = [0, pr.e("conversionType"), version_2 as u32, 0];
|
||||
p.f[0] = [offset(black, white), knee, white, gamma as f32];
|
||||
p.f[1] = [pr.f("internalBlackPoint") as f32, pr.f("internalWhitePoint") as f32, 0.0, 0.0];
|
||||
p.f[2] = [offset(95.0, 685.0), knee, 685.0, 1.7];
|
||||
}
|
||||
|
||||
@@ -29,8 +29,9 @@ fn fxe_circle(@builtin(global_invocation_id) gid: vec3<u32>) {
|
||||
if (P.u[0].z != 0u) {
|
||||
cov = 1.0 - cov;
|
||||
}
|
||||
let a = cov * P.f[1].z;
|
||||
textureStore(out, p, gen_blend(textureLoad(src, p, 0), vec4<f32>(P.f[2].xyz * a, a), P.u[0].x));
|
||||
let o = textureLoad(src, p, 0);
|
||||
let a = gen_alpha(cov * P.f[1].z, o.w, P.u[0].x);
|
||||
textureStore(out, p, gen_blend(o, vec4<f32>(P.f[2].xyz * a, a), P.u[0].x));
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- Ellipse (generate2::ellipse)
|
||||
|
||||
@@ -32,6 +32,12 @@ fn gen_blend(o: vec4<f32>, g: vec4<f32>, mode: u32) -> vec4<f32> {
|
||||
return blend_pixel(mode, o, g, 0.5);
|
||||
}
|
||||
|
||||
// generate::gen_alpha: with None (mode 255) the generated alpha `a` is scaled by the layer's
|
||||
// alpha, so the pattern stays inside the layer and its masks; other modes keep `a`.
|
||||
fn gen_alpha(a: f32, layer_a: f32, mode: u32) -> f32 {
|
||||
return select(a, a * layer_a, mode == 255u);
|
||||
}
|
||||
|
||||
// A (hi, lo) pair from `data`.
|
||||
fn gen_hl(i: u32) -> vec2<f32> {
|
||||
return vec2<f32>(data[i], data[i + 1u]);
|
||||
@@ -466,9 +472,10 @@ fn gen_checker(@builtin(global_invocation_id) gid: vec3<u32>) {
|
||||
}
|
||||
let sx = gen_axis(f32(p.x) + P.f[0].x, P.f[0].z, P.f[1].x);
|
||||
let sy = gen_axis(f32(p.y) + P.f[0].y, P.f[0].w, P.f[1].y);
|
||||
let cov = clamp(0.5 + 0.5 * sx * sy, 0.0, 1.0) * P.f[1].z;
|
||||
let o = textureLoad(src, p, 0);
|
||||
let a = gen_alpha(clamp(0.5 + 0.5 * sx * sy, 0.0, 1.0) * P.f[1].z, o.w, P.u[0].x);
|
||||
let c = P.f[2].xyz;
|
||||
textureStore(out, p, gen_blend(textureLoad(src, p, 0), vec4<f32>(c * cov, cov), P.u[0].x));
|
||||
textureStore(out, p, gen_blend(o, vec4<f32>(c * a, a), P.u[0].x));
|
||||
}
|
||||
|
||||
// f32::rem_euclid.
|
||||
@@ -502,8 +509,9 @@ fn gen_grid(@builtin(global_invocation_id) gid: vec3<u32>) {
|
||||
if (P.u[0].y != 0u) {
|
||||
cov = 1.0 - cov;
|
||||
}
|
||||
let a = cov * P.f[1].z;
|
||||
textureStore(out, p, gen_blend(textureLoad(src, p, 0), vec4<f32>(P.f[2].xyz * a, a), P.u[0].x));
|
||||
let o = textureLoad(src, p, 0);
|
||||
let a = gen_alpha(cov * P.f[1].z, o.w, P.u[0].x);
|
||||
textureStore(out, p, gen_blend(o, vec4<f32>(P.f[2].xyz * a, a), P.u[0].x));
|
||||
}
|
||||
|
||||
// u[0] = (mode, seed); f[0..4] = points (x, y); f[4..8] = colours;
|
||||
@@ -535,7 +543,7 @@ fn gen_fourcolor(@builtin(global_invocation_id) gid: vec3<u32>) {
|
||||
}
|
||||
let o = textureLoad(src, p, 0);
|
||||
// None keeps the layer's alpha, as the CPU path does (#1381).
|
||||
let op = select(P.f[8].z, P.f[8].z * o.w, P.u[0].x == 255u);
|
||||
let op = gen_alpha(P.f[8].z, o.w, P.u[0].x);
|
||||
textureStore(out, p, gen_blend(o, vec4<f32>(c * op, op), P.u[0].x));
|
||||
}
|
||||
|
||||
|
||||
@@ -258,10 +258,17 @@ fn fp2_vector(@builtin(global_invocation_id) gid: vec3<u32>) {
|
||||
// 3 CC Overbrights, 4 Color Link (alpha), 5 Color Link (blend), 6 CC Composite.
|
||||
|
||||
// utility::Cineon::log_to_lin; c = (offset, knee, white, gamma), r = (internal black, white).
|
||||
fn fp2_log_to_lin(v: f32, c: vec4<f32>, r: vec2<f32>) -> f32 {
|
||||
// Version 1 takes the saved Gamma, where 1.7 gives linear output.
|
||||
fn fp2_log_to_lin(v: f32, c: vec4<f32>, r: vec2<f32>, version_2: bool) -> f32 {
|
||||
let code = v * 1023.0;
|
||||
var lin = (pow(10.0, (code - c.z) * 0.002 / 0.6) - c.x) / max(1.0 - c.x, 1e-6);
|
||||
lin = powz(max(lin, 0.0), 1.7 / max(c.w, 0.01));
|
||||
let exposure = pow(10.0, (code - c.z) * 0.002 / 0.6);
|
||||
var lin: f32;
|
||||
if (version_2) {
|
||||
let root_offset = pow(c.x, 1.0 / max(c.w, 0.001));
|
||||
lin = max((pow(exposure, 1.0 / max(c.w, 0.001)) - root_offset) / max(1.0 - root_offset, 1e-6), 0.0);
|
||||
} else {
|
||||
lin = powz(max((exposure - c.x) / max(1.0 - c.x, 1e-6), 0.0), 1.7 / max(c.w, 0.01));
|
||||
}
|
||||
let k = c.y;
|
||||
if (k < 1.0 && lin > k) {
|
||||
let w = 1.0 - k;
|
||||
@@ -271,7 +278,7 @@ fn fp2_log_to_lin(v: f32, c: vec4<f32>, r: vec2<f32>) -> f32 {
|
||||
}
|
||||
|
||||
// utility::Cineon::lin_to_log.
|
||||
fn fp2_lin_to_log(v: f32, c: vec4<f32>, r: vec2<f32>) -> f32 {
|
||||
fn fp2_lin_to_log(v: f32, c: vec4<f32>, r: vec2<f32>, version_2: bool) -> f32 {
|
||||
let d = r.y - r.x;
|
||||
var lin = (v - r.x) / select(d, 1e-6, abs(d) < 1e-6);
|
||||
let k = c.y;
|
||||
@@ -279,8 +286,14 @@ fn fp2_lin_to_log(v: f32, c: vec4<f32>, r: vec2<f32>) -> f32 {
|
||||
let w = 1.0 - k;
|
||||
lin = k - w * log(max(1.0 - (lin - k) / w, 1e-6));
|
||||
}
|
||||
lin = powz(max(lin, 0.0), max(c.w, 0.01) / 1.7);
|
||||
let code = c.z + log(max(lin * (1.0 - c.x) + c.x, 1e-9)) * 0.4342944819032518 * 0.6 / 0.002;
|
||||
var exposure: f32;
|
||||
if (version_2) {
|
||||
let root_offset = pow(c.x, 1.0 / max(c.w, 0.001));
|
||||
exposure = powz(max(lin, 0.0) * (1.0 - root_offset) + root_offset, max(c.w, 0.001));
|
||||
} else {
|
||||
exposure = powz(max(lin, 0.0), max(c.w, 0.01) / 1.7) * (1.0 - c.x) + c.x;
|
||||
}
|
||||
let code = c.z + log(max(exposure, 1e-9)) * 0.4342944819032518 * 0.6 / 0.002;
|
||||
return code / 1023.0;
|
||||
}
|
||||
|
||||
@@ -292,15 +305,25 @@ fn fp2_spow(v: f32, e: f32) -> f32 {
|
||||
fn fp2_cineon(v: f32) -> f32 {
|
||||
let c = P.f[0];
|
||||
let r = P.f[1].xy;
|
||||
let version_2 = P.u[0].z != 0u;
|
||||
switch P.u[0].y {
|
||||
case 0u: {
|
||||
return fp2_lin_to_log(v, c, r);
|
||||
return fp2_lin_to_log(v, c, r, version_2);
|
||||
}
|
||||
case 1u: {
|
||||
return fp2_log_to_lin(v, c, r);
|
||||
return fp2_log_to_lin(v, c, r, version_2);
|
||||
}
|
||||
default: {
|
||||
return fp2_lin_to_log(fp2_log_to_lin(v, c, r), P.f[2], vec2<f32>(0.0, 1.0));
|
||||
if (version_2) {
|
||||
// Default points keep the input code; custom points pass through Gamma 1 first.
|
||||
var code = v;
|
||||
if (c.x != P.f[2].x || c.z != 685.0 || r.x != 0.0 || r.y != 1.0) {
|
||||
let unit = vec4<f32>(c.xyz, 1.0);
|
||||
code = fp2_lin_to_log(fp2_log_to_lin(v, unit, r, true), P.f[2], vec2<f32>(0.0, 1.0), false);
|
||||
}
|
||||
return powz(max(code, 0.0), 1.0 / max(c.w, 0.001));
|
||||
}
|
||||
return fp2_lin_to_log(fp2_log_to_lin(v, c, r, false), P.f[2], vec2<f32>(0.0, 1.0), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -314,7 +337,7 @@ fn fp2_point(@builtin(global_invocation_id) gid: vec3<u32>) {
|
||||
let px = textureLoad(src, p, 0);
|
||||
var o = px;
|
||||
switch P.u[0].x {
|
||||
// f[0], f[1], f[2]: see fp2_cineon; u[0].y = conversion type.
|
||||
// f[0], f[1], f[2]: see fp2_cineon; u[0].y = conversion type, z = version 2.
|
||||
case 0u: {
|
||||
if (px.w > 0.0) {
|
||||
let c = px.xyz / px.w;
|
||||
|
||||
@@ -179,7 +179,14 @@ fn composites_and_colour() {
|
||||
env_case("ec.color.colorlink", &[("sourceLayer", Value::Layer(Some(9))), ("sampleSource", e(4)), ("clip", n(5.0))]);
|
||||
effect_case("ec.utility.cineon", &[]);
|
||||
effect_case("ec.utility.cineon", &[("conversionType", e(0)), ("gamma", n(2.2))]);
|
||||
effect_case("ec.utility.cineon", &[("version", n(1.0)), ("gamma", n(2.2))]);
|
||||
effect_case("ec.utility.cineon", &[("version", n(1.0)), ("gamma", n(0.0)), ("conversionType", e(0))]);
|
||||
effect_case("ec.utility.cineon", &[("conversionType", e(2)), ("highlightRolloff", n(60.0)), ("tenBitWhitePoint", n(800.0))]);
|
||||
effect_case("ec.utility.cineon", &[("conversionType", e(1)), ("gamma", n(1.7)), ("highlightRolloff", n(0.0))]);
|
||||
effect_case("ec.utility.cineon", &[("conversionType", e(1)), ("gamma", n(2.2)), ("highlightRolloff", n(0.0))]);
|
||||
effect_case("ec.utility.cineon", &[("conversionType", e(2)), ("gamma", n(1.0)), ("highlightRolloff", n(0.0))]);
|
||||
effect_case("ec.utility.cineon", &[("conversionType", e(2)), ("gamma", n(1.7))]);
|
||||
env_case_allow("ec.utility.cineon", &[("version", n(1.0)), ("conversionType", e(2)), ("gamma", n(2.2))], 0.005);
|
||||
effect_case("ec.utility.hdrcompander", &[("gain", n(4.0)), ("gamma", n(2.0))]);
|
||||
effect_case("ec.utility.hdrcompander", &[("mode", e(1)), ("gain", n(3.0)), ("gamma", n(1.5))]);
|
||||
effect_case("ec.utility.hdrcompression", &[]);
|
||||
@@ -210,6 +217,31 @@ fn hdr_compression_over_range() {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cineon_version_2_paths_match_cpu() {
|
||||
for vals in [
|
||||
&[("conversionType", e(2)), ("gamma", n(1.0)), ("highlightRolloff", n(0.0))][..],
|
||||
&[("conversionType", e(2)), ("gamma", n(1.0)), ("highlightRolloff", n(20.0))][..],
|
||||
&[("conversionType", e(2)), ("gamma", n(1.7)), ("highlightRolloff", n(20.0))][..],
|
||||
&[("conversionType", e(1)), ("gamma", n(2.2)), ("highlightRolloff", n(0.0))][..],
|
||||
] {
|
||||
env_case_allow("ec.utility.cineon", vals, 0.005);
|
||||
}
|
||||
let Some(g) = gpu() else { return };
|
||||
let spec = effectcraft_effects::find("ec.utility.cineon").unwrap();
|
||||
let mut params =
|
||||
effectcraft_effects::Params { values: spec.params.iter().map(|ps| (ps.id.to_string(), effectcraft_effects::default_value(ps, [1.0, 1.0]))).collect() };
|
||||
params.values.insert("gamma".into(), n(1.7));
|
||||
params.values.insert("highlightRolloff".into(), n(0.0));
|
||||
let mut img = effectcraft_raster::Image::new(1, 1);
|
||||
img.set(0, 0, [400.0 / 1023.0, 400.0 / 1023.0, 400.0 / 1023.0, 1.0]);
|
||||
let buf = Buf { img, offset: [0.0; 2], scale: 1.0 };
|
||||
let ctx = effectcraft_effects::EffectCtx { params: ¶ms, time: 0.0, layer_size: [1.0, 1.0], seed: 0, adjustment: false, env: EffectEnv::default() };
|
||||
let out = effectcraft_render::Accelerator::effects(g, &[effectcraft_render::FxStep { spec, ctx }], &buf, None).expect("the GPU runs the effect");
|
||||
let got = (out.img.get(0, 0)[0].clamp(0.0, 1.0) * 255.0).round() as i32;
|
||||
assert!((got - 57).abs() <= 1, "code 400: {got} vs 57");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stylize() {
|
||||
let _flips = allow_llvmpipe_boundary_flips();
|
||||
|
||||
Reference in new issue
Block a user