| author | |
| committer | |
| log | 7b67be7af565d0fe15f0fe9cef70188105c52ac5 |
| tree | 8b8597c695b830589d1a8cc023c6f2c54cfab9f9 |
| parent | 4b05551050c90049563a0a4869e2ba7ee5a27041 |
| signature | Signed by SSH key SHA256:52mNGHRsVFBDED9IAX5pe+LRWUefqTbxEReunq21QvU |
Assisted-by: claude-opus-5.518 files changed, 338 insertions(+), 473 deletions(-)
crates/engine/src/eval/alpha_keyers.rs+28-41| ... | ... | @@ -363,7 +363,7 @@ impl Engine { |
| 363 | 363 | |
| 364 | 364 | let mut u = UniformParams::default(); |
| 365 | 365 | u.p[0] = [b2f(is_divide), blend, b2f(mask.is_some()), b2f(mask_inv)]; |
| 366 | u.p[1] = [b2f(mbm), 0.0, 0.0, 0.0]; | |
| 366 | u.p[1] = [b2f(mbm), b2f(src.depth == BitDepth::Int8), 0.0, 0.0]; | |
| 367 | 367 | u.p[2] = self.process_skip(comp, node, time); |
| 368 | 368 | |
| 369 | 369 | let tag = if is_divide { "AlphaDivide" } else { "AlphaMultiply" }; |
| ... | ... | @@ -419,32 +419,18 @@ impl Engine { |
| 419 | 419 | let (mask, mask_inv) = self.eval_mask_input_sized(comp, node, time, Some(src.size), enc, visiting, stats); |
| 420 | 420 | let mask_hash = mask.as_ref().map_or(0, |m| m.content_hash); |
| 421 | 421 | |
| 422 | let ch_cfg = |pfx: &str| -> [f32; 4] { | |
| 423 | [ | |
| 424 | comp.eval_number(node, &format!("{pfx}Low"), time, 0.0, &self.expr) as f32, | |
| 425 | comp.eval_number(node, &format!("{pfx}High"), time, 1.0, &self.expr) as f32, | |
| 426 | eval_num_alias(comp, node, &format!("{pfx}Frequency"), &format!("{pfx}Freq"), time, 1.0, &self.expr) as f32, | |
| 427 | comp.eval_number(node, &format!("{pfx}Phase"), time, 0.0, &self.expr) as f32, | |
| 428 | ] | |
| 429 | }; | |
| 430 | let use_alpha = if node.inputs.contains_key("UseAlpha") { | |
| 431 | comp.eval_number(node, "UseAlpha", time, 0.0, &self.expr) > 0.5 | |
| 432 | } else { | |
| 433 | ["AlphaLow", "AlphaHigh", "AlphaFrequency", "AlphaFreq", "AlphaPhase"] | |
| 434 | .iter() | |
| 435 | .any(|k| node.inputs.contains_key(*k)) | |
| 436 | }; | |
| 437 | ||
| 422 | let num = |id: String, default: f64| comp.eval_number(node, &id, time, default, &self.expr) as f32; | |
| 438 | 423 | let mut u = UniformParams::default(); |
| 439 | u.p[0] = ch_cfg("Red"); | |
| 440 | u.p[1] = ch_cfg("Green"); | |
| 441 | u.p[2] = ch_cfg("Blue"); | |
| 442 | u.p[3] = ch_cfg("Alpha"); | |
| 443 | u.p[4] = [b2f(use_alpha), blend, b2f(mask.is_some()), b2f(mask_inv)]; | |
| 444 | u.p[5] = [b2f(mbm), 0.0, 0.0, 0.0]; | |
| 445 | u.p[6] = self.process_skip(comp, node, time); | |
| 446 | ||
| 447 | let key = self.make_key(node, "PseudoColor", src.size, &[src.content_hash, mask_hash], bytemuck::cast_slice(&u.p[..7])); | |
| 424 | for (c, (name, enabled)) in [("Red", 1.0), ("Green", 1.0), ("Blue", 1.0), ("Alpha", 0.0)].into_iter().enumerate() { | |
| 425 | u.p[c * 3] = [num(format!("{name}Low"), 0.0), num(format!("{name}High"), 1.0), num(format!("{name}SoftEdge"), 0.0), num(format!("{name}Waveform"), 0.0)]; | |
| 426 | u.p[c * 3 + 1] = [num(format!("{name}Frequency"), 1.0), num(format!("{name}Phase"), 0.0), num(format!("{name}Mean"), 0.5), num(format!("{name}Amplitude"), 0.5)]; | |
| 427 | u.p[c * 3 + 2] = [num(name.to_string(), enabled), num(format!("{name}Wrap"), 0.0), 0.0, 0.0]; | |
| 428 | } | |
| 429 | u.p[12] = [blend, b2f(mask.is_some()), b2f(mask_inv), b2f(mbm)]; | |
| 430 | u.p[13] = self.process_skip(comp, node, time); | |
| 431 | u.p[14] = [b2f(src.depth == BitDepth::Int8), 0.0, 0.0, 0.0]; | |
| 432 | ||
| 433 | let key = self.make_key(node, "PseudoColor", src.size, &[src.content_hash, mask_hash], bytemuck::cast_slice(&u.p[..15])); | |
| 448 | 434 | if let Some(hit) = self.cache.get(key, node.id, frame_i) { |
| 449 | 435 | stats.cache_hits += 1; |
| 450 | 436 | return hit; |
| ... | ... | @@ -853,32 +839,33 @@ mod tests { |
| 853 | 839 | } |
| 854 | 840 | |
| 855 | 841 | #[test] |
| 856 | fn pseudo_color_sine_wave_ranges_freq_phase_and_use_alpha() { | |
| 842 | fn pseudo_color_waveforms_ranges_and_alpha() { | |
| 857 | 843 | let src = r#"Composition { Tools = ordered() { |
| 858 | 844 | Ramp = Background { Inputs = { Width = Input { Value = 128, }, Height = Input { Value = 16, }, Type = Input { Value = FuID { "Horizontal" }, }, |
| 859 | TopLeftRed = Input { Value = 0.0, }, TopLeftGreen = Input { Value = 0.0, }, TopLeftBlue = Input { Value = 0.0, }, TopLeftAlpha = Input { Value = 0.25, }, | |
| 860 | TopRightRed = Input { Value = 1.0, }, TopRightGreen = Input { Value = 1.0, }, TopRightBlue = Input { Value = 1.0, }, TopRightAlpha = Input { Value = 0.25, }, }, }, | |
| 845 | TopLeftRed = Input { Value = 0.0, }, TopLeftGreen = Input { Value = 0.0, }, TopLeftBlue = Input { Value = 0.0, }, | |
| 846 | TopRightRed = Input { Value = 1.0, }, TopRightGreen = Input { Value = 1.0, }, TopRightBlue = Input { Value = 1.0, }, }, }, | |
| 861 | 847 | PCDef = PseudoColor { Inputs = { Input = Input { SourceOp = "Ramp", Source = "Output", }, }, }, |
| 862 | PCRange = PseudoColor { Inputs = { Input = Input { SourceOp = "Ramp", Source = "Output", }, RedHigh = Input { Value = 0.828, }, GreenLow = Input { Value = 0.506, }, }, }, | |
| 863 | PCFreq = PseudoColor { Inputs = { Input = Input { SourceOp = "Ramp", Source = "Output", }, RedFreq = Input { Value = 2.0, }, RedPhase = Input { Value = 0.25, }, UseAlpha = Input { Value = 1, }, }, }, | |
| 848 | PCRange = PseudoColor { Inputs = { Input = Input { SourceOp = "Ramp", Source = "Output", }, RedHigh = Input { Value = 0.5, }, GreenWaveform = Input { Value = 2, }, Blue = Input { Value = 0, }, }, }, | |
| 849 | PCAlpha = PseudoColor { Inputs = { Input = Input { SourceOp = "Ramp", Source = "Output", }, RedFrequency = Input { Value = 2.0, }, RedPhase = Input { Value = 0.25, }, Alpha = Input { Value = 1, }, AlphaPhase = Input { Value = 0.25, }, }, }, | |
| 864 | 850 | } }"#; |
| 865 | 851 | let comp = Comp::from_fusion_str(src).expect("parse PseudoColor comp"); |
| 866 | 852 | let Ok(mut eng) = Engine::new_headless() else { return }; |
| 867 | 853 | |
| 868 | 854 | let (_, def) = eval_px(&mut eng, &comp, "PCDef"); |
| 869 | assert!((px_at(&def, 128, 0, 8)[0] as i32 - 131).abs() <= 3); | |
| 870 | assert!(px_at(&def, 128, 32, 8)[0] >= 252); | |
| 855 | assert!((px_at(&def, 128, 0, 8)[0] as i32 - 128).abs() <= 3, "sine is centered on Mean at v=0"); | |
| 856 | assert!(px_at(&def, 128, 32, 8)[0] >= 252, "sine peaks at v=0.25"); | |
| 871 | 857 | assert!(px_at(&def, 128, 96, 8)[0] <= 3); |
| 872 | assert!((px_at(&def, 128, 32, 8)[3] as i32 - 64).abs() <= 2, "UseAlpha=0 keeps alpha untouched"); | |
| 858 | assert_eq!(px_at(&def, 128, 32, 8)[3], 255, "Alpha is off by default"); | |
| 873 | 859 | |
| 874 | 860 | let (_, rng) = eval_px(&mut eng, &comp, "PCRange"); |
| 875 | assert!((px_at(&rng, 128, 32, 8)[1] as i32 - 64).abs() <= 3); | |
| 876 | assert!(px_at(&rng, 128, 127, 8)[0] >= 252); | |
| 877 | ||
| 878 | let (_, frq) = eval_px(&mut eng, &comp, "PCFreq"); | |
| 879 | assert!(px_at(&frq, 128, 0, 8)[0] >= 252); | |
| 880 | assert!(px_at(&frq, 128, 32, 8)[0] <= 4); | |
| 881 | assert!(px_at(&frq, 128, 32, 8)[3] >= 252, "UseAlpha=1 maps a=0.25 -> sin(pi/2) -> 255"); | |
| 861 | assert!((px_at(&rng, 128, 100, 8)[0] as i32 - 200).abs() <= 3, "values above High pass through"); | |
| 862 | assert!((px_at(&rng, 128, 32, 8)[1] as i32 - 192).abs() <= 3, "sawtooth runs fract(v + 0.5)"); | |
| 863 | assert!((px_at(&rng, 128, 32, 8)[2] as i32 - 64).abs() <= 3, "disabled channels pass through"); | |
| 864 | ||
| 865 | let (_, alp) = eval_px(&mut eng, &comp, "PCAlpha"); | |
| 866 | assert!(px_at(&alp, 128, 0, 8)[0] >= 252); | |
| 867 | assert!(px_at(&alp, 128, 32, 8)[0] <= 4); | |
| 868 | assert!(px_at(&alp, 128, 32, 8)[3] >= 252, "Alpha=1 maps a=1 through sin(2 pi (1 + 0.25))"); | |
| 882 | 869 | } |
| 883 | 870 | |
| 884 | 871 | #[test] |
crates/engine/src/eval/color_lut/lut_io.rs+8-7| ... | ... | @@ -516,18 +516,19 @@ impl Engine { |
| 516 | 516 | if blend <= 1e-6 && !(mbm && has_mask) { |
| 517 | 517 | return src; |
| 518 | 518 | } |
| 519 | let Some(cube_id) = node | |
| 519 | let cube = node | |
| 520 | 520 | .connected_node("LUTCubeImage") |
| 521 | 521 | .or_else(|| node.connected_node("LUTImage")) |
| 522 | 522 | .or_else(|| node.connected_node("Input2")) |
| 523 | 523 | .and_then(|s| comp.find_node(s)) |
| 524 | else { | |
| 525 | return src; | |
| 526 | }; | |
| 527 | let cube = self.eval_node(comp, cube_id, time, enc, visiting, stats); | |
| 528 | let Some((lut_n, tiles_x)) = infer_cube_layout(cube.size[0], cube.size[1]) else { | |
| 524 | .map(|cube_id| self.eval_node(comp, cube_id, time, enc, visiting, stats)); | |
| 525 | // Without a usable cube the LUT is an identity, which MultiplyByMask still masks. | |
| 526 | let layout = cube.as_ref().and_then(|c| infer_cube_layout(c.size[0], c.size[1])); | |
| 527 | if layout.is_none() && !mbm { | |
| 529 | 528 | return src; |
| 530 | }; | |
| 529 | } | |
| 530 | let (lut_n, tiles_x) = layout.unwrap_or((0, 1)); | |
| 531 | let cube = cube.unwrap_or_else(|| self.dummy.clone()); | |
| 531 | 532 | |
| 532 | 533 | let src = if has_mask { self.crop_to_canvas(enc, src) } else { src }; |
| 533 | 534 | let (mask, mask_inv) = self.eval_mask_input_sized(comp, node, time, Some(src.size), enc, visiting, stats); |
crates/engine/src/eval/color_science/params.rs+3-1| ... | ... | @@ -200,7 +200,9 @@ pub(super) fn parse_color_type(comp: &Comp, node: &Node, time: f64, expr: &ExprE |
| 200 | 200 | _ => 0, |
| 201 | 201 | }; |
| 202 | 202 | } |
| 203 | comp.eval_number(node, "ColorType", time, 0.0, expr).round().clamp(0.0, 8.0) as i32 | |
| 203 | // Fusion's numeric order is HSV, YUV, YIQ, CMY, HLS, XYZ, Negative, BW; Negative inverts like CMY. | |
| 204 | const FUSION_ORDER: [i32; 8] = [5, 1, 2, 3, 4, 6, 3, 0]; | |
| 205 | FUSION_ORDER[comp.eval_number(node, "ColorType", time, 0.0, expr).round().clamp(0.0, 7.0) as usize] | |
| 204 | 206 | } |
| 205 | 207 | |
| 206 | 208 | pub(super) fn parse_color_space_dir(comp: &Comp, node: &Node, time: f64, expr: &ExprEngine) -> i32 { |
crates/engine/src/eval/depth_optical.rs+43-41| ... | ... | @@ -1,7 +1,7 @@ |
| 1 | 1 | //! Wave 35B — Depth, Optical & Filter FX GPU pipelines and evaluators: |
| 2 | 2 | //! - `DepthBlur` (depth-driven CoC blur from `BlurImage`/`BlurChannel` or `aux.z`) |
| 3 | //! - `Fog` (depth-driven atmospheric fog from `aux.z` or `FogImage`/`Fog`) | |
| 4 | //! - `Highlight` (2-pass bright-threshold extraction + directional starburst streaks) | |
| 3 | //! - `Fog` (depth-driven atmospheric fog from `aux.z`, colored by the optional `Fog` image) | |
| 4 | //! - `Highlight` (2-pass bright-threshold extraction + exponential starburst streaks) | |
| 5 | 5 | //! - `HotSpot` (radial primary glow + secondary optical lens flare elements) |
| 6 | 6 | //! - `RankFilter` (GPU order-statistic Min/Median/Max/Percentile filter) |
| 7 | 7 | //! |
| ... | ... | @@ -487,7 +487,7 @@ impl Engine { |
| 487 | 487 | dst |
| 488 | 488 | } |
| 489 | 489 | |
| 490 | /// 2. `Fog`: depth-driven atmospheric fog from `aux.z` or `FogImage`/`Fog`. | |
| 490 | /// 2. `Fog`: depth-driven atmospheric fog from `aux.z`, colored by the optional `Fog` image. | |
| 491 | 491 | #[allow(clippy::too_many_arguments)] |
| 492 | 492 | pub(super) fn eval_fog( |
| 493 | 493 | &mut self, |
| ... | ... | @@ -513,8 +513,7 @@ impl Engine { |
| 513 | 513 | let src_aux = src.aux.clone(); |
| 514 | 514 | let src = self.crop_to_canvas(enc, src); |
| 515 | 515 | let fog_img = node |
| 516 | .connected_node("FogImage") | |
| 517 | .or_else(|| node.connected_node("Fog")) | |
| 516 | .connected_node("Fog") | |
| 518 | 517 | .and_then(|s| comp.find_node(s)) |
| 519 | 518 | .map(|fid| { |
| 520 | 519 | let t = self.eval_node(comp, fid, time, enc, visiting, stats); |
| ... | ... | @@ -528,19 +527,19 @@ impl Engine { |
| 528 | 527 | if let Some(fz) = fi.aux.as_ref().and_then(|a| a.z.clone()) { |
| 529 | 528 | (0, false, Some(fz)) |
| 530 | 529 | } else { |
| 531 | (1, false, None) | |
| 530 | (1, true, None) | |
| 532 | 531 | } |
| 533 | 532 | } else { |
| 534 | (0, false, None) | |
| 533 | (1, false, None) | |
| 535 | 534 | }; |
| 536 | 535 | |
| 537 | 536 | let near_p = self.eval_num_alias(comp, node, "ZNearPlane", "NearPlane", time, 0.0); |
| 538 | let far_p = self.eval_num_alias(comp, node, "ZFarPlane", "FarPlane", time, -100.0); | |
| 537 | let far_p = self.eval_num_alias(comp, node, "ZFarPlane", "FarPlane", time, -500.0); | |
| 539 | 538 | let falloff = comp.eval_number(node, "Falloff", time, 1.0, &self.expr) as f32; |
| 540 | 539 | let z_scale = comp.eval_number(node, "ZScale", time, 1.0, &self.expr) as f32; |
| 541 | let fog_r = comp.eval_number(node, "FogRed", time, 1.0, &self.expr) as f32; | |
| 542 | let fog_g = comp.eval_number(node, "FogGreen", time, 1.0, &self.expr) as f32; | |
| 543 | let fog_b = comp.eval_number(node, "FogBlue", time, 1.0, &self.expr) as f32; | |
| 540 | let fog_r = comp.eval_number(node, "FogRed", time, 0.7, &self.expr) as f32; | |
| 541 | let fog_g = comp.eval_number(node, "FogGreen", time, 0.7, &self.expr) as f32; | |
| 542 | let fog_b = comp.eval_number(node, "FogBlue", time, 0.8, &self.expr) as f32; | |
| 544 | 543 | let fog_a = comp.eval_number(node, "FogAlpha", time, 1.0, &self.expr) as f32; |
| 545 | 544 | let (mask, mask_inv) = self.eval_mask_input_sized(comp, node, time, Some(src.size), enc, visiting, stats); |
| 546 | 545 | let skip = self.process_skip(comp, node, time); |
| ... | ... | @@ -589,7 +588,7 @@ impl Engine { |
| 589 | 588 | dst |
| 590 | 589 | } |
| 591 | 590 | |
| 592 | /// 3. `Highlight`: threshold bright pixels (`Low`/`High`) + directional starburst streaks. | |
| 591 | /// 3. `Highlight`: threshold bright pixels (`Low`/`High`/`Curve`) + exponential starburst streaks. | |
| 593 | 592 | #[allow(clippy::too_many_arguments)] |
| 594 | 593 | pub(super) fn eval_highlight( |
| 595 | 594 | &mut self, |
| ... | ... | @@ -611,33 +610,37 @@ impl Engine { |
| 611 | 610 | return src; |
| 612 | 611 | } |
| 613 | 612 | let src = self.crop_to_canvas(enc, src); |
| 614 | ||
| 615 | let low = comp.eval_number(node, "Low", time, 0.75, &self.expr) as f32; | |
| 616 | let high = comp.eval_number(node, "High", time, 1.0, &self.expr) as f32; | |
| 617 | let num_points = comp.eval_number(node, "NumberOfPoints", time, 4.0, &self.expr).clamp(1.0, 16.0) as f32; | |
| 618 | let angle_deg = comp.eval_number(node, "Angle", time, 0.0, &self.expr) as f32; | |
| 619 | let length_norm = comp.eval_number(node, "Length", time, 0.15, &self.expr).max(0.0) as f32; | |
| 620 | // Length is normalized to image width; src.size[0] already scales cleanly by proxy_scale. | |
| 621 | let length_px = (length_norm * src.size[0] as f32).min(256.0); | |
| 622 | let falloff = self.eval_num_alias(comp, node, "Falloff", "Decay", time, 1.0); | |
| 623 | let strength = self.eval_num_alias(comp, node, "Strength", "Gain", time, 1.0); | |
| 624 | let tint_r = self.eval_num_alias(comp, node, "ColorRed", "RedScale", time, 1.0); | |
| 625 | let tint_g = self.eval_num_alias(comp, node, "ColorGreen", "GreenScale", time, 1.0); | |
| 626 | let tint_b = self.eval_num_alias(comp, node, "ColorBlue", "BlueScale", time, 1.0); | |
| 627 | let merge_orig = comp.eval_number(node, "MergeWithOriginal", time, 1.0, &self.expr) > 0.5; | |
| 628 | 613 | let (mask, mask_inv) = self.eval_mask_input_sized(comp, node, time, Some(src.size), enc, visiting, stats); |
| 629 | 614 | let skip = self.process_skip(comp, node, time); |
| 630 | let steps = if self.hiq { 28.0 } else { 14.0 }; | |
| 615 | let num = |id: &str, default: f64| comp.eval_number(node, id, time, default, &self.expr) as f32; | |
| 616 | ||
| 617 | // Each streak tap s pixels away weighs d^s with d = log10((1 + 9 * Length) * ChannelScale), independent of resolution. | |
| 618 | let length_gain = 1.0 + 9.0 * num("Length", 0.8); | |
| 619 | let decay = ["RedScale", "GreenScale", "BlueScale", "AlphaScale"].map(|id| (length_gain * num(id, 1.0)).log10().max(0.0)); | |
| 620 | let d_max = decay.into_iter().fold(0.0, f32::max); | |
| 621 | let reach = (src.size[0] as f32).hypot(src.size[1] as f32).ceil(); | |
| 622 | // Fusion stops once the strongest weight falls below e^-10 or would exceed 32768. | |
| 623 | let taps = match d_max { | |
| 624 | d if d <= 0.0 => 0.0, | |
| 625 | d if d < 1.0 => (-10.0 / d.ln()).floor().min(reach), | |
| 626 | d if d > 1.0 => (32768f32.ln() / d.ln()).floor().min(reach), | |
| 627 | _ => reach, | |
| 628 | }; | |
| 631 | 629 | |
| 632 | 630 | let mut u_ext = UniformParams::default(); |
| 633 | u_ext.p[0] = [low, high, strength, 0.0]; | |
| 631 | u_ext.p[0] = [num("Low", 0.9), num("High", 1.0), num("Curve", 1.0), (src.depth == BitDepth::Int8) as u8 as f32]; | |
| 634 | 632 | |
| 635 | 633 | let mut u_str = UniformParams::default(); |
| 636 | u_str.p[0] = [num_points, angle_deg.to_radians(), length_px, falloff]; | |
| 637 | u_str.p[1] = [tint_r, tint_g, tint_b, merge_orig as u8 as f32]; | |
| 634 | u_str.p[0] = [ | |
| 635 | num("NumberOfPoints", 4.0).round().clamp(1.0, 64.0), | |
| 636 | num("Angle", 0.0).to_radians(), | |
| 637 | taps, | |
| 638 | (num("MergeOver", 1.0) > 0.5) as u8 as f32, | |
| 639 | ]; | |
| 640 | u_str.p[1] = decay; | |
| 638 | 641 | u_str.p[2] = [blend, mask.is_some() as u8 as f32, mask_inv as u8 as f32, mbm as u8 as f32]; |
| 639 | 642 | u_str.p[3] = skip; |
| 640 | u_str.p[4] = [steps, low, high, strength]; | |
| 643 | u_str.p[4] = u_ext.p[0]; | |
| 641 | 644 | |
| 642 | 645 | let mask_hash = mask.as_ref().map_or(0, |m| m.content_hash); |
| 643 | 646 | let key = self.make_key( |
| ... | ... | @@ -654,7 +657,7 @@ impl Engine { |
| 654 | 657 | stats.cache_misses += 1; |
| 655 | 658 | stats.nodes_evaluated += 1; |
| 656 | 659 | |
| 657 | let bright = self.alloc_tex(src.size, src.depth, 0); | |
| 660 | let bright = self.alloc_tex(src.size, src.depth.max(BitDepth::Float32), 0); | |
| 658 | 661 | let mut dst = self.alloc_tex_like(&src, src.depth, key); |
| 659 | 662 | if src.aux.is_some() && dst.size == src.size && dst.origin == src.origin { |
| 660 | 663 | dst.set_aux(src.aux.clone()); |
| ... | ... | @@ -1099,7 +1102,7 @@ mod tests { |
| 1099 | 1102 | FogTex = Fog {{ |
| 1100 | 1103 | Inputs = {{ |
| 1101 | 1104 | Input = Input {{ SourceOp = "Scene", Source = "Output", }}, |
| 1102 | FogImage = Input {{ SourceOp = "TintImg", Source = "Output", }}, | |
| 1105 | Fog = Input {{ SourceOp = "TintImg", Source = "Output", }}, | |
| 1103 | 1106 | NearPlane = Input {{ Value = -2.0, }}, |
| 1104 | 1107 | FarPlane = Input {{ Value = -30.0, }}, |
| 1105 | 1108 | }}, |
| ... | ... | @@ -1126,7 +1129,7 @@ mod tests { |
| 1126 | 1129 | |
| 1127 | 1130 | let (_, px_t) = eval_px(&mut eng, &comp, "FogTex"); |
| 1128 | 1131 | let far_t = px_at(&px_t, 32, 28, 16); |
| 1129 | assert!(far_t[0] <= 3 && far_t[1] >= 250 && far_t[2] >= 250, "FogImage cyan must tint far fog, got {far_t:?}"); | |
| 1132 | assert!(far_t[0] <= 3 && far_t[1] >= 250 && far_t[2] >= 250, "Fog image cyan must replace the far fog color, got {far_t:?}"); | |
| 1130 | 1133 | |
| 1131 | 1134 | let (_, sky0) = eval_px(&mut eng, &comp, "FogSkyZeroA"); |
| 1132 | 1135 | assert_eq!(px_at(&sky0, 16, 8, 8)[3], 0, "FogAlpha=0 must keep empty sky transparent"); |
| ... | ... | @@ -1156,17 +1159,16 @@ mod tests { |
| 1156 | 1159 | Input = Input { SourceOp = "Scene", Source = "Output", }, |
| 1157 | 1160 | Low = Input { Value = 0.6, }, High = Input { Value = 0.9, }, |
| 1158 | 1161 | NumberOfPoints = Input { Value = 4, }, Angle = Input { Value = 0.0, }, |
| 1159 | Length = Input { Value = 0.25, }, Falloff = Input { Value = 1.0, }, | |
| 1160 | ColorRed = Input { Value = 1.0, }, ColorGreen = Input { Value = 0.5, }, ColorBlue = Input { Value = 0.2, }, | |
| 1161 | MergeWithOriginal = Input { Value = 1, }, | |
| 1162 | Length = Input { Value = 0.5, }, | |
| 1163 | GreenScale = Input { Value = 0.7, }, BlueScale = Input { Value = 0.5, }, | |
| 1162 | 1164 | }, |
| 1163 | 1165 | }, |
| 1164 | 1166 | HLOnly = Highlight { |
| 1165 | 1167 | Inputs = { |
| 1166 | 1168 | Input = Input { SourceOp = "Scene", Source = "Output", }, |
| 1167 | 1169 | Low = Input { Value = 0.6, }, High = Input { Value = 0.9, }, |
| 1168 | NumberOfPoints = Input { Value = 4, }, Length = Input { Value = 0.25, }, | |
| 1169 | MergeWithOriginal = Input { Value = 0, }, | |
| 1170 | NumberOfPoints = Input { Value = 4, }, Length = Input { Value = 0.5, }, | |
| 1171 | MergeOver = Input { Value = 0, }, | |
| 1170 | 1172 | }, |
| 1171 | 1173 | }, |
| 1172 | 1174 | }, |
| ... | ... | @@ -1181,7 +1183,7 @@ mod tests { |
| 1181 | 1183 | assert!(ray_y[0] >= 20, "Y ray must glow for 4-point star, got {ray_y:?}"); |
| 1182 | 1184 | assert!(off_diag[0] <= 2, "off-ray diagonal must stay dark, got {off_diag:?}"); |
| 1183 | 1185 | |
| 1184 | // MergeWithOriginal=0 must drop the dim patch (lum=0.3 < Low=0.6). | |
| 1186 | // MergeOver=0 must drop the dim patch (lum=0.3 < Low=0.6). | |
| 1185 | 1187 | let (_, px_only) = eval_px(&mut eng, &comp, "HLOnly"); |
| 1186 | 1188 | let dim_px = px_at(&px_only, 64, 10, 54); |
| 1187 | 1189 | assert!(dim_px[0] <= 2 && dim_px[1] <= 2 && dim_px[2] <= 2, "dim spot below Low must not highlight, got {dim_px:?}"); |
| ... | ... | @@ -1189,7 +1191,7 @@ mod tests { |
| 1189 | 1191 | eng.proxy_scale = 2; |
| 1190 | 1192 | let (tex_p, px_p) = eval_px(&mut eng, &comp, "HL"); |
| 1191 | 1193 | assert_eq!(tex_p.size, [32, 32]); |
| 1192 | assert!(px_at(&px_p, 32, 20, 16)[0] >= 15, "proxy Highlight must scale streaks cleanly"); | |
| 1194 | assert!(px_at(&px_p, 32, 20, 16)[0] >= 15, "proxy Highlight must still streak"); | |
| 1193 | 1195 | } |
| 1194 | 1196 | |
| 1195 | 1197 | #[test] |
crates/engine/src/eval/fx_fuses.rs+51-96| ... | ... | @@ -1,6 +1,6 @@ |
| 1 | 1 | //! Wave 36 GPU pipelines & evaluators: |
| 2 | 2 | //! - `VectorDenoise` (motion-compensated bilateral temporal denoiser) |
| 3 | //! - `Mandel` (escape-time Mandelbrot / Julia fractal generator with smooth coloring) | |
| 3 | //! - `Mandel` (escape-time Mandelbrot generator with continuous-potential coloring) | |
| 4 | 4 | //! - `UnsharpMask` (separable Gaussian blur + thresholded high-frequency boost) |
| 5 | 5 | //! - `Letterbox` (aspect-preserving Letterbox & Pan-and-Scan framing) |
| 6 | 6 | //! - Archive Fuses in `fx_fuses/fuses.rs`: `Fuse.Wipe`, `Fuse.Null`, |
| ... | ... | @@ -291,6 +291,35 @@ impl FxFusesPipelines { |
| 291 | 291 | } |
| 292 | 292 | } |
| 293 | 293 | |
| 294 | /// `c` for pixel `(x, row)`: offsets run from the frame center in pixel-corner units, imaginary growing downward. | |
| 295 | fn mandel_c(size: [u32; 2], pos: [f64; 2], unit: f64, rot: f64, x: f64, row: f64) -> [f64; 2] { | |
| 296 | let local = [x - 0.5 * size[0] as f64, row + 1.0 - 0.5 * size[1] as f64]; | |
| 297 | let (sa, ca) = rot.sin_cos(); | |
| 298 | [pos[0] + (local[0] * ca - local[1] * sa) * unit, pos[1] + (local[0] * sa + local[1] * ca) * unit] | |
| 299 | } | |
| 300 | ||
| 301 | /// log2 of the largest continuous potential `ln|z| / 2^n` in the frame, which Fusion normalizes by. | |
| 302 | /// The potential is harmonic outside the set, so its maximum lies on the frame border. | |
| 303 | fn mandel_border_log2_potential(size: [u32; 2], pos: [f64; 2], unit: f64, rot: f64, iterations: u32, escape: f64) -> f64 { | |
| 304 | let [w, h] = size.map(|v| v.max(1) as f64 - 1.0); | |
| 305 | let steps = size[0].max(size[1]).max(2) as usize; | |
| 306 | let border = (0..=steps).flat_map(|i| { | |
| 307 | let t = i as f64 / steps as f64; | |
| 308 | [[t * w, 0.0], [t * w, h], [0.0, t * h], [w, t * h]] | |
| 309 | }); | |
| 310 | border | |
| 311 | .filter_map(|[x, row]| { | |
| 312 | let c = mandel_c(size, pos, unit, rot, x, row); | |
| 313 | let mut z = [0.0_f64; 2]; | |
| 314 | (1..=iterations).find_map(|n| { | |
| 315 | z = [z[0] * z[0] - z[1] * z[1] + c[0], 2.0 * z[0] * z[1] + c[1]]; | |
| 316 | let z2 = z[0] * z[0] + z[1] * z[1]; | |
| 317 | (z2 > escape * escape).then(|| (0.5 * z2.ln()).log2() - n as f64) | |
| 318 | }) | |
| 319 | }) | |
| 320 | .fold(f64::NEG_INFINITY, f64::max) | |
| 321 | } | |
| 322 | ||
| 294 | 323 | pub(self) fn first_num(comp: &Comp, node: &Node, keys: &[&str], time: f64, default: f64, expr: &ExprEngine) -> f64 { |
| 295 | 324 | for &k in keys { |
| 296 | 325 | if node.inputs.contains_key(k) { |
| ... | ... | @@ -524,92 +553,29 @@ impl Engine { |
| 524 | 553 | let size = if w == comp.width && h == comp.height { comp_dims } else { self.scaled_dims(w, h) }; |
| 525 | 554 | let depth = self.node_depth(comp, node, time, None); |
| 526 | 555 | |
| 527 | let is_julia = match first_str(node, &["Mode", "Type", "FractalType"]) { | |
| 528 | Some(s) => s.eq_ignore_ascii_case("julia"), | |
| 529 | None => first_num(comp, node, &["Mode", "Type", "FractalType", "Julia"], time, 0.0, &self.expr) >= 0.5, | |
| 530 | }; | |
| 531 | let default_center = if is_julia { [0.0, 0.0] } else { [-0.5, 0.0] }; | |
| 532 | let (cx, cy) = if node.inputs.contains_key("XPosition") || node.inputs.contains_key("YPosition") { | |
| 533 | ( | |
| 534 | comp.eval_number(node, "XPosition", time, default_center[0], &self.expr) as f32, | |
| 535 | comp.eval_number(node, "YPosition", time, default_center[1], &self.expr) as f32, | |
| 536 | ) | |
| 537 | } else { | |
| 538 | let c = first_point(comp, node, &["Center"], time, default_center, &self.expr); | |
| 539 | (c[0] as f32, c[1] as f32) | |
| 540 | }; | |
| 541 | let zoom = if node.inputs.contains_key("Zoom") { | |
| 542 | comp.eval_number(node, "Zoom", time, 1.0, &self.expr).max(1e-6) as f32 | |
| 543 | } else if node.inputs.contains_key("Size") { | |
| 544 | (1.0 / comp.eval_number(node, "Size", time, 1.0, &self.expr).max(1e-6)) as f32 | |
| 545 | } else { | |
| 546 | 1.0_f32 | |
| 547 | }; | |
| 548 | let rot_rad = (first_num(comp, node, &["Rotation", "Angle"], time, 0.0, &self.expr) as f32).to_radians(); | |
| 549 | let max_iter = first_num(comp, node, &["Iterations", "MaxIterations"], time, 64.0, &self.expr).round().clamp(1.0, 1024.0) as f32; | |
| 550 | let escape_lim = first_num(comp, node, &["EscapeLimit", "Bailout"], time, 4.0, &self.expr).max(4.0) as f32; | |
| 551 | let escape_r2 = (escape_lim * escape_lim).max(16.0); | |
| 552 | let grad_curve = first_num(comp, node, &["GradientCurve", "Curve"], time, 0.5, &self.expr).max(0.05) as f32; | |
| 553 | ||
| 554 | let mut jc = first_point(comp, node, &["JuliaSeed", "C", "Seed"], time, [-0.7, 0.27015], &self.expr); | |
| 555 | if node.inputs.contains_key("JuliaX") || node.inputs.contains_key("CReal") { | |
| 556 | jc[0] = first_num(comp, node, &["JuliaX", "CReal"], time, jc[0], &self.expr); | |
| 557 | } | |
| 558 | if node.inputs.contains_key("JuliaY") || node.inputs.contains_key("CImag") { | |
| 559 | jc[1] = first_num(comp, node, &["JuliaY", "CImag"], time, jc[1], &self.expr); | |
| 560 | } | |
| 561 | ||
| 562 | let any_rgb_wave = ["RedRepetitions", "GreenRepetitions", "BlueRepetitions", "RedPhase", "GreenPhase", "BluePhase"] | |
| 563 | .iter() | |
| 564 | .any(|k| node.inputs.contains_key(*k)); | |
| 565 | let r_rep = comp.eval_number(node, "RedRepetitions", time, 1.0, &self.expr) as f32; | |
| 566 | let g_rep = comp.eval_number(node, "GreenRepetitions", time, 1.0, &self.expr) as f32; | |
| 567 | let b_rep = comp.eval_number(node, "BlueRepetitions", time, 1.0, &self.expr) as f32; | |
| 568 | let r_ph = comp.eval_number(node, "RedPhase", time, 0.0, &self.expr) as f32; | |
| 569 | let g_ph = comp.eval_number(node, "GreenPhase", time, if any_rgb_wave { 0.0 } else { 0.15 }, &self.expr) as f32; | |
| 570 | let b_ph = comp.eval_number(node, "BluePhase", time, if any_rgb_wave { 0.0 } else { 0.30 }, &self.expr) as f32; | |
| 571 | ||
| 572 | let tint = [ | |
| 573 | first_num(comp, node, &["ColorRed", "Red"], time, 1.0, &self.expr) as f32, | |
| 574 | first_num(comp, node, &["ColorGreen", "Green"], time, 1.0, &self.expr) as f32, | |
| 575 | first_num(comp, node, &["ColorBlue", "Blue"], time, 1.0, &self.expr) as f32, | |
| 576 | first_num(comp, node, &["ColorAlpha", "Alpha"], time, 1.0, &self.expr) as f32, | |
| 577 | ]; | |
| 578 | let inside = [ | |
| 579 | comp.eval_number(node, "InsideRed", time, 0.0, &self.expr) as f32, | |
| 580 | comp.eval_number(node, "InsideGreen", time, 0.0, &self.expr) as f32, | |
| 581 | comp.eval_number(node, "InsideBlue", time, 0.0, &self.expr) as f32, | |
| 582 | comp.eval_number(node, "InsideAlpha", time, 1.0, &self.expr) as f32, | |
| 583 | ]; | |
| 584 | let blend = comp.eval_number(node, "Blend", time, 1.0, &self.expr) as f32; | |
| 585 | let grad = comp.eval_gradient(node, "Gradient", time).or_else(|| comp.eval_gradient(node, "Palette", time)); | |
| 586 | let lut_data = grad.map(|g| { | |
| 587 | let mut bytes = [0u8; 256 * 4]; | |
| 588 | for (i, texel) in bytes.chunks_exact_mut(4).enumerate() { | |
| 589 | let c = g.sample(i as f64 / 255.0); | |
| 590 | for (b, v) in texel.iter_mut().zip(c) { | |
| 591 | *b = (v.clamp(0.0, 1.0) * 255.0).round() as u8; | |
| 592 | } | |
| 593 | } | |
| 594 | let mut gh = DefaultHasher::new(); | |
| 595 | bytes.hash(&mut gh); | |
| 596 | (bytes, gh.finish()) | |
| 597 | }); | |
| 598 | let grad_hash = lut_data.as_ref().map_or(0, |l| l.1); | |
| 599 | ||
| 600 | 556 | let (mask, mask_inv) = self.eval_mask_input_sized(comp, node, time, Some(size), enc, visiting, stats); |
| 601 | 557 | let mask_hash = mask.as_ref().map_or(0, |m| m.content_hash); |
| 602 | ||
| 558 | let num = |id: &str, default: f64| comp.eval_number(node, id, time, default, &self.expr); | |
| 559 | ||
| 560 | // Zoom compounds 1.25x per unit above 1; Zoom 1 spans 5 units across the frame width. | |
| 561 | let unit = 5.0 / (size[0] as f64 * 1.25_f64.powf(num("Zoom", 1.0).max(1.0) - 1.0)); | |
| 562 | let pos = [num("XPosition", -0.5), num("YPosition", 0.0)]; | |
| 563 | let rot = num("Rotation", 0.0).to_radians(); | |
| 564 | let iterations = num("Iterations", 256.0).round().clamp(1.0, 4096.0); | |
| 565 | let escape = num("EscapeLimit", 16.0); | |
| 603 | 566 | let mut u = UniformParams::default(); |
| 604 | u.p[0] = [cx, cy, zoom, rot_rad]; | |
| 605 | u.p[1] = [if is_julia { 1.0 } else { 0.0 }, max_iter, escape_r2, grad_curve]; | |
| 606 | u.p[2] = [jc[0] as f32, jc[1] as f32, r_rep, g_rep]; | |
| 607 | u.p[3] = [b_rep, r_ph, g_ph, b_ph]; | |
| 608 | u.p[4] = [if lut_data.is_some() { 1.0 } else { 0.0 }, blend, if mask.is_some() { 1.0 } else { 0.0 }, if mask_inv { 1.0 } else { 0.0 }]; | |
| 609 | u.p[5] = tint; | |
| 610 | u.p[6] = inside; | |
| 611 | ||
| 612 | let key = self.make_key(node, "Mandel", size, &[mask_hash, grad_hash, depth as u64], bytemuck::cast_slice(&u.p[..7])); | |
| 567 | u.p[0] = [pos[0] as f32, pos[1] as f32, unit as f32, rot as f32]; | |
| 568 | u.p[1] = [iterations as f32, escape as f32, num("GradientCurve", 0.125) as f32, num("GradMethod", 0.0).round() as f32]; | |
| 569 | u.p[2] = ["RedRepetitions", "GreenRepetitions", "BlueRepetitions", "AlphaRepetitions"].map(|id| num(id, 1.0) as f32); | |
| 570 | u.p[3] = ["RedPhase", "GreenPhase", "BluePhase", "AlphaPhase"].map(|id| num(id, 0.0) as f32); | |
| 571 | u.p[4] = [ | |
| 572 | num("Blend", 1.0) as f32, | |
| 573 | if mask.is_some() { 1.0 } else { 0.0 }, | |
| 574 | if mask_inv { 1.0 } else { 0.0 }, | |
| 575 | mandel_border_log2_potential(size, pos, unit, rot, iterations as u32, escape) as f32, | |
| 576 | ]; | |
| 577 | ||
| 578 | let key = self.make_key(node, "Mandel", size, &[mask_hash, depth as u64], bytemuck::cast_slice(&u.p[..5])); | |
| 613 | 579 | if let Some(hit) = self.cache.get(key, node.id, frame_i) { |
| 614 | 580 | stats.cache_hits += 1; |
| 615 | 581 | return hit; |
| ... | ... | @@ -617,20 +583,9 @@ impl Engine { |
| 617 | 583 | stats.cache_misses += 1; |
| 618 | 584 | stats.nodes_evaluated += 1; |
| 619 | 585 | |
| 620 | let lut_tex = lut_data.map(|(bytes, _)| { | |
| 621 | let tex = create_texture(&self.device, [256, 1], 0); | |
| 622 | self.queue.write_texture( | |
| 623 | tex.texture.as_image_copy(), | |
| 624 | &bytes, | |
| 625 | wgpu::TexelCopyBufferLayout { offset: 0, bytes_per_row: Some(256 * 4), rows_per_image: Some(1) }, | |
| 626 | wgpu::Extent3d { width: 256, height: 1, depth_or_array_layers: 1 }, | |
| 627 | ); | |
| 628 | tex | |
| 629 | }); | |
| 630 | 586 | let dst = self.alloc_tex(size, depth, key); |
| 631 | let lut_view = lut_tex.as_ref().map_or(&self.dummy.view, |t| &t.view); | |
| 632 | 587 | let mv = mask.as_ref().map_or(&self.dummy.view, |m| &m.view); |
| 633 | self.dispatch_fx(enc, FxOp::Mandel, &self.dummy.view, lut_view, mv, None, &dst, &u); | |
| 588 | self.dispatch_fx(enc, FxOp::Mandel, &self.dummy.view, &self.dummy.view, mv, None, &dst, &u); | |
| 634 | 589 | self.cache.insert(key, dst.clone(), node.id, frame_i); |
| 635 | 590 | dst |
| 636 | 591 | } |
crates/engine/src/eval/fx_fuses/tests.rs+13-29| ... | ... | @@ -68,42 +68,26 @@ fn vector_denoise_reduces_temporal_flicker_and_preserves_edges() { |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | #[test] |
| 71 | fn mandel_renders_mandelbrot_julia_and_gradient_lut() { | |
| 71 | fn mandel_matches_fusion_coloring() { | |
| 72 | 72 | let c = comp(r#" |
| 73 | M = Mandel { Inputs = { | |
| 73 | M = Mandel { Inputs = { Width = Input { Value = 64, }, Height = Input { Value = 64, }, }, }, | |
| 74 | P = Mandel { Inputs = { | |
| 74 | 75 | Width = Input { Value = 64, }, Height = Input { Value = 64, }, |
| 75 | XPosition = Input { Value = -0.5, }, Zoom = Input { Value = 1.0, }, | |
| 76 | Iterations = Input { Value = 80, }, EscapeLimit = Input { Value = 4, }, | |
| 77 | GradientCurve = Input { Value = 0.45, }, | |
| 78 | RedRepetitions = Input { Value = 1.8, }, GreenRepetitions = Input { Value = 2.0, }, | |
| 79 | BluePhase = Input { Value = 0.25, }, | |
| 80 | }, }, | |
| 81 | J = Mandel { Inputs = { | |
| 82 | Width = Input { Value = 64, }, Height = Input { Value = 64, }, | |
| 83 | Mode = Input { Value = FuID { "Julia" }, }, | |
| 84 | JuliaSeed = Input { Value = { -0.7, 0.27015 }, }, | |
| 85 | Iterations = Input { Value = 64, }, | |
| 86 | }, }, | |
| 87 | G = Mandel { Inputs = { | |
| 88 | Width = Input { Value = 64, }, Height = Input { Value = 64, }, | |
| 89 | Gradient = Input { Value = Gradient { Colors = { | |
| 90 | [0] = { 0, 0, 1, 1 }, | |
| 91 | [1] = { 1, 1, 0, 1 }, | |
| 92 | } }, }, | |
| 76 | RedPhase = Input { Value = 0.5, }, | |
| 93 | 77 | }, }, |
| 94 | 78 | "#); |
| 95 | 79 | let Some((tex_m, px_m)) = render(&c, "M", 0.0) else { return }; |
| 96 | 80 | assert_eq!(tex_m.size, [64, 64]); |
| 97 | assert_eq!(at(&px_m, 64, 32, 32), [0, 0, 0, 255], "cardioid center should be inside set"); | |
| 98 | let corner = at(&px_m, 64, 2, 2); | |
| 99 | assert!(corner[0] as u32 + corner[1] as u32 + corner[2] as u32 > 20, "exterior should be colored: {corner:?}"); | |
| 100 | ||
| 101 | let (_, px_j) = render(&c, "J", 0.0).unwrap(); | |
| 102 | assert_ne!(px_m, px_j, "Julia mode should differ from Mandelbrot"); | |
| 81 | assert_eq!(at(&px_m, 64, 40, 31), [0, 0, 0, 0], "cardioid interior stays transparent black"); | |
| 82 | let corner = at(&px_m, 64, 0, 63); | |
| 83 | assert!(corner[3] <= 1, "the frame's largest potential maps to t = 0: {corner:?}"); | |
| 84 | let near = at(&px_m, 64, 20, 28); | |
| 85 | assert!(near[0] == near[3] && near[3] > 30, "exterior is an unpremultiplied grey ramp: {near:?}"); | |
| 103 | 86 | |
| 104 | let (_, px_g) = render(&c, "G", 0.0).unwrap(); | |
| 105 | let g_corner = at(&px_g, 64, 2, 2); | |
| 106 | assert!(g_corner[2] > 100, "Gradient LUT exterior near t=0 should be blue: {g_corner:?}"); | |
| 87 | let (_, px_p) = render(&c, "P", 0.0).unwrap(); | |
| 88 | assert_eq!(at(&px_p, 64, 40, 31), [0, 0, 0, 0], "RedPhase leaves the interior untouched"); | |
| 89 | let shifted = at(&px_p, 64, 0, 63)[0]; | |
| 90 | assert!((126..=129).contains(&shifted), "RedPhase 0.5 lifts t = 0 to mid-grey: {shifted}"); | |
| 107 | 91 | } |
| 108 | 92 | |
| 109 | 93 | #[test] |
crates/engine/src/eval/io.rs+2-1| ... | ... | @@ -943,7 +943,8 @@ impl Engine { |
| 943 | 943 | let mut bytes = [0u8; 256 * 4]; |
| 944 | 944 | for (i, texel) in bytes.chunks_exact_mut(4).enumerate() { |
| 945 | 945 | let t = i as f64 / 255.0; |
| 946 | let c = grad.as_ref().map_or_else(|| std::array::from_fn(|k| c1[k] + (c2[k] - c1[k]) * t as f32), |g| g.sample(t)); | |
| 946 | // Without a Gradient input Fusion uses an opaque black-to-white ramp, ignoring Color1/Color2. | |
| 947 | let c = grad.as_ref().map_or([t as f32, t as f32, t as f32, 1.0], |g| g.sample(t)); | |
| 947 | 948 | for (b, v) in texel.iter_mut().zip(c) { |
| 948 | 949 | *b = (v.clamp(0.0, 1.0) * 255.0).round() as u8; |
| 949 | 950 | } |
crates/engine/src/eval/masks.rs+7-7| ... | ... | @@ -171,7 +171,7 @@ impl Engine { |
| 171 | 171 | let solid = if comp.eval_number(node, "Solid", time, 1.0, &self.expr) > 0.5 { 1.0 } else { 0.0 }; |
| 172 | 172 | let is_box = Self::mask_filter_is_box(node); |
| 173 | 173 | let clamp_edges = Self::mask_clamp_edges(node); |
| 174 | let (prev_mask, _) = self.eval_mask_input_sized(comp, node, time, Some(size), enc, visiting, stats); | |
| 174 | let prev_mask = self.chained_mask(comp, node, time, size, enc, visiting, stats); | |
| 175 | 175 | if let Some(ignored) = self.eval_paint_ignore(node, size, prev_mask.clone()) { |
| 176 | 176 | return ignored; |
| 177 | 177 | } |
| ... | ... | @@ -236,7 +236,7 @@ impl Engine { |
| 236 | 236 | let level = (comp.eval_number(node, "Level", time, 1.0, &self.expr).clamp(0.0, 1.0) * 255.0).floor() as f32 / 255.0; |
| 237 | 237 | let is_box = Self::mask_filter_is_box(node); |
| 238 | 238 | let clamp_edges = Self::mask_clamp_edges(node); |
| 239 | let (prev_mask, _) = self.eval_mask_input_sized(comp, node, time, Some(size), enc, visiting, stats); | |
| 239 | let prev_mask = self.chained_mask(comp, node, time, size, enc, visiting, stats); | |
| 240 | 240 | if let Some(ignored) = self.eval_paint_ignore(node, size, prev_mask.clone()) { |
| 241 | 241 | return ignored; |
| 242 | 242 | } |
| ... | ... | @@ -438,9 +438,9 @@ impl Engine { |
| 438 | 438 | combined |
| 439 | 439 | } |
| 440 | 440 | |
| 441 | /// `BitmapMask` and `WandMask` only chain `EffectMask` when it is driven by a mask node/port, | |
| 442 | /// ignoring regular `Image` outputs wired into `EffectMask`. | |
| 443 | pub(super) fn bitmap_or_wand_prev_mask( | |
| 441 | /// The upstream mask a mask tool chains onto: Fusion ignores a non-mask `Image` output wired into | |
| 442 | /// a mask tool's `EffectMask`. | |
| 443 | pub(super) fn chained_mask( | |
| 444 | 444 | &mut self, |
| 445 | 445 | comp: &Comp, |
| 446 | 446 | node: &Node, |
| ... | ... | @@ -532,7 +532,7 @@ impl Engine { |
| 532 | 532 | let fit_mode = Self::fit_mask_mode(comp, node, "FitInput", time, &self.expr); |
| 533 | 533 | let is_box = Self::mask_filter_is_box(node); |
| 534 | 534 | let clamp_edges = Self::mask_clamp_edges(node); |
| 535 | let prev_mask = self.bitmap_or_wand_prev_mask(comp, node, time, size, enc, visiting, stats); | |
| 535 | let prev_mask = self.chained_mask(comp, node, time, size, enc, visiting, stats); | |
| 536 | 536 | if let Some(ignored) = self.eval_paint_ignore(node, size, prev_mask.clone()) { |
| 537 | 537 | return ignored; |
| 538 | 538 | } |
| ... | ... | @@ -630,7 +630,7 @@ impl Engine { |
| 630 | 630 | let level = comp.eval_number(node, "Level", time, 1.0, &self.expr) as f32; |
| 631 | 631 | let is_box = Self::mask_filter_is_box(node); |
| 632 | 632 | let clamp_edges = Self::mask_clamp_edges(node); |
| 633 | let prev_mask = self.bitmap_or_wand_prev_mask(comp, node, time, size, enc, visiting, stats); | |
| 633 | let prev_mask = self.chained_mask(comp, node, time, size, enc, visiting, stats); | |
| 634 | 634 | if let Some(ignored) = self.eval_paint_ignore(node, size, prev_mask.clone()) { |
| 635 | 635 | return ignored; |
| 636 | 636 | } |
crates/engine/src/eval/surface_fx/masks_fx.rs+3-3| ... | ... | @@ -325,7 +325,7 @@ impl Engine { |
| 325 | 325 | stats: &mut EvalStats, |
| 326 | 326 | ) -> CachedTexture { |
| 327 | 327 | let size = self.explicit_mask_size(comp, node, time, comp_dims); |
| 328 | let (prev_mask, _) = self.eval_mask_input_sized(comp, node, time, Some(size), enc, visiting, stats); | |
| 328 | let prev_mask = self.chained_mask(comp, node, time, size, enc, visiting, stats); | |
| 329 | 329 | if let Some(ignored) = self.eval_paint_ignore(node, size, prev_mask.clone()) { |
| 330 | 330 | return ignored; |
| 331 | 331 | } |
| ... | ... | @@ -544,7 +544,7 @@ impl Engine { |
| 544 | 544 | src.canvas_size |
| 545 | 545 | }; |
| 546 | 546 | |
| 547 | let prev_mask = self.bitmap_or_wand_prev_mask(comp, node, time, size, enc, visiting, stats); | |
| 547 | let prev_mask = self.chained_mask(comp, node, time, size, enc, visiting, stats); | |
| 548 | 548 | if let Some(ignored) = self.eval_paint_ignore(node, size, prev_mask.clone()) { |
| 549 | 549 | return ignored; |
| 550 | 550 | } |
| ... | ... | @@ -655,7 +655,7 @@ impl Engine { |
| 655 | 655 | stats: &mut EvalStats, |
| 656 | 656 | ) -> CachedTexture { |
| 657 | 657 | let size = self.explicit_mask_size(comp, node, time, comp_dims); |
| 658 | let (prev_mask, _) = self.eval_mask_input_sized(comp, node, time, Some(size), enc, visiting, stats); | |
| 658 | let prev_mask = self.chained_mask(comp, node, time, size, enc, visiting, stats); | |
| 659 | 659 | if let Some(ignored) = self.eval_paint_ignore(node, size, prev_mask.clone()) { |
| 660 | 660 | return ignored; |
| 661 | 661 | } |
crates/engine/src/eval/warps_masks.rs+1-1| ... | ... | @@ -693,7 +693,7 @@ impl Engine { |
| 693 | 693 | let level = comp.eval_number(node, "Level", time, 1.0, &self.expr) as f32; |
| 694 | 694 | let is_box = Self::mask_filter_is_box(node); |
| 695 | 695 | let clamp_edges = wm_mask_clamp_edges(node); |
| 696 | let (prev_mask, _) = self.eval_mask_input_sized(comp, node, time, Some(size), enc, visiting, stats); | |
| 696 | let prev_mask = self.chained_mask(comp, node, time, size, enc, visiting, stats); | |
| 697 | 697 | if wm_is_paint_ignore(node) { |
| 698 | 698 | return prev_mask.unwrap_or_else(|| self.alloc_tex(size, BitDepth::Int8, 0)); |
| 699 | 699 | } |
crates/engine/src/eval/warps_masks/bspline.rs+1-1| ... | ... | @@ -404,7 +404,7 @@ impl Engine { |
| 404 | 404 | let write_len = if write_len_raw.is_finite() { write_len_raw.clamp(0.0, 1.0) } else { 1.0 }; |
| 405 | 405 | let is_box = Self::mask_filter_is_box(node); |
| 406 | 406 | let clamp_edges = wm_mask_clamp_edges(node); |
| 407 | let (prev_mask, _) = self.eval_mask_input_sized(comp, node, time, Some(size), enc, visiting, stats); | |
| 407 | let prev_mask = self.chained_mask(comp, node, time, size, enc, visiting, stats); | |
| 408 | 408 | if wm_is_paint_ignore(node) { |
| 409 | 409 | return prev_mask.unwrap_or_else(|| self.alloc_tex(size, model::BitDepth::Int8, 0)); |
| 410 | 410 | } |
crates/engine/src/shaders/alpha_keyers.wgsl+38-19| ... | ... | @@ -77,7 +77,7 @@ fn apply_mask_blend( |
| 77 | 77 | // ============================================================================ |
| 78 | 78 | // 1 & 2. AlphaMultiply / AlphaDivide |
| 79 | 79 | // p[0] = (mode: 0=multiply 1=divide, blend, has_mask, mask_inv) |
| 80 | // p[1] = (mbm, 0, 0, 0) | |
| 80 | // p[1] = (mbm, quantize_8bit, 0, 0) | |
| 81 | 81 | // p[2] = (skip_r, skip_g, skip_b, skip_a) |
| 82 | 82 | // ============================================================================ |
| 83 | 83 | @compute @workgroup_size(8, 8) |
| ... | ... | @@ -93,6 +93,10 @@ fn alpha_op(@builtin(global_invocation_id) gid: vec3<u32>) { |
| 93 | 93 | let rgb = select(vec3<f32>(0.0), src.rgb / src.a, src.a > 1e-6); |
| 94 | 94 | res = vec4<f32>(rgb, src.a); |
| 95 | 95 | } |
| 96 | // Fusion stores an 8-bit effect result before Blend mixes it with the source. | |
| 97 | if (u.p[1].y > 0.5) { | |
| 98 | res = floor(clamp(res, vec4<f32>(0.0), vec4<f32>(1.0)) * 255.0 + 0.5) / 255.0; | |
| 99 | } | |
| 96 | 100 | let out_col = apply_mask_blend( |
| 97 | 101 | src, res, gid.xy, dims, u.p[0].y, u.p[0].z, u.p[0].w, u.p[1].x, u.p[2], |
| 98 | 102 | ); |
| ... | ... | @@ -100,20 +104,35 @@ fn alpha_op(@builtin(global_invocation_id) gid: vec3<u32>) { |
| 100 | 104 | } |
| 101 | 105 | |
| 102 | 106 | // ============================================================================ |
| 103 | // 3. PseudoColor (Fusion procedural per-channel sine-wave false-color mapper) | |
| 104 | // p[0] = (r_lo, r_hi, r_freq, r_phase) | |
| 105 | // p[1] = (g_lo, g_hi, g_freq, g_phase) | |
| 106 | // p[2] = (b_lo, b_hi, b_freq, b_phase) | |
| 107 | // p[3] = (a_lo, a_hi, a_freq, a_phase) | |
| 108 | // p[4] = (use_alpha, blend, has_mask, mask_inv) | |
| 109 | // p[5] = (mbm, 0, 0, 0) | |
| 110 | // p[6] = (skip_r, skip_g, skip_b, skip_a) | |
| 107 | // 3. PseudoColor (Fusion per-channel waveform false-color mapper on premultiplied values) | |
| 108 | // p[c*3] = (low, high, soft_edge, waveform: 0=Sine 1=Triangle 2=Sawtooth 3=Square) | |
| 109 | // p[c*3+1] = (frequency, phase, mean, amplitude) | |
| 110 | // p[c*3+2] = (enabled, wrap, 0, 0) | |
| 111 | // p[12] = (blend, has_mask, mask_inv, mbm) | |
| 112 | // p[13] = (skip_r, skip_g, skip_b, skip_a) | |
| 113 | // p[14] = (quantize_8bit, 0, 0, 0) | |
| 111 | 114 | // ============================================================================ |
| 112 | fn pseudo_channel(val: f32, cfg: vec4<f32>) -> f32 { | |
| 113 | if (val >= cfg.x && val <= cfg.y) { | |
| 114 | return 0.5 + 0.5 * sin(TAU * (val * cfg.z + cfg.w)); | |
| 115 | fn pseudo_channel(v: f32, c: i32) -> f32 { | |
| 116 | let range = u.p[c * 3]; | |
| 117 | let wave_cfg = u.p[c * 3 + 1]; | |
| 118 | let flags = u.p[c * 3 + 2]; | |
| 119 | if (flags.x < 0.5 || v < range.x || v > range.y) { return v; } | |
| 120 | let phi = v * wave_cfg.x + wave_cfg.y; | |
| 121 | // Fusion's double-precision sin(2 pi phi) is slightly negative at positive integers. | |
| 122 | let pos_int = phi > 0.0 && fract(phi) == 0.0; | |
| 123 | // Fusion takes `fmod` (truncating) for the periodic shapes, so negative phases fall off the [-1, 1] wave. | |
| 124 | var wave: f32; | |
| 125 | switch i32(range.w) { | |
| 126 | case 1: { wave = 1.0 - 4.0 * abs((phi + 0.25) % 1.0 - 0.5); } | |
| 127 | case 2: { wave = 2.0 * (((v + 0.5) * wave_cfg.x + wave_cfg.y) % 1.0) - 1.0; } | |
| 128 | case 3: { wave = select(-1.0, 1.0, fract(phi) <= 0.5 && !pos_int); } | |
| 129 | default: { wave = select(sin(TAU * (phi % 1.0)), -1e-6, pos_int); } | |
| 115 | 130 | } |
| 116 | return val; | |
| 131 | let raw = wave_cfg.z + wave_cfg.w * wave; | |
| 132 | let res = select(clamp(raw, 0.0, 1.0), raw % 1.0, flags.y > 0.5); | |
| 133 | let edge = min(range.z, 0.5 * (range.y - range.x)); | |
| 134 | let s = select(1.0, clamp(min(v - range.x, range.y - v) / edge, 0.0, 1.0), edge > 0.0); | |
| 135 | return mix(v, res, s); | |
| 117 | 136 | } |
| 118 | 137 | |
| 119 | 138 | @compute @workgroup_size(8, 8) |
| ... | ... | @@ -122,13 +141,13 @@ fn pseudo_color_op(@builtin(global_invocation_id) gid: vec3<u32>) { |
| 122 | 141 | if (gid.x >= dims.x || gid.y >= dims.y) { return; } |
| 123 | 142 | let p = vec2<i32>(gid.xy); |
| 124 | 143 | let src = textureLoad(tex_a, p, 0); |
| 125 | let r = pseudo_channel(src.r, u.p[0]); | |
| 126 | let g = pseudo_channel(src.g, u.p[1]); | |
| 127 | let b = pseudo_channel(src.b, u.p[2]); | |
| 128 | let a = select(src.a, pseudo_channel(src.a, u.p[3]), u.p[4].x > 0.5); | |
| 129 | let res = vec4<f32>(r, g, b, a); | |
| 144 | var res = vec4<f32>(pseudo_channel(src.r, 0), pseudo_channel(src.g, 1), pseudo_channel(src.b, 2), pseudo_channel(src.a, 3)); | |
| 145 | // Fusion stores an 8-bit effect result before Blend mixes it with the source. | |
| 146 | if (u.p[14].x > 0.5) { | |
| 147 | res = floor(clamp(res, vec4<f32>(0.0), vec4<f32>(1.0)) * 255.0 + 0.5) / 255.0; | |
| 148 | } | |
| 130 | 149 | let out_col = apply_mask_blend( |
| 131 | src, res, gid.xy, dims, u.p[4].y, u.p[4].z, u.p[4].w, u.p[5].x, u.p[6], | |
| 150 | src, res, gid.xy, dims, u.p[12].x, u.p[12].y, u.p[12].z, u.p[12].w, u.p[13], | |
| 132 | 151 | ); |
| 133 | 152 | store_dst(p, out_col); |
| 134 | 153 | } |
crates/engine/src/shaders/archive_fx2.wgsl+10-19| ... | ... | @@ -78,20 +78,11 @@ fn apply_channel_blend( |
| 78 | 78 | orig: vec4<f32>, |
| 79 | 79 | effect: vec4<f32>, |
| 80 | 80 | eff: f32, |
| 81 | mask_v: f32, | |
| 82 | 81 | mbm: f32, |
| 83 | 82 | skip: vec4<f32>, |
| 84 | 83 | ) -> vec4<f32> { |
| 85 | var out_c = mix(orig, effect, eff); | |
| 86 | if (mbm > 0.5) { | |
| 87 | out_c = out_c * mask_v; | |
| 88 | } | |
| 89 | return vec4<f32>( | |
| 90 | select(out_c.r, orig.r, skip.x > 0.5), | |
| 91 | select(out_c.g, orig.g, skip.y > 0.5), | |
| 92 | select(out_c.b, orig.b, skip.z > 0.5), | |
| 93 | select(out_c.a, orig.a, skip.w > 0.5), | |
| 94 | ); | |
| 84 | let out_c = select(mix(orig, effect, eff), effect * eff, mbm > 0.5); | |
| 85 | return select(out_c, select(orig, vec4<f32>(0.0), mbm > 0.5), skip > vec4<f32>(0.5)); | |
| 95 | 86 | } |
| 96 | 87 | |
| 97 | 88 | fn hash_u32(x_in: u32) -> u32 { |
| ... | ... | @@ -206,7 +197,7 @@ fn fuse_hexagon_op(@builtin(global_invocation_id) gid: vec3<u32>) { |
| 206 | 197 | col = mix(col, vec4<f32>(u.p[5].yzw, 1.0), b_fac); |
| 207 | 198 | } |
| 208 | 199 | |
| 209 | let out_c = apply_channel_blend(vec4<f32>(0.0), col, eff, mask_v, u.p[5].x, u.p[6]); | |
| 200 | let out_c = apply_channel_blend(vec4<f32>(0.0), col, eff, u.p[5].x, u.p[6]); | |
| 210 | 201 | store_dst(p, out_c); |
| 211 | 202 | } |
| 212 | 203 | |
| ... | ... | @@ -362,7 +353,7 @@ fn fuse_lightning_op(@builtin(global_invocation_id) gid: vec3<u32>) { |
| 362 | 353 | effect = vec4<f32>(out_rgb, out_a); |
| 363 | 354 | } |
| 364 | 355 | |
| 365 | let out_c = apply_channel_blend(orig, effect, eff, mask_v, u.p[5].w, u.p[6]); | |
| 356 | let out_c = apply_channel_blend(orig, effect, eff, u.p[5].w, u.p[6]); | |
| 366 | 357 | store_dst(p, out_c); |
| 367 | 358 | } |
| 368 | 359 | |
| ... | ... | @@ -493,7 +484,7 @@ fn fuse_voronoi_op(@builtin(global_invocation_id) gid: vec3<u32>) { |
| 493 | 484 | } |
| 494 | 485 | } |
| 495 | 486 | |
| 496 | let out_c = apply_channel_blend(orig, effect, eff, mask_v, u.p[4].w, u.p[5]); | |
| 487 | let out_c = apply_channel_blend(orig, effect, eff, u.p[4].w, u.p[5]); | |
| 497 | 488 | store_dst(p, out_c); |
| 498 | 489 | } |
| 499 | 490 | |
| ... | ... | @@ -576,7 +567,7 @@ fn defocus_op(@builtin(global_invocation_id) gid: vec3<u32>) { |
| 576 | 567 | |
| 577 | 568 | let inv_w = 1.0 / max(w_sum, 1e-5); |
| 578 | 569 | let effect = vec4<f32>(acc_rgb * inv_w, acc_a * inv_w); |
| 579 | let out_c = apply_channel_blend(orig, effect, eff, mask_v, u.p[2].w, u.p[3]); | |
| 570 | let out_c = apply_channel_blend(orig, effect, eff, u.p[2].w, u.p[3]); | |
| 580 | 571 | store_dst(p, out_c); |
| 581 | 572 | } |
| 582 | 573 | |
| ... | ... | @@ -702,7 +693,7 @@ fn autogain_apply_op(@builtin(global_invocation_id) gid: vec3<u32>) { |
| 702 | 693 | } |
| 703 | 694 | } |
| 704 | 695 | |
| 705 | let out_c = apply_channel_blend(orig, effect, eff, mask_v, u.p[2].x, u.p[3]); | |
| 696 | let out_c = apply_channel_blend(orig, effect, eff, u.p[2].x, u.p[3]); | |
| 706 | 697 | store_dst(p, out_c); |
| 707 | 698 | } |
| 708 | 699 | |
| ... | ... | @@ -752,7 +743,7 @@ fn color_balance_op(@builtin(global_invocation_id) gid: vec3<u32>) { |
| 752 | 743 | } |
| 753 | 744 | |
| 754 | 745 | let effect = vec4<f32>(rgb, orig.a); |
| 755 | let out_c = apply_channel_blend(orig, effect, eff, mask_v, u.p[3].w, u.p[4]); | |
| 746 | let out_c = apply_channel_blend(orig, effect, eff, u.p[3].w, u.p[4]); | |
| 756 | 747 | store_dst(p, out_c); |
| 757 | 748 | } |
| 758 | 749 | |
| ... | ... | @@ -819,7 +810,7 @@ fn soft_clip_op(@builtin(global_invocation_id) gid: vec3<u32>) { |
| 819 | 810 | let b = soft_clip_scalar(orig.b, lo, hi, k_lo, k_hi); |
| 820 | 811 | let a = select(orig.a, soft_clip_scalar(orig.a, lo, hi, k_lo, k_hi), clip_a); |
| 821 | 812 | |
| 822 | let out_c = apply_channel_blend(orig, vec4<f32>(r, g, b, a), eff, mask_v, u.p[2].x, u.p[3]); | |
| 813 | let out_c = apply_channel_blend(orig, vec4<f32>(r, g, b, a), eff, u.p[2].x, u.p[3]); | |
| 823 | 814 | store_dst(p, out_c); |
| 824 | 815 | } |
| 825 | 816 | |
| ... | ... | @@ -909,6 +900,6 @@ fn grain_op(@builtin(global_invocation_id) gid: vec3<u32>) { |
| 909 | 900 | orig.a, |
| 910 | 901 | ); |
| 911 | 902 | |
| 912 | let out_c = apply_channel_blend(orig, effect, eff, mask_v, u.p[3].x, u.p[4]); | |
| 903 | let out_c = apply_channel_blend(orig, effect, eff, u.p[3].x, u.p[4]); | |
| 913 | 904 | store_dst(p, out_c); |
| 914 | 905 | } |
crates/engine/src/shaders/color_science.wgsl+3-2| ... | ... | @@ -704,6 +704,7 @@ fn matte_finish_op(@builtin(global_invocation_id) gid: vec3<u32>) { |
| 704 | 704 | // tex_a = original BG, tex_b = composited result, mask_tex = EffectMask |
| 705 | 705 | // p[0] = (blend, has_mask, mask_inv, mbm) |
| 706 | 706 | // p[1] = (skip_r, skip_g, skip_b, skip_a) |
| 707 | // Unlike the other tools, MultiMerge keeps the Background in skipped channels even under MultiplyByMask. | |
| 707 | 708 | // ============================================================================ |
| 708 | 709 | @compute @workgroup_size(8, 8) |
| 709 | 710 | fn blend_mask_op(@builtin(global_invocation_id) gid: vec3<u32>) { |
| ... | ... | @@ -714,7 +715,7 @@ fn blend_mask_op(@builtin(global_invocation_id) gid: vec3<u32>) { |
| 714 | 715 | let bg = sample_bilinear(tex_a, uv); |
| 715 | 716 | let fg = textureLoad(tex_b, p, 0); |
| 716 | 717 | let out_col = apply_mask_blend( |
| 717 | bg, fg, gid.xy, dims, u.p[0].x, u.p[0].y, u.p[0].z, u.p[0].w, u.p[1], | |
| 718 | bg, fg, gid.xy, dims, u.p[0].x, u.p[0].y, u.p[0].z, u.p[0].w, vec4<f32>(0.0), | |
| 718 | 719 | ); |
| 719 | store_dst(p, out_col); | |
| 720 | store_dst(p, select(out_col, bg, u.p[1] > vec4<f32>(0.5))); | |
| 720 | 721 | } |
crates/engine/src/shaders/depth_optical.wgsl+68-87| ... | ... | @@ -77,12 +77,9 @@ fn finalize_fx( |
| 77 | 77 | ) -> vec4<f32> { |
| 78 | 78 | let m = eval_mask(uv, has_mask, mask_inv); |
| 79 | 79 | let eff = clamp(blend * m, 0.0, 1.0); |
| 80 | var out = mix(src, fx, eff); | |
| 81 | out = select(out, src, skip > vec4<f32>(0.5)); | |
| 82 | if (mbm > 0.5 && has_mask > 0.5) { | |
| 83 | out = out * m; | |
| 84 | } | |
| 85 | return sanitize_out(out); | |
| 80 | let use_mbm = mbm > 0.5 && has_mask > 0.5; | |
| 81 | let out = select(mix(src, fx, eff), fx * eff, use_mbm); | |
| 82 | return sanitize_out(select(out, select(src, vec4<f32>(0.0), use_mbm), skip > vec4<f32>(0.5))); | |
| 86 | 83 | } |
| 87 | 84 | |
| 88 | 85 | // Read Z from unfilterable R32Float z_tex using normalized UV via integer textureLoad. |
| ... | ... | @@ -245,7 +242,7 @@ fn depth_blur_op(@builtin(global_invocation_id) gid: vec3<u32>) { |
| 245 | 242 | // p[0] = (near_plane, far_plane, falloff, z_scale) |
| 246 | 243 | // p[1] = (fog_r, fog_g, fog_b, fog_a) |
| 247 | 244 | // p[2] = (fog_opacity, depth_mode, has_fog_color_img, 0) |
| 248 | // depth_mode: 0 = z_tex (aux.z), 1 = aux_img_tex luma (FogImage as depth) | |
| 245 | // depth_mode: 0 = z_tex (aux.z), 1 = no depth: the image sits at Z = 0 in front of an opaque fog background | |
| 249 | 246 | // p[3] = (blend, has_mask, mask_inv, mbm) |
| 250 | 247 | // p[4] = process_skip (r, g, b, a) |
| 251 | 248 | // ----------------------------------------------------------------------------- |
| ... | ... | @@ -269,8 +266,7 @@ fn fog_op(@builtin(global_invocation_id) gid: vec3<u32>) { |
| 269 | 266 | let has_fog_color_img = params.p[2].z > 0.5; |
| 270 | 267 | |
| 271 | 268 | if (has_fog_color_img) { |
| 272 | let fi = textureSampleLevel(aux_img_tex, samp, uv, 0.0); | |
| 273 | fog_col = vec4<f32>(fog_col.rgb * fi.rgb, fog_col.a * fi.a); | |
| 269 | fog_col = textureSampleLevel(aux_img_tex, samp, uv, 0.0); | |
| 274 | 270 | } |
| 275 | 271 | |
| 276 | 272 | var t_raw = 0.0; |
| ... | ... | @@ -287,23 +283,24 @@ fn fog_op(@builtin(global_invocation_id) gid: vec3<u32>) { |
| 287 | 283 | t_raw = select(0.0, 1.0, z_eff <= near_p); |
| 288 | 284 | } |
| 289 | 285 | } |
| 286 | } else if (abs(denom) > 1e-6) { | |
| 287 | t_raw = clamp(-near_p / denom, 0.0, 1.0); | |
| 290 | 288 | } else { |
| 291 | let d_img = textureSampleLevel(aux_img_tex, samp, uv, 0.0); | |
| 292 | let z_eff = luma_709(d_img.rgb) * z_scale; | |
| 293 | if (abs(denom) > 1e-6) { | |
| 294 | t_raw = clamp((z_eff - near_p) / denom, 0.0, 1.0); | |
| 295 | } else { | |
| 296 | t_raw = clamp(z_eff, 0.0, 1.0); | |
| 297 | } | |
| 289 | t_raw = select(0.0, 1.0, near_p >= 0.0); | |
| 298 | 290 | } |
| 299 | 291 | |
| 300 | 292 | let f = clamp(pow(t_raw, falloff) * fog_opacity, 0.0, 1.0); |
| 301 | 293 | let fog_a = clamp(fog_col.a, 0.0, 1.0); |
| 302 | // Premultiplied fog composite: opaque surfaces always fog cleanly, while | |
| 303 | // transparent sky receives fog scaled by FogAlpha. | |
| 304 | let out_rgb = src.rgb * (1.0 - f) + fog_col.rgb * (f * (src.a + (1.0 - src.a) * fog_a)); | |
| 305 | let out_a = src.a + (1.0 - src.a) * (f * fog_a); | |
| 306 | let fogged = vec4<f32>(out_rgb, out_a); | |
| 294 | var fogged: vec4<f32>; | |
| 295 | if (depth_mode == 1) { | |
| 296 | let surface = src.rgb * (1.0 - f) + fog_col.rgb * (f * src.a); | |
| 297 | fogged = vec4<f32>(surface + fog_col.rgb * (fog_opacity * (1.0 - src.a)), min(src.a + fog_a * fog_opacity, 1.0)); | |
| 298 | } else { | |
| 299 | // Premultiplied fog composite: opaque surfaces always fog cleanly, while | |
| 300 | // transparent sky receives fog scaled by FogAlpha. | |
| 301 | let out_rgb = src.rgb * (1.0 - f) + fog_col.rgb * (f * (src.a + (1.0 - src.a) * fog_a)); | |
| 302 | fogged = vec4<f32>(out_rgb, src.a + (1.0 - src.a) * (f * fog_a)); | |
| 303 | } | |
| 307 | 304 | |
| 308 | 305 | let out = finalize_fx( |
| 309 | 306 | src, |
| ... | ... | @@ -320,7 +317,7 @@ fn fog_op(@builtin(global_invocation_id) gid: vec3<u32>) { |
| 320 | 317 | |
| 321 | 318 | // ----------------------------------------------------------------------------- |
| 322 | 319 | // 3a. Highlight — bright pixel extraction pass |
| 323 | // p[0] = (low, high, strength, 0) | |
| 320 | // p[0] = (low, high, curve, quantize_8bit) | |
| 324 | 321 | // ----------------------------------------------------------------------------- |
| 325 | 322 | @compute @workgroup_size(8, 8) |
| 326 | 323 | fn highlight_extract_op(@builtin(global_invocation_id) gid: vec3<u32>) { |
| ... | ... | @@ -328,32 +325,45 @@ fn highlight_extract_op(@builtin(global_invocation_id) gid: vec3<u32>) { |
| 328 | 325 | if (gid.x >= dims.x || gid.y >= dims.y) { |
| 329 | 326 | return; |
| 330 | 327 | } |
| 331 | let uv = (vec2<f32>(gid.xy) + 0.5) / vec2<f32>(dims); | |
| 332 | let src = textureSampleLevel(src_tex, samp, uv, 0.0); | |
| 328 | let src = textureLoad(src_tex, vec2<i32>(gid.xy), 0); | |
| 333 | 329 | let low = params.p[0].x; |
| 334 | 330 | let high = params.p[0].y; |
| 335 | let strength = max(params.p[0].z, 0.0); | |
| 336 | ||
| 337 | let lum = luma_709(max(src.rgb, vec3<f32>(0.0))); | |
| 331 | let lum = luma_709(src.rgb); | |
| 332 | // Fusion's ramp reaches (High - Low)^(2 * Curve - 1) at High, then jumps to full strength above it. | |
| 333 | let curve = params.p[0].z; | |
| 338 | 334 | var w = 0.0; |
| 339 | if (high > low + 1e-5) { | |
| 340 | w = clamp((lum - low) / (high - low), 0.0, 1.0); | |
| 335 | if (lum <= low) { | |
| 336 | w = 0.0; | |
| 337 | } else if (lum > high) { | |
| 338 | w = 1.0; | |
| 341 | 339 | } else { |
| 342 | w = select(0.0, 1.0, lum > high + 1e-5); | |
| 340 | w = pow(lum - low, curve) * pow(high - low, curve - 1.0); | |
| 343 | 341 | } |
| 344 | let extracted = vec4<f32>(src.rgb * (w * strength), w * src.a); | |
| 345 | textureStore(dst_tex, vec2<i32>(gid.xy), sanitize_out(extracted)); | |
| 342 | textureStore(dst_tex, vec2<i32>(gid.xy), sanitize_out(src * w)); | |
| 343 | } | |
| 344 | ||
| 345 | fn highlight_tap(p: vec2<f32>, dims: vec2<i32>) -> vec4<f32> { | |
| 346 | let i = vec2<i32>(floor(p)); | |
| 347 | let f = p - floor(p); | |
| 348 | var c = array<vec4<f32>, 4>(); | |
| 349 | for (var k = 0; k < 4; k = k + 1) { | |
| 350 | let q = i + vec2<i32>(k & 1, k >> 1u); | |
| 351 | if (all(q >= vec2<i32>(0)) && all(q < dims)) { | |
| 352 | c[k] = textureLoad(aux_img_tex, q, 0); | |
| 353 | } | |
| 354 | } | |
| 355 | return mix(mix(c[0], c[1], f.x), mix(c[2], c[3], f.x), f.y); | |
| 346 | 356 | } |
| 347 | 357 | |
| 348 | 358 | // ----------------------------------------------------------------------------- |
| 349 | // 3b. Highlight — directional starburst streaks + composite pass | |
| 359 | // 3b. Highlight — starburst streaks + composite pass | |
| 350 | 360 | // src_tex = original image |
| 351 | 361 | // aux_img_tex = extracted bright texture from highlight_extract_op |
| 352 | // p[0] = (num_points, angle_rad, length_px, falloff) | |
| 353 | // p[1] = (tint_r, tint_g, tint_b, merge_with_original) | |
| 362 | // p[0] = (num_points, angle_rad, taps, merge_over) | |
| 363 | // p[1] = per-channel decay d: tap s weighs d^s | |
| 354 | 364 | // p[2] = (blend, has_mask, mask_inv, mbm) |
| 355 | 365 | // p[3] = process_skip (r, g, b, a) |
| 356 | // p[4] = (steps_per_ray, 0, 0, 0) | |
| 366 | // p[4] = extraction params (low, high, curve, quantize_8bit) | |
| 357 | 367 | // ----------------------------------------------------------------------------- |
| 358 | 368 | @compute @workgroup_size(8, 8) |
| 359 | 369 | fn highlight_streaks_op(@builtin(global_invocation_id) gid: vec3<u32>) { |
| ... | ... | @@ -361,62 +371,33 @@ fn highlight_streaks_op(@builtin(global_invocation_id) gid: vec3<u32>) { |
| 361 | 371 | if (gid.x >= dims.x || gid.y >= dims.y) { |
| 362 | 372 | return; |
| 363 | 373 | } |
| 374 | let idims = vec2<i32>(dims); | |
| 364 | 375 | let fdims = vec2<f32>(dims); |
| 365 | let inv_dims = 1.0 / fdims; | |
| 366 | let uv = (vec2<f32>(gid.xy) + 0.5) / fdims; | |
| 367 | let src = textureSampleLevel(src_tex, samp, uv, 0.0); | |
| 368 | ||
| 369 | let num_points = clamp(i32(round(params.p[0].x)), 1, 16); | |
| 370 | let base_angle = params.p[0].y; | |
| 371 | let length_px = max(params.p[0].z, 0.0); | |
| 372 | let falloff = max(params.p[0].w, 0.05); | |
| 373 | let tint = params.p[1].rgb; | |
| 374 | let merge_orig = params.p[1].w > 0.5; | |
| 375 | let steps = clamp(i32(round(params.p[4].x)), 4, 48); | |
| 376 | ||
| 377 | let center_bright = textureSampleLevel(aux_img_tex, samp, uv, 0.0); | |
| 378 | var streak = center_bright * 0.25; | |
| 379 | if (length_px > 0.25) { | |
| 380 | let fsteps = f32(steps); | |
| 381 | let ray_norm = 1.0 / max(f32(num_points) * 0.35 + 0.65, 1.0); | |
| 382 | for (var k = 0; k < num_points; k = k + 1) { | |
| 383 | let a = base_angle + TAU * (f32(k) / f32(num_points)); | |
| 384 | // Y-up Fusion angle -> Y-down texture coordinate step | |
| 385 | let dir = vec2<f32>(cos(a), -sin(a)) * inv_dims; | |
| 386 | var ray_acc = vec4<f32>(0.0); | |
| 387 | var ray_wsum = 0.0; | |
| 388 | for (var s = 1; s <= steps; s = s + 1) { | |
| 389 | let t = f32(s) / fsteps; | |
| 390 | let su = uv + dir * (t * length_px); | |
| 391 | let w = pow(max(1.0 - t, 0.0), falloff * 1.8); | |
| 392 | if (su.x >= 0.0 && su.x <= 1.0 && su.y >= 0.0 && su.y <= 1.0) { | |
| 393 | ray_acc += textureSampleLevel(aux_img_tex, samp, su, 0.0) * w; | |
| 394 | } | |
| 395 | ray_wsum += w; | |
| 376 | let pos = vec2<f32>(gid.xy); | |
| 377 | let src = textureLoad(src_tex, vec2<i32>(gid.xy), 0); | |
| 378 | ||
| 379 | let num_points = i32(params.p[0].x); | |
| 380 | let taps = i32(params.p[0].z); | |
| 381 | var streak = vec4<f32>(0.0); | |
| 382 | for (var k = 0; k < num_points; k = k + 1) { | |
| 383 | let a = params.p[0].y + TAU * f32(k) / f32(num_points); | |
| 384 | let dir = vec2<f32>(cos(a), -sin(a)); | |
| 385 | var w = vec4<f32>(1.0); | |
| 386 | for (var s = 1; s <= taps; s = s + 1) { | |
| 387 | let q = pos - dir * f32(s); | |
| 388 | if (any(q <= vec2<f32>(-1.0)) || any(q >= fdims)) { | |
| 389 | break; | |
| 396 | 390 | } |
| 397 | streak += (ray_acc / max(ray_wsum * 0.35, 1e-4)) * ray_norm; | |
| 391 | w *= params.p[1]; | |
| 392 | streak += w * highlight_tap(q, idims); | |
| 398 | 393 | } |
| 399 | 394 | } |
| 400 | 395 | |
| 401 | let colored_streak = vec4<f32>(streak.rgb * tint, clamp(streak.a, 0.0, 1.0)); | |
| 402 | var fx = colored_streak; | |
| 403 | if (merge_orig) { | |
| 404 | fx = vec4<f32>( | |
| 405 | src.rgb + colored_streak.rgb, | |
| 406 | clamp(src.a + colored_streak.a * (1.0 - src.a), 0.0, 1.0), | |
| 407 | ); | |
| 408 | } | |
| 409 | ||
| 410 | let out = finalize_fx( | |
| 411 | src, | |
| 412 | fx, | |
| 413 | uv, | |
| 414 | params.p[2].x, | |
| 415 | params.p[2].y, | |
| 416 | params.p[2].z, | |
| 417 | params.p[2].w, | |
| 418 | params.p[3], | |
| 419 | ); | |
| 396 | var fx = select(streak, src + streak, params.p[0].w > 0.5); | |
| 397 | // Fusion stores an 8-bit effect result before Blend mixes it with the source. | |
| 398 | if (params.p[4].w > 0.5) { fx = floor(clamp(fx, vec4<f32>(0.0), vec4<f32>(1.0)) * 255.0 + 0.5) / 255.0; } | |
| 399 | let uv = (pos + 0.5) / fdims; | |
| 400 | let out = finalize_fx(src, fx, uv, params.p[2].x, params.p[2].y, params.p[2].z, params.p[2].w, params.p[3]); | |
| 420 | 401 | textureStore(dst_tex, vec2<i32>(gid.xy), out); |
| 421 | 402 | } |
| 422 | 403 |
crates/engine/src/shaders/fx_fuses.wgsl+43-85| ... | ... | @@ -1,6 +1,6 @@ |
| 1 | 1 | // Wave 36 compute shaders: |
| 2 | 2 | // - VectorDenoise (motion-compensated bilateral temporal denoiser) |
| 3 | // - Mandel (escape-time Mandelbrot / Julia fractal generator with smooth coloring) | |
| 3 | // - Mandel (escape-time Mandelbrot generator with continuous-potential coloring) | |
| 4 | 4 | // - UnsharpMask (thresholded high-frequency sharpening boost) |
| 5 | 5 | // - Letterbox (aspect-preserving Letterbox & Pan-and-Scan framing) |
| 6 | 6 | // - Fuse.Wipe (directional / radial / iris / box transition wipe) |
| ... | ... | @@ -57,20 +57,11 @@ fn apply_channel_blend( |
| 57 | 57 | orig: vec4<f32>, |
| 58 | 58 | effect: vec4<f32>, |
| 59 | 59 | eff: f32, |
| 60 | mask_v: f32, | |
| 61 | 60 | mbm: f32, |
| 62 | 61 | skip: vec4<f32>, |
| 63 | 62 | ) -> vec4<f32> { |
| 64 | var out_c = mix(orig, effect, eff); | |
| 65 | if (mbm > 0.5) { | |
| 66 | out_c = out_c * mask_v; | |
| 67 | } | |
| 68 | return vec4<f32>( | |
| 69 | select(out_c.r, orig.r, skip.x > 0.5), | |
| 70 | select(out_c.g, orig.g, skip.y > 0.5), | |
| 71 | select(out_c.b, orig.b, skip.z > 0.5), | |
| 72 | select(out_c.a, orig.a, skip.w > 0.5), | |
| 73 | ); | |
| 63 | let out_c = select(mix(orig, effect, eff), effect * eff, mbm > 0.5); | |
| 64 | return select(out_c, select(orig, vec4<f32>(0.0), mbm > 0.5), skip > vec4<f32>(0.5)); | |
| 74 | 65 | } |
| 75 | 66 | |
| 76 | 67 | fn safe_smoothstep(lo: f32, hi: f32, x: f32) -> f32 { |
| ... | ... | @@ -234,93 +225,60 @@ fn vd_finalize_op(@builtin(global_invocation_id) gid: vec3<u32>) { |
| 234 | 225 | let eff_col = textureLoad(src_b, p, 0); |
| 235 | 226 | let m = read_mask(gid.xy, dims, u.p[0].y, u.p[0].z); |
| 236 | 227 | let mbm = u.p[0].w; |
| 237 | let eff = select(clamp(u.p[0].x * m, 0.0, 1.0), clamp(u.p[0].x, 0.0, 1.0), mbm > 0.5); | |
| 238 | let out_c = apply_channel_blend(orig, eff_col, eff, m, mbm, u.p[1]); | |
| 228 | let eff = clamp(u.p[0].x * m, 0.0, 1.0); | |
| 229 | let out_c = apply_channel_blend(orig, eff_col, eff, mbm, u.p[1]); | |
| 239 | 230 | store_dst(p, out_c); |
| 240 | 231 | } |
| 241 | 232 | |
| 242 | 233 | // ============================================================================ |
| 243 | // 2. Mandel: Mandelbrot / Julia escape-time fractal generator | |
| 234 | // 2. Mandel: Fusion's escape-time Mandelbrot generator | |
| 244 | 235 | // ============================================================================ |
| 245 | // src_b = optional 256x1 Gradient LUT when p[4].x > 0.5 | |
| 246 | 236 | // mask_tex = EffectMask |
| 247 | // p[0] = (cx, cy, zoom, rot_rad) | |
| 248 | // p[1] = (mode_julia, max_iter, escape_r2, grad_curve) | |
| 249 | // p[2] = (julia_cr, julia_ci, r_rep, g_rep) | |
| 250 | // p[3] = (b_rep, r_phase, g_phase, b_phase) | |
| 251 | // p[4] = (has_lut, blend, has_mask, mask_inv) | |
| 252 | // p[5] = tint_rgba | |
| 253 | // p[6] = inside_rgba | |
| 237 | // p[0] = (x_position, y_position, units_per_pixel, rotation_rad) | |
| 238 | // p[1] = (iterations, escape_limit, gradient_curve, grad_method: 0 = Continuous Potential, 1 = Iterations) | |
| 239 | // p[2] = repetitions (r, g, b, a) | |
| 240 | // p[3] = phases (r, g, b, a) | |
| 241 | // p[4] = (blend, has_mask, mask_inv, log2 of the frame's largest potential) | |
| 254 | 242 | @compute @workgroup_size(8, 8) |
| 255 | 243 | fn mandel_op(@builtin(global_invocation_id) gid: vec3<u32>) { |
| 256 | 244 | let dims = textureDimensions(dst_tex); |
| 257 | 245 | if (gid.x >= dims.x || gid.y >= dims.y) { return; } |
| 258 | 246 | |
| 259 | let p = vec2<i32>(gid.xy); | |
| 260 | let fdims = vec2<f32>(dims); | |
| 261 | let fu = pix_to_fu(gid.xy, dims); | |
| 262 | let aspect = fdims.x / max(fdims.y, 1.0); | |
| 263 | ||
| 264 | let zoom = max(u.p[0].z, 1e-6); | |
| 265 | let span_y = 2.6 / zoom; | |
| 266 | let span_x = span_y * aspect; | |
| 267 | let local = vec2<f32>((fu.x - 0.5) * span_x, (fu.y - 0.5) * span_y); | |
| 247 | // Mirrors `mandel_c` in fx_fuses.rs. | |
| 248 | let local = vec2<f32>(f32(gid.x), f32(gid.y) + 1.0) - 0.5 * vec2<f32>(dims); | |
| 268 | 249 | let ca = cos(u.p[0].w); |
| 269 | 250 | let sa = sin(u.p[0].w); |
| 270 | let rot = vec2<f32>(local.x * ca - local.y * sa, local.x * sa + local.y * ca); | |
| 271 | let plane = vec2<f32>(u.p[0].x, u.p[0].y) + rot; | |
| 272 | ||
| 273 | let is_julia = u.p[1].x > 0.5; | |
| 274 | let max_iter = clamp(i32(round(u.p[1].y)), 1, 1024); | |
| 275 | let escape_r2 = max(u.p[1].z, 16.0); | |
| 276 | ||
| 277 | var z = select(vec2<f32>(0.0, 0.0), plane, is_julia); | |
| 278 | let c = select(plane, vec2<f32>(u.p[2].x, u.p[2].y), is_julia); | |
| 279 | ||
| 280 | var iter: i32 = 0; | |
| 281 | var z2: f32 = dot(z, z); | |
| 282 | for (var i: i32 = 0; i < 1024; i = i + 1) { | |
| 283 | if (i >= max_iter || z2 > escape_r2) { | |
| 284 | break; | |
| 285 | } | |
| 286 | let zx = z.x * z.x - z.y * z.y + c.x; | |
| 287 | let zy = 2.0 * z.x * z.y + c.y; | |
| 288 | z = vec2<f32>(zx, zy); | |
| 251 | let c = u.p[0].xy + vec2<f32>(local.x * ca - local.y * sa, local.x * sa + local.y * ca) * u.p[0].z; | |
| 252 | ||
| 253 | let max_iter = i32(u.p[1].x); | |
| 254 | let escape_r2 = u.p[1].y * u.p[1].y; | |
| 255 | var z = vec2<f32>(0.0); | |
| 256 | var iter = 0; | |
| 257 | var z2 = 0.0; | |
| 258 | loop { | |
| 259 | if (iter >= max_iter || z2 > escape_r2) { break; } | |
| 260 | z = vec2<f32>(z.x * z.x - z.y * z.y, 2.0 * z.x * z.y) + c; | |
| 289 | 261 | z2 = dot(z, z); |
| 290 | 262 | iter = iter + 1; |
| 291 | 263 | } |
| 292 | 264 | |
| 293 | var col: vec4<f32>; | |
| 294 | if (z2 <= escape_r2) { | |
| 295 | col = u.p[6]; | |
| 296 | } else { | |
| 297 | // Smooth continuous escape-time coloring: iter + 1 - log2(log2(|z|)) | |
| 298 | let mag = max(sqrt(z2), 2.0001); | |
| 299 | let log_zn = log2(mag); | |
| 300 | let nu = max(f32(iter) + 1.0 - log2(max(log_zn, 1.0001)), 0.0); | |
| 301 | let curve = max(u.p[1].w, 0.05); | |
| 302 | let norm_t = pow(clamp(nu / max(f32(max_iter), 1.0), 0.0, 1.0), curve); | |
| 303 | ||
| 304 | if (u.p[4].x > 0.5) { | |
| 305 | let lut_u = clamp(norm_t, 0.0, 1.0); | |
| 306 | col = textureSampleLevel(src_b, samp_lin, vec2<f32>(lut_u, 0.5), 0.0); | |
| 265 | // Points inside the set stay transparent black. | |
| 266 | var col = vec4<f32>(0.0); | |
| 267 | if (z2 > escape_r2) { | |
| 268 | let curve = u.p[1].z; | |
| 269 | var t: f32; | |
| 270 | if (u.p[1].w < 0.5) { | |
| 271 | let log2_pot = log2(0.5 * log(z2)) - f32(iter); | |
| 272 | t = 1.0 - exp2(curve * (log2_pot - u.p[4].w)); | |
| 307 | 273 | } else { |
| 308 | let r_rep = u.p[2].z; | |
| 309 | let g_rep = u.p[2].w; | |
| 310 | let b_rep = u.p[3].x; | |
| 311 | let r_ph = u.p[3].y; | |
| 312 | let g_ph = u.p[3].z; | |
| 313 | let b_ph = u.p[3].w; | |
| 314 | let r = 0.5 - 0.5 * cos(TAU * (norm_t * r_rep + r_ph)); | |
| 315 | let g = 0.5 - 0.5 * cos(TAU * (norm_t * g_rep + g_ph)); | |
| 316 | let b = 0.5 - 0.5 * cos(TAU * (norm_t * b_rep + b_ph)); | |
| 317 | col = vec4<f32>(r, g, b, 1.0) * u.p[5]; | |
| 274 | t = pow((f32(iter) + 0.75) / f32(max_iter), 1.0 - curve); | |
| 318 | 275 | } |
| 276 | // Each channel wraps t * repetitions + phase back into [0, 1]. | |
| 277 | let v = vec4<f32>(clamp(t, 0.0, 1.0)) * u.p[2] + u.p[3]; | |
| 278 | col = select(fract(v), v, (v >= vec4<f32>(0.0)) & (v <= vec4<f32>(1.0))); | |
| 319 | 279 | } |
| 320 | ||
| 321 | let m = read_mask(gid.xy, dims, u.p[4].z, u.p[4].w); | |
| 322 | let eff = clamp(u.p[4].y * m, 0.0, 1.0); | |
| 323 | store_dst(p, col * eff); | |
| 280 | let m = read_mask(gid.xy, dims, u.p[4].y, u.p[4].z); | |
| 281 | store_dst(vec2<i32>(gid.xy), col * clamp(u.p[4].x * m, 0.0, 1.0)); | |
| 324 | 282 | } |
| 325 | 283 | |
| 326 | 284 | // ============================================================================ |
| ... | ... | @@ -352,8 +310,8 @@ fn unsharp_mask_op(@builtin(global_invocation_id) gid: vec3<u32>) { |
| 352 | 310 | |
| 353 | 311 | let m = read_mask(gid.xy, dims, u.p[0].w, u.p[1].x); |
| 354 | 312 | let mbm = u.p[1].y; |
| 355 | let eff = select(clamp(u.p[0].z * m, 0.0, 1.0), clamp(u.p[0].z, 0.0, 1.0), mbm > 0.5); | |
| 356 | let out_c = apply_channel_blend(orig, boosted, eff, m, mbm, u.p[2]); | |
| 313 | let eff = clamp(u.p[0].z * m, 0.0, 1.0); | |
| 314 | let out_c = apply_channel_blend(orig, boosted, eff, mbm, u.p[2]); | |
| 357 | 315 | store_dst(p, out_c); |
| 358 | 316 | } |
| 359 | 317 | |
| ... | ... | @@ -525,8 +483,8 @@ fn wipe_op(@builtin(global_invocation_id) gid: vec3<u32>) { |
| 525 | 483 | let wiped = mix(bg, fg, w); |
| 526 | 484 | let m = read_mask(gid.xy, dims, u.p[2].y, u.p[2].z); |
| 527 | 485 | let mbm = u.p[2].w; |
| 528 | let eff = select(clamp(u.p[2].x * m, 0.0, 1.0), clamp(u.p[2].x, 0.0, 1.0), mbm > 0.5); | |
| 529 | let out_c = apply_channel_blend(bg, wiped, eff, m, mbm, u.p[3]); | |
| 486 | let eff = clamp(u.p[2].x * m, 0.0, 1.0); | |
| 487 | let out_c = apply_channel_blend(bg, wiped, eff, mbm, u.p[3]); | |
| 530 | 488 | store_dst(p, out_c); |
| 531 | 489 | } |
| 532 | 490 | |
| ... | ... | @@ -635,7 +593,7 @@ fn ocl_rays_op(@builtin(global_invocation_id) gid: vec3<u32>) { |
| 635 | 593 | |
| 636 | 594 | let m = read_mask(gid.xy, dims, u.p[3].y, u.p[3].z); |
| 637 | 595 | let mbm = u.p[3].w; |
| 638 | let eff = select(clamp(u.p[3].x * m, 0.0, 1.0), clamp(u.p[3].x, 0.0, 1.0), mbm > 0.5); | |
| 639 | let out_c = apply_channel_blend(orig, effect, eff, m, mbm, u.p[5]); | |
| 596 | let eff = clamp(u.p[3].x * m, 0.0, 1.0); | |
| 597 | let out_c = apply_channel_blend(orig, effect, eff, mbm, u.p[5]); | |
| 640 | 598 | store_dst(p, out_c); |
| 641 | 599 | } |
crates/engine/src/shaders/surface_fx.wgsl+10-19| ... | ... | @@ -133,20 +133,11 @@ fn apply_channel_blend( |
| 133 | 133 | orig: vec4<f32>, |
| 134 | 134 | effect: vec4<f32>, |
| 135 | 135 | eff: f32, |
| 136 | mask_v: f32, | |
| 137 | 136 | mbm: f32, |
| 138 | 137 | skip: vec4<f32>, |
| 139 | 138 | ) -> vec4<f32> { |
| 140 | var out_c = mix(orig, effect, eff); | |
| 141 | if (mbm > 0.5) { | |
| 142 | out_c = out_c * mask_v; | |
| 143 | } | |
| 144 | return vec4<f32>( | |
| 145 | select(out_c.r, orig.r, skip.x > 0.5), | |
| 146 | select(out_c.g, orig.g, skip.y > 0.5), | |
| 147 | select(out_c.b, orig.b, skip.z > 0.5), | |
| 148 | select(out_c.a, orig.a, skip.w > 0.5), | |
| 149 | ); | |
| 139 | let out_c = select(mix(orig, effect, eff), effect * eff, mbm > 0.5); | |
| 140 | return select(out_c, select(orig, vec4<f32>(0.0), mbm > 0.5), skip > vec4<f32>(0.5)); | |
| 150 | 141 | } |
| 151 | 142 | |
| 152 | 143 | fn extract_channel(c: vec4<f32>, ch: i32) -> f32 { |
| ... | ... | @@ -250,7 +241,7 @@ fn distort_op(@builtin(global_invocation_id) gid: vec3<u32>) { |
| 250 | 241 | |
| 251 | 242 | let mask_v = read_mask(gid.xy, dims, u.p[3].x, u.p[3].y); |
| 252 | 243 | let eff = u.p[2].w * mask_v; |
| 253 | store_dst(p, apply_channel_blend(orig, effect, eff, mask_v, u.p[3].z, u.p[5])); | |
| 244 | store_dst(p, apply_channel_blend(orig, effect, eff, u.p[3].z, u.p[5])); | |
| 254 | 245 | } |
| 255 | 246 | |
| 256 | 247 | // ---------------------------------------------------------------------------- |
| ... | ... | @@ -320,7 +311,7 @@ fn create_bump_map_op(@builtin(global_invocation_id) gid: vec3<u32>) { |
| 320 | 311 | |
| 321 | 312 | let mask_v = read_mask(gid.xy, dims, u.p[2].x, u.p[2].y); |
| 322 | 313 | let eff = u.p[1].w * mask_v; |
| 323 | store_dst(p, apply_channel_blend(orig, effect, eff, mask_v, u.p[2].z, u.p[3])); | |
| 314 | store_dst(p, apply_channel_blend(orig, effect, eff, u.p[2].z, u.p[3])); | |
| 324 | 315 | } |
| 325 | 316 | |
| 326 | 317 | // ---------------------------------------------------------------------------- |
| ... | ... | @@ -399,7 +390,7 @@ fn create_relief_map_op(@builtin(global_invocation_id) gid: vec3<u32>) { |
| 399 | 390 | |
| 400 | 391 | let mask_v = read_mask(gid.xy, dims, u.p[1].z, u.p[1].w); |
| 401 | 392 | let eff = u.p[1].y * mask_v; |
| 402 | store_dst(p, apply_channel_blend(orig, effect, eff, mask_v, u.p[2].x, u.p[4])); | |
| 393 | store_dst(p, apply_channel_blend(orig, effect, eff, u.p[2].x, u.p[4])); | |
| 403 | 394 | } |
| 404 | 395 | |
| 405 | 396 | // ---------------------------------------------------------------------------- |
| ... | ... | @@ -448,7 +439,7 @@ fn custom_filter_op(@builtin(global_invocation_id) gid: vec3<u32>) { |
| 448 | 439 | |
| 449 | 440 | let mask_v = read_mask(gid.xy, dims, u.p[1].x, u.p[1].y); |
| 450 | 441 | let eff = u.p[0].w * mask_v; |
| 451 | store_dst(p, apply_channel_blend(orig, effect, eff, mask_v, u.p[1].z, u.p[2])); | |
| 442 | store_dst(p, apply_channel_blend(orig, effect, eff, u.p[1].z, u.p[2])); | |
| 452 | 443 | } |
| 453 | 444 | |
| 454 | 445 | // ---------------------------------------------------------------------------- |
| ... | ... | @@ -580,7 +571,7 @@ fn cineon_log_op(@builtin(global_invocation_id) gid: vec3<u32>) { |
| 580 | 571 | |
| 581 | 572 | let mask_v = read_mask(gid.xy, dims, u.p[1].x, u.p[1].y); |
| 582 | 573 | let eff = u.p[0].w * mask_v; |
| 583 | store_dst(p, apply_channel_blend(orig, effect, eff, mask_v, u.p[1].z, u.p[2])); | |
| 574 | store_dst(p, apply_channel_blend(orig, effect, eff, u.p[1].z, u.p[2])); | |
| 584 | 575 | } |
| 585 | 576 | |
| 586 | 577 | // ---------------------------------------------------------------------------- |
| ... | ... | @@ -611,7 +602,7 @@ fn light_trim_op(@builtin(global_invocation_id) gid: vec3<u32>) { |
| 611 | 602 | |
| 612 | 603 | let mask_v = read_mask(gid.xy, dims, u.p[1].z, u.p[1].w); |
| 613 | 604 | let eff = u.p[1].y * mask_v; |
| 614 | store_dst(p, apply_channel_blend(orig, effect, eff, mask_v, u.p[2].x, u.p[3])); | |
| 605 | store_dst(p, apply_channel_blend(orig, effect, eff, u.p[2].x, u.p[3])); | |
| 615 | 606 | } |
| 616 | 607 | |
| 617 | 608 | // ---------------------------------------------------------------------------- |
| ... | ... | @@ -799,7 +790,7 @@ fn tv_op(@builtin(global_invocation_id) gid: vec3<u32>) { |
| 799 | 790 | |
| 800 | 791 | let mask_v = read_mask(gid.xy, dims, u.p[3].w, u.p[4].x); |
| 801 | 792 | let eff = u.p[3].z * mask_v; |
| 802 | store_dst(p, apply_channel_blend(orig, effect, eff, mask_v, u.p[4].y, u.p[5])); | |
| 793 | store_dst(p, apply_channel_blend(orig, effect, eff, u.p[4].y, u.p[5])); | |
| 803 | 794 | } |
| 804 | 795 | |
| 805 | 796 | // ---------------------------------------------------------------------------- |
| ... | ... | @@ -901,5 +892,5 @@ fn frame_avg_finish_op(@builtin(global_invocation_id) gid: vec3<u32>) { |
| 901 | 892 | |
| 902 | 893 | let mask_v = read_mask(gid.xy, dims, u.p[0].z, u.p[0].w); |
| 903 | 894 | let eff = u.p[0].y * mask_v; |
| 904 | store_dst(p, apply_channel_blend(orig, effect, eff, mask_v, u.p[1].x, u.p[2])); | |
| 895 | store_dst(p, apply_channel_blend(orig, effect, eff, u.p[1].x, u.p[2])); | |
| 905 | 896 | } |
crates/engine/src/shaders/warps_masks.wgsl+6-14| ... | ... | @@ -91,17 +91,9 @@ fn sample_wrap_u_clamp_v(tex: texture_2d<f32>, fu: vec2<f32>) -> vec4<f32> { |
| 91 | 91 | return mix(mix(c00, c10, tx), mix(c01, c11, tx), ty); |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | fn apply_channel_blend(orig: vec4<f32>, effect: vec4<f32>, eff: f32, mask_v: f32, mbm: f32, skip: vec4<f32>) -> vec4<f32> { | |
| 95 | var out = mix(orig, effect, eff); | |
| 96 | if (mbm > 0.5) { | |
| 97 | out = out * mask_v; | |
| 98 | } | |
| 99 | return vec4<f32>( | |
| 100 | select(out.r, orig.r, skip.x > 0.5), | |
| 101 | select(out.g, orig.g, skip.y > 0.5), | |
| 102 | select(out.b, orig.b, skip.z > 0.5), | |
| 103 | select(out.a, orig.a, skip.w > 0.5), | |
| 104 | ); | |
| 94 | fn apply_channel_blend(orig: vec4<f32>, effect: vec4<f32>, eff: f32, mbm: f32, skip: vec4<f32>) -> vec4<f32> { | |
| 95 | let out_c = select(mix(orig, effect, eff), effect * eff, mbm > 0.5); | |
| 96 | return select(out_c, select(orig, vec4<f32>(0.0), mbm > 0.5), skip > vec4<f32>(0.5)); | |
| 105 | 97 | } |
| 106 | 98 | |
| 107 | 99 | // ============================================================================ |
| ... | ... | @@ -141,7 +133,7 @@ fn coord_space_op(@builtin(global_invocation_id) gid: vec3<u32>) { |
| 141 | 133 | |
| 142 | 134 | let orig = textureLoad(src_a, p, 0); |
| 143 | 135 | let m = read_mask(gid.xy, dims, has_mask, mask_inv); |
| 144 | let out = apply_channel_blend(orig, warped, blend * m, m, mbm, skip); | |
| 136 | let out = apply_channel_blend(orig, warped, blend * m, mbm, skip); | |
| 145 | 137 | store_dst(p, out); |
| 146 | 138 | } |
| 147 | 139 | |
| ... | ... | @@ -275,7 +267,7 @@ fn lens_distort_op(@builtin(global_invocation_id) gid: vec3<u32>) { |
| 275 | 267 | |
| 276 | 268 | let orig = textureLoad(src_a, p, 0); |
| 277 | 269 | let m = read_mask(gid.xy, dims, has_mask, mask_inv); |
| 278 | let out = apply_channel_blend(orig, warped, blend * m, m, mbm, skip); | |
| 270 | let out = apply_channel_blend(orig, warped, blend * m, mbm, skip); | |
| 279 | 271 | store_dst(p, out); |
| 280 | 272 | } |
| 281 | 273 | |
| ... | ... | @@ -423,6 +415,6 @@ fn trails_blend_op(@builtin(global_invocation_id) gid: vec3<u32>) { |
| 423 | 415 | let eff_col = textureLoad(src_b, p, 0); |
| 424 | 416 | let blend = clamp(u.p[0].x, 0.0, 1.0); |
| 425 | 417 | let m = read_mask(gid.xy, dims, u.p[0].y, u.p[0].z); |
| 426 | let out = apply_channel_blend(orig, eff_col, blend * m, m, u.p[0].w, u.p[1]); | |
| 418 | let out = apply_channel_blend(orig, eff_col, blend * m, u.p[0].w, u.p[1]); | |
| 427 | 419 | store_dst(p, out); |
| 428 | 420 | } |