authoravatarclover caruso<git@paperclover.net>2026-12-01 15:40:49-08:00
committeravatarclover caruso<git@paperclover.net>2026-12-01 15:49:39-08:00
log38056dd778593cf0e6b61720591c70e93d58b502
tree32374c6f396a24e0e022e1d671682f73c7303cc7
parentc137ce0295f22709d2f8e0d2db6543ea0c6724dd
signature Signed by SSH key SHA256:52mNGHRsVFBDED9IAX5pe+LRWUefqTbxEReunq21QvU

fix(engine): improve Plasma and DaySky parity and optimize vortex/kscope WGSL


4 files changed, 214 insertions(+), 29 deletions(-)

crates/engine/src/eval/io.rs+36
...@@ -1682,6 +1682,42 @@ Composition {{...@@ -1682,6 +1682,42 @@ Composition {{
1682 assert!(px.iter().any(|p| *p != px[0]), "the quotient still varies across the frame");1682 assert!(px.iter().any(|p| *p != px[0]), "the quotient still varies across the frame");
1683 }1683 }
16841684
1685 #[test]
1686 fn plasma_multiply_and_divide_match_fusion_probes() {
1687 // Operation = 2 (Multiply) with Phase = 0.21449 matches Fusion 21.1 probes across high-phase fringes.
1688 if let Some(px) = render_generator("Plasma", 256, 256, "Operation = Input { Value = 2, }, Phase = Input { Value = 0.21449, },") {
1689 for (x, y, want) in [
1690 (64usize, 64usize, [181u8, 84, 12, 8]),
1691 (128, 128, [227, 254, 208, 114]),
1692 (192, 192, [4, 63, 160, 238]),
1693 ] {
1694 let p = px[y * 256 + x].map(|c| (c * 255.0).round() as u8);
1695 for ch in 0..4 {
1696 assert!(p[ch].abs_diff(want[ch]) <= 2, "op2 ({x},{y}) ch{ch}: got {p:?} want {want:?}");
1697 }
1698 }
1699 }
1700 // Operation = 3 (Divide) with scaled Type-1 & Type-2 circles + overflow fallback matches Fusion 21.1.
1701 let inputs = "Phase = Input { Value = 0.3804, }, Operation = Input { Value = 3, }, \
1702 Circle1Scale = Input { Value = 7.48849, }, Circle1Center = Input { Value = { 0.0597, 0.8826 }, }, \
1703 Circle4Type = Input { Value = 1, }, Circle4Scale = Input { Value = 9.22157, }, \
1704 Scale = Input { Value = 4.53735, }, AlphaPhase = Input { Value = 0.06949, }, \
1705 Circle2Center = Input { Value = { 0.7631, 0.8558 }, },";
1706 if let Some(px) = render_generator("Plasma", 256, 256, inputs) {
1707 for (x, y, want) in [
1708 (192usize, 128usize, [21u8, 3, 58, 18]),
1709 (192, 64, [197, 252, 235, 201]),
1710 (128, 64, [151, 233, 253, 156]),
1711 (0, 128, [245, 176, 79, 243]),
1712 ] {
1713 let p = px[y * 256 + x].map(|c| (c * 255.0).round() as u8);
1714 for ch in 0..4 {
1715 assert!(p[ch].abs_diff(want[ch]) <= 2, "op3 ({x},{y}) ch{ch}: got {p:?} want {want:?}");
1716 }
1717 }
1718 }
1719 }
1720
1685 #[test]1721 #[test]
1686 fn loader_single_frame_still_returns_empty_outside_range_unless_looping() {1722 fn loader_single_frame_still_returns_empty_outside_range_unless_looping() {
1687 let dir = std::env::temp_dir().join("fission_loader_single_still_oob_test");1723 let dir = std::env::temp_dir().join("fission_loader_single_still_oob_test");
crates/engine/src/eval/warps.rs+111-7
...@@ -379,12 +379,36 @@ impl Engine {...@@ -379,12 +379,36 @@ impl Engine {
379 let bs = comp.eval_number(node, "BackscatteredLight", time, 1.0, &self.expr).max(0.0);379 let bs = comp.eval_number(node, "BackscatteredLight", time, 1.0, &self.expr).max(0.0);
380380
381 let (sun_dir, ts) = solar_direction(lat_deg, lon_deg, month, day, hour);381 let (sun_dir, ts) = solar_direction(lat_deg, lon_deg, month, day, hour);
382 // Calibrated to Fusion 21.1 DaySky: Turbidity in [0,1] maps to T = 1.9 + 4.0 * turb382 // Calibrated to Fusion 21.1 DaySky: Turbidity in [0,1] maps to Preetham T = 2.0 + 4.0 * turb.
383 let t_preetham = 1.9 + turbidity_in * 4.0;383 let t_preetham = 2.0 + turbidity_in * 4.0;
384 let (xz, yz, _yz_lum) = preetham_zenith_xyy(t_preetham, ts);384 let (mut xz, mut yz, _yz_lum) = preetham_zenith_xyy(t_preetham, ts);
385 let mut night_lum_scale = 1.0_f64;
386 // When the sun is well below the horizon, Preetham's zenith cubic pushes yz > 0.65, which
387 // archive_fx.wgsl's [0.05, 0.65] chromaticity clamp would clip into an overly red hue.
388 // For out-of-gamut (B <= 0) night/twilight skies, project (xz, yz) into [0.05, 0.55] while
389 // preserving zenith R/G ratio and G luminance so the shader's clamp never clips.
390 if yz > 0.60 && do_tm {
391 let xt = xz / yz;
392 let zt = (1.0 - xz - yz) / yz;
393 let rt = 3.2404542 * xt - 1.5371385 - 0.4985314 * zt;
394 let gt = -0.9692660 * xt + 1.8760108 + 0.0415560 * zt;
395 let bt = 0.0556434 * xt - 0.2040259 + 1.0572252 * zt;
396 if bt <= 0.0 && gt > 1e-4 && rt > 0.0 {
397 let ratio = rt / gt;
398 let yz_cap = 0.55_f64;
399 let xc = (ratio * (1.8344548 * yz_cap + 0.0415560) + (1.0386071 * yz_cap + 0.4985314))
400 / (3.7389856 + ratio * 1.0108220);
401 let g_proj = (-1.0108220 * xc + 1.8344548 * yz_cap + 0.0415560) / yz_cap;
402 if (0.05..=0.60).contains(&xc) && g_proj > 1e-4 {
403 xz = xc;
404 yz = yz_cap;
405 night_lum_scale = gt / g_proj;
406 }
407 }
408 }
385 let c_y0 = [409 let c_y0 = [
386 0.1787 * t_preetham - 1.4630,410 0.1787 * t_preetham - 1.4630,
387 (-0.3554 * t_preetham + 0.4275) * 1.20,411 -0.3554 * t_preetham + 0.4275,
388 -0.0227 * t_preetham + 5.3251,412 -0.0227 * t_preetham + 5.3251,
389 0.1206 * t_preetham - 2.5771,413 0.1206 * t_preetham - 2.5771,
390 -0.0670 * t_preetham + 0.3703,414 -0.0670 * t_preetham + 0.3703,
...@@ -443,7 +467,7 @@ impl Engine {...@@ -443,7 +467,7 @@ impl Engine {
443 } else if !do_tm {467 } else if !do_tm {
444 1000.0468 1000.0
445 } else {469 } else {
446 (exposure / geomean_fy) as f32470 (exposure * night_lum_scale / geomean_fy) as f32
447 };471 };
448 let f_y0 = 1.0_f64;472 let f_y0 = 1.0_f64;
449 let f_x0 = eval_perez(0.0, ts, c_x);473 let f_x0 = eval_perez(0.0, ts, c_x);
...@@ -731,8 +755,8 @@ fn solar_direction(lat_deg: f64, lon_deg: f64, month: usize, day: f64, hour: f64...@@ -731,8 +755,8 @@ fn solar_direction(lat_deg: f64, lon_deg: f64, month: usize, day: f64, hour: f64
731 let b = 2.0 * std::f64::consts::PI * (doy - 81.0) / 365.0;755 let b = 2.0 * std::f64::consts::PI * (doy - 81.0) / 365.0;
732 let eot_min = 9.87 * (2.0 * b).sin() - 7.53 * b.cos() - 1.5 * b.sin();756 let eot_min = 9.87 * (2.0 * b).sin() - 7.53 * b.cos() - 1.5 * b.sin();
733 let decl = 23.44_f64.to_radians() * ((2.0 * std::f64::consts::PI / 365.0) * (doy - 81.0)).sin();757 let decl = 23.44_f64.to_radians() * ((2.0 * std::f64::consts::PI / 365.0) * (doy - 81.0)).sin();
734 let std_meridian = (lon_deg / 15.0).round() * 15.0;758 let std_meridian = (lon_deg / 15.0).trunc() * 15.0;
735 let solar_hour = hour + (lon_deg - std_meridian) / 15.0 + eot_min / 60.0;759 let solar_hour = hour + (std_meridian - lon_deg) / 15.0 + eot_min / 60.0;
736 let hour_angle = ((solar_hour - 12.0) * 15.0).to_radians();760 let hour_angle = ((solar_hour - 12.0) * 15.0).to_radians();
737 let lat = lat_deg.to_radians();761 let lat = lat_deg.to_radians();
738 let sin_alt = (lat.sin() * decl.sin() + lat.cos() * decl.cos() * hour_angle.cos()).clamp(-1.0, 1.0);762 let sin_alt = (lat.sin() * decl.sin() + lat.cos() * decl.cos() * hour_angle.cos()).clamp(-1.0, 1.0);
...@@ -1473,4 +1497,84 @@ mod tests {...@@ -1473,4 +1497,84 @@ mod tests {
1473 assert!(x_axis_diff <= 16, "Aspect < 1 must preserve X-axis ripples, got x_axis_diff={x_axis_diff}");1497 assert!(x_axis_diff <= 16, "Aspect < 1 must preserve X-axis ripples, got x_axis_diff={x_axis_diff}");
1474 assert!(y_axis_diff > 200, "Aspect=0.5 must stretch Y-axis ripples, got y_axis_diff={y_axis_diff}");1498 assert!(y_axis_diff > 200, "Aspect=0.5 must stretch Y-axis ripples, got y_axis_diff={y_axis_diff}");
1475 }1499 }
1500
1501 #[test]
1502 fn day_sky_matches_fusion_noon_night_and_longitude_sign() {
1503 let render_256 = |inputs: &str| -> Option<Vec<u8>> {
1504 let src = format!(
1505 r#"Composition {{ CurrentTime = 0, RenderRange = {{ 0, 0 }}, GlobalRange = {{ 0, 0 }}, Tools = ordered() {{
1506 DS = DaySky {{ Inputs = {{ Width = Input {{ Value = 256, }}, Height = Input {{ Value = 256, }}, {inputs} }}, }},
1507 }} }}"#
1508 );
1509 let comp = Comp::from_fusion_str(&src).unwrap();
1510 let mut eng = Engine::new_headless().ok()?;
1511 let (tex, _) = eng.evaluate(&comp, comp.find_node("DS").unwrap(), 0.0);
1512 eng.readback_rgba(&tex).ok()
1513 };
1514
1515 // 1. Default noon sky matches Fusion 21.1 T = 2.0 + 4*turb & unmodified Preetham B_Y.
1516 if let Some(px) = render_256("") {
1517 for (x, y, want) in [
1518 (128usize, 0usize, [39u8, 69, 141, 255]),
1519 (128, 128, [40, 80, 161, 255]),
1520 (128, 220, [99, 146, 222, 255]),
1521 ] {
1522 let i = (y * 256 + x) * 4;
1523 for ch in 0..4 {
1524 assert!(px[i + ch].abs_diff(want[ch]) <= 2, "noon ({x},{y}) ch{ch}: got {:?} want {want:?}", &px[i..i + 4]);
1525 }
1526 }
1527 }
1528
1529 // 2. Sun well below horizon (Time = 22.45137) preserves warm amber G/R without 0.65 chromaticity clipping.
1530 if let Some(px) = render_256("Time = Input { Value = 22.45137, },") {
1531 for (x, y, want) in [
1532 (128usize, 0usize, [111u8, 76, 0, 255]),
1533 (128, 128, [142, 97, 0, 255]),
1534 (192, 192, [208, 139, 0, 255]),
1535 ] {
1536 let i = (y * 256 + x) * 4;
1537 for ch in 0..4 {
1538 assert!(px[i + ch].abs_diff(want[ch]) <= 5, "night ({x},{y}) ch{ch}: got {:?} want {want:?}", &px[i..i + 4]);
1539 }
1540 }
1541 }
1542
1543 // 3. Longitude uses trunc(lon/15)*15 meridian & (SM - Lon) sign: 143.9376 in September sits East of South.
1544 let (dir, _) = solar_direction(41.38, 143.9376, 9, 1.0, 12.0);
1545 assert!(dir[1] > 0.0, "expected East-of-South azimuth (sun_dir.y > 0), got {dir:?}");
1546 if let Some(px) = render_256(r#"Longitude = Input { Value = 143.9376, }, Month = Input { Value = FuID { "September" }, },"#) {
1547 let i_east = (94 * 256 + 11) * 4;
1548 let i_west = (94 * 256 + 245) * 4;
1549 assert!(px[i_east] > px[i_west], "East peak at x=11 should be brighter than x=245: {:?} vs {:?}", &px[i_east..i_east + 3], &px[i_west..i_west + 3]);
1550 }
1551 }
1552
1553 #[test]
1554 fn vortex_and_kscope_early_outs_preserve_mask_and_channels() {
1555 let vortex_src = r#"Composition { CurrentTime = 0, RenderRange = { 0, 0 }, GlobalRange = { 0, 0 }, Tools = ordered() {
1556 BG = Background { Inputs = { Width = Input { Value = 64, }, Height = Input { Value = 64, },
1557 Type = Input { Value = FuID { "Horizontal" }, },
1558 TopLeftRed = Input { Value = 0.2, }, TopRightRed = Input { Value = 0.9, }, TopLeftAlpha = Input { Value = 1, }, }, },
1559 Rect = RectangleMask { Inputs = { Width = Input { Value = 0.5, }, Height = Input { Value = 0.5, },
1560 MaskWidth = Input { Value = 64, }, MaskHeight = Input { Value = 64, }, }, },
1561 V0 = Vortex { Inputs = { Angle = Input { Value = 0, }, MultiplyByMask = Input { Value = 1, },
1562 ProcessRed = Input { Value = 0, }, Blend = Input { Value = 0.5, },
1563 Input = Input { SourceOp = "BG", Source = "Output", }, EffectMask = Input { SourceOp = "Rect", Source = "Mask", }, }, },
1564 } }"#;
1565 if let (Some(out), Some(in_pt)) = (eval_px(vortex_src, "V0", 2, 2), eval_px(vortex_src, "V0", 32, 32)) {
1566 assert_eq!(out, [0, 0, 0, 0], "Vortex Angle=0 with MultiplyByMask must zero outside mask");
1567 assert!(in_pt[3].abs_diff(128) <= 2, "Vortex Angle=0 inside mask scales processed alpha by blend: {in_pt:?}");
1568 }
1569
1570 let kscope_src = r#"Composition { CurrentTime = 0, RenderRange = { 0, 0 }, GlobalRange = { 0, 0 }, Tools = ordered() {
1571 BG = Background { Inputs = { Width = Input { Value = 64, }, Height = Input { Value = 64, },
1572 TopLeftRed = Input { Value = 0.4, }, TopLeftGreen = Input { Value = 0.7, }, TopLeftAlpha = Input { Value = 1, }, }, },
1573 K0 = Fuse.KScope { Inputs = { Blend = Input { Value = 0, }, Input = Input { SourceOp = "BG", Source = "Output", }, }, },
1574 K1 = Fuse.KScope { Inputs = { Blend = Input { Value = 1, }, Slices = Input { Value = 6, }, Input = Input { SourceOp = "BG", Source = "Output", }, }, },
1575 } }"#;
1576 if let (Some(k0), Some(k1)) = (eval_px(kscope_src, "K0", 16, 16), eval_px(kscope_src, "K1", 16, 16)) {
1577 assert_eq!(k0, k1, "solid input with Blend=0 and Blend=1 should match identically");
1578 }
1579 }
1476}1580}
crates/engine/src/shaders/keyers_gen.wgsl+8-4
...@@ -395,12 +395,15 @@ fn plasma_circle_term(u_pos: vec2<f32>, aspect_inv: f32, c: vec4<f32>, master_sc...@@ -395,12 +395,15 @@ fn plasma_circle_term(u_pos: vec2<f32>, aspect_inv: f32, c: vec4<f32>, master_sc
395 let d = length(delta);395 let d = length(delta);
396 let s = max(master_scale * c.z, 1e-5);396 let s = max(master_scale * c.z, 1e-5);
397 if (ctype == 1) {397 if (ctype == 1) {
398 let lin = 39.269908 * d / s;398 let lin = 39.26990817 * d / s;
399 return select(lin, lin - 6.2831853 * floor(lin / 6.2831853), wrap);399 // Smooth the Type-1 cone tip at d = 0 with a tiny radial offset matching Fusion,
400 // preventing 1/t spikes in Divide mode without visibly shifting linear fringes.
401 let lin_r = sqrt(lin * lin + 0.001916 * 0.001916) - 0.001916;
402 return select(lin_r, lin_r - 6.2831853 * floor(lin_r / 6.2831853), wrap);
400 }403 }
401 let r0 = 0.0125 * s;404 let r0 = 0.0125 * s;
402 let dr = sqrt(d * d + r0 * r0) - r0;405 let dr = sqrt(d * d + r0 * r0) - r0;
403 return 2.208832 * (1.0 + sin(33.684 * dr / s));406 return 2.2089323 * (1.0 + sin(33.6842105 * dr / s));
404}407}
405408
406@compute @workgroup_size(8, 8)409@compute @workgroup_size(8, 8)
...@@ -449,7 +452,8 @@ fn plasma_op(@builtin(global_invocation_id) gid: vec3<u32>) {...@@ -449,7 +452,8 @@ fn plasma_op(@builtin(global_invocation_id) gid: vec3<u32>) {
449 }452 }
450 acc = acc / (t[i] / sc);453 acc = acc / (t[i] / sc);
451 }454 }
452 th = select(tau * acc, -tau * ph, bad);455 let res = tau * acc;
456 th = select(res, -tau * ph, bad || !(abs(res) < 205887.4));
453 }457 }
454 }458 }
455 case 4: { th = max(max(t[0], t[1]), max(t[2], t[3])); }459 case 4: { th = max(max(t[0], t[1]), max(t[2], t[3])); }
crates/engine/src/shaders/transform.wgsl+59-18
...@@ -426,21 +426,46 @@ fn homography_op(@builtin(global_invocation_id) gid: vec3<u32>) {...@@ -426,21 +426,46 @@ fn homography_op(@builtin(global_invocation_id) gid: vec3<u32>) {
426fn vortex_op(@builtin(global_invocation_id) gid: vec3<u32>) {426fn vortex_op(@builtin(global_invocation_id) gid: vec3<u32>) {
427 let dims = textureDimensions(dst_tex);427 let dims = textureDimensions(dst_tex);
428 if (gid.x >= dims.x || gid.y >= dims.y) { return; }428 if (gid.x >= dims.x || gid.y >= dims.y) { return; }
429 let p = vec2<i32>(gid.xy);
430 let orig = textureLoad(src_a, p, 0);
431 let blend = u.p[1].y;
432 let mbm = u.p[2].x > 0.5;
433 if (blend <= 0.0 && !mbm) {
434 store_dst(p, orig);
435 return;
436 }
437
438 let raw_mask = read_mask(gid.xy, dims, u.p[1].z, u.p[1].w);
439 let m = clamp(raw_mask * blend, 0.0, 1.0);
440 let skip = u.p[3] > vec4<f32>(0.5);
441 if (m <= 0.0) {
442 let res = select(orig, vec4<f32>(0.0), mbm);
443 let unproc = select(orig, orig * raw_mask, mbm);
444 store_dst(p, select(res, unproc, skip));
445 return;
446 }
447
448 let angle = u.p[0].w;
449 if (abs(angle) <= 1e-6) {
450 let res = select(orig, orig * m, mbm);
451 let unproc = select(orig, orig * raw_mask, mbm);
452 store_dst(p, select(res, unproc, skip));
453 return;
454 }
455
429 let aspect = f32(dims.x) / max(f32(dims.y), 1.0);456 let aspect = f32(dims.x) / max(f32(dims.y), 1.0);
430 let fu = pix_to_fu(gid.xy, dims);457 let fu = pix_to_fu(gid.xy, dims);
431 let center = u.p[0].xy;458 let center = u.p[0].xy;
432 let radius = max(u.p[0].z, 1e-5);459 let radius = max(u.p[0].z, 1e-5);
433 let angle = u.p[0].w;
434 let power = max(u.p[1].x, 0.0);460 let power = max(u.p[1].x, 0.0);
435 let blend = u.p[1].y;
436461
437 let orig = textureLoad(src_a, vec2<i32>(gid.xy), 0);
438 // Isotropic frame-width delta so swirls stay circular on 16:9 canvases462 // Isotropic frame-width delta so swirls stay circular on 16:9 canvases
439 let rel_w = (fu - center) * vec2<f32>(1.0, 1.0 / aspect);463 let rel_w = (fu - center) * vec2<f32>(1.0, 1.0 / aspect);
440 let r = length(rel_w);464 let r2 = dot(rel_w, rel_w);
441465
442 var warped = orig;466 var warped = orig;
443 if (r < radius && abs(angle) > 1e-6) {467 if (r2 < radius * radius) {
468 let r = sqrt(r2);
444 let t = pow(max(1.0 - r / radius, 0.0), power);469 let t = pow(max(1.0 - r / radius, 0.0), power);
445 let th = -angle * t;470 let th = -angle * t;
446 let c = cos(th);471 let c = cos(th);
...@@ -450,10 +475,9 @@ fn vortex_op(@builtin(global_invocation_id) gid: vec3<u32>) {...@@ -450,10 +475,9 @@ fn vortex_op(@builtin(global_invocation_id) gid: vec3<u32>) {
450 warped = sample_edges(src_a, src_fu, 2);475 warped = sample_edges(src_a, src_fu, 2);
451 }476 }
452477
453 let raw_mask = read_mask(gid.xy, dims, u.p[1].z, u.p[1].w);478 let res = select(mix(orig, warped, m), warped * m, mbm);
454 let res = mask_mix(orig, warped, raw_mask, blend, u.p[2].x > 0.5);479 let unproc = select(orig, orig * raw_mask, mbm);
455 let unproc = select(orig, orig * raw_mask, u.p[2].x > 0.5);480 store_dst(p, select(res, unproc, skip));
456 store_dst(vec2<i32>(gid.xy), select(res, unproc, u.p[3] > vec4<f32>(0.5)));
457}481}
458482
459483
...@@ -467,29 +491,46 @@ fn vortex_op(@builtin(global_invocation_id) gid: vec3<u32>) {...@@ -467,29 +491,46 @@ fn vortex_op(@builtin(global_invocation_id) gid: vec3<u32>) {
467fn kscope_op(@builtin(global_invocation_id) gid: vec3<u32>) {491fn kscope_op(@builtin(global_invocation_id) gid: vec3<u32>) {
468 let dims = textureDimensions(dst_tex);492 let dims = textureDimensions(dst_tex);
469 if (gid.x >= dims.x || gid.y >= dims.y) { return; }493 if (gid.x >= dims.x || gid.y >= dims.y) { return; }
494 let p = vec2<i32>(gid.xy);
495 let blend = u.p[1].w;
496 if (blend <= 0.0) {
497 store_dst(p, textureLoad(src_a, p, 0));
498 return;
499 }
500
501 let m = clamp(read_mask(gid.xy, dims, u.p[2].x, u.p[2].y) * blend, 0.0, 1.0);
502 if (m <= 0.0) {
503 store_dst(p, textureLoad(src_a, p, 0));
504 return;
505 }
506
470 let aspect = f32(dims.x) / max(f32(dims.y), 1.0);507 let aspect = f32(dims.x) / max(f32(dims.y), 1.0);
508 let inv_aspect = 1.0 / aspect;
471 let fu = pix_to_fu(gid.xy, dims);509 let fu = pix_to_fu(gid.xy, dims);
472 let center = u.p[0].xy;510 let center = u.p[0].xy;
473 let slices = max(u.p[0].z, 1.0);511 let slices = max(u.p[0].z, 1.0);
474 let angle = u.p[0].w;512 let angle = u.p[0].w;
475 let cap_angle = u.p[1].x;513 let cap_angle = u.p[1].x;
476 let scale = max(u.p[1].y, 1e-4);514 let inv_scale = 1.0 / max(u.p[1].y, 1e-4);
477 let edges = i32(u.p[1].z + 0.5);515 let edges = i32(u.p[1].z + 0.5);
478 let blend = u.p[1].w;
479516
480 let orig = textureLoad(src_a, vec2<i32>(gid.xy), 0);
481 let rel = (fu - center) * vec2<f32>(aspect, 1.0);517 let rel = (fu - center) * vec2<f32>(aspect, 1.0);
482 let r = length(rel) / scale;518 let r = length(rel) * inv_scale;
483 let sector = 6.28318530718 / slices;519 let sector = 6.28318530718 / slices;
520 let two_sector = 2.0 * sector;
484 var th = atan2(rel.y, rel.x) - angle;521 var th = atan2(rel.y, rel.x) - angle;
485 th = th - floor(th / (2.0 * sector)) * (2.0 * sector);522 th = th - floor(th / two_sector) * two_sector;
486 if (th > sector) {523 if (th > sector) {
487 th = 2.0 * sector - th;524 th = two_sector - th;
488 }525 }
489 th = th + cap_angle;526 th = th + cap_angle;
490 let src_fu = center + vec2<f32>(cos(th) * r / aspect, sin(th) * r);527 let src_fu = center + vec2<f32>(cos(th) * r * inv_aspect, sin(th) * r);
491 let kcol = sample_edges(src_a, src_fu, edges);528 let kcol = sample_edges(src_a, src_fu, edges);
492529
493 let m = read_mask(gid.xy, dims, u.p[2].x, u.p[2].y) * blend;530 if (m >= 1.0) {
494 store_dst(vec2<i32>(gid.xy), mix(orig, kcol, clamp(m, 0.0, 1.0)));531 store_dst(p, kcol);
532 return;
533 }
534 let orig = textureLoad(src_a, p, 0);
535 store_dst(p, mix(orig, kcol, m));
495}536}