feat(blur): a privacy blur layer for the Live scene — boxes and circles over the desktop

Creator request 2026-11-01: a layer that hides part of the desktop from viewers. Box or circle,
drag/resize like any layer, one strength slider, several allowed.

**Z-order is policy, not preference.** `AddSource` inserts a blur directly above the background
and therefore below the brand logo, and `OnSceneElementsReordered` pushes any blur that ends up
above the brand back down. Nothing else in the app can move it into the brand's way.

**Overlap = the strongest single blur, never a stack.** `SceneCompositor.ApplyBlurLayers` collects
every visible blur the first time one is reached in the z-order, sorts them strongest-first, and
shares one coverage map: a pixel already covered by a stronger blur is skipped. Blurring
back-to-front would have produced something stronger than any slider setting allows, which is
exactly what was ruled out.

**One blur curve, shared with the webcam.** `RegionBlur` carries the constants the webcam blur
already used — downscale 4, radius 1–6 downscaled px, `RadiusFor(strength)` — and
`BackgroundEffectProcessor` now delegates to it instead of holding its own copy. The layer's
slider is the same 0–1 scale with the same 0.5 default, so "half strength" means the same blur in
both features. Cost is proportional to the blur's own rect, not the frame.

**Live scene only**, enforced in `AddSource` as well as the (+) menu (`CanAddBlur`), so a stale
menu item or a scripted call cannot plant one on BRB. `ElementKind.Dynamic`, so it is never baked
into the static base and every render path gets it — pump, preview, thumbnails, scene dump.

Persistence: `Source.BlurAmount` column + migration; shape rides the existing `ClipShape`.
Properties panel: Box | Circle plus the strength slider, gated on `IsBlurSelected`.

4 tests: outside the mask is byte-identical, inside loses its hard edges, a circle leaves its
box corners alone, and two identical stacked blurs equal one (the coverage map). Release builds
at 0 warnings.
This commit is contained in:
2026-11-01 09:55:04 -08:00
parent 2e12c5651e
commit 71d0e87cac
14 changed files with 534 additions and 23 deletions
+54
View File
@@ -174,10 +174,26 @@ public sealed class SceneCompositor
}
// Composite the above-split layers (dynamic + any static above them) per frame.
var blurApplied = false;
for (var i = Math.Max(0, split); i < scene.Elements.Count; i++)
{
var element = scene.Elements[i];
if (!element.IsVisible) continue;
// Privacy blurs are handled as ONE group the first time one is reached: overlapping
// boxes must resolve to the strongest single blur, never to a blurred blur. The group
// runs at the lowest blur's z-position, which is where the creator put it — directly
// above the background and below the brand logo.
if (element is Source { Type: SourceType.Blur })
{
if (!blurApplied)
{
blurApplied = true;
ApplyBlurLayers(scene, buffer, cropW, cropH, options, timings);
}
continue;
}
switch (element)
{
case Source { IsBackground: true }:
@@ -377,6 +393,44 @@ public sealed class SceneCompositor
return scaled;
}
/// <summary>
/// Apply every visible privacy blur to the composed-so-far buffer, strongest first, skipping
/// pixels a stronger blur already covered. That ordering is what makes an overlap read as "the
/// strongest one wins": blurring back-to-front would stack passes and produce something
/// stronger than any single slider allows, which the creator ruled out.
/// </summary>
private static void ApplyBlurLayers(
Scene scene, byte[] buffer, int cropW, int cropH, CompositorOptions options, CompositeTimings? timings)
{
var blurs = scene.Elements.OfType<Source>()
.Where(s => s.Type == SourceType.Blur && s.IsVisible && s.Width > 0 && s.Height > 0)
.OrderByDescending(s => s.BlurAmount)
.ToArray();
if (blurs.Length == 0) return;
var tBlur = System.Diagnostics.Stopwatch.GetTimestamp();
var coverage = System.Buffers.ArrayPool<byte>.Shared.Rent(cropW * cropH);
try
{
Array.Clear(coverage, 0, cropW * cropH);
var stride = cropW * 4;
foreach (var blur in blurs)
{
var x = (int)Math.Round(blur.X - options.SourceRectX);
var y = (int)Math.Round(blur.Y - options.SourceRectY);
RegionBlur.ApplyInPlace(
buffer, stride, cropW, cropH,
x, y, (int)Math.Round(blur.Width), (int)Math.Round(blur.Height),
blur.BlurAmount, blur.ClipShape == ClipShape.Round, coverage);
}
}
finally
{
System.Buffers.ArrayPool<byte>.Shared.Return(coverage);
}
timings?.Add("blur", System.Diagnostics.Stopwatch.GetTimestamp() - tBlur);
}
private static void BlitBakedElement(
byte[] buffer, int cropW, int cropH, CompositorOptions options, SceneElement element, VideoFrame frame,
CompositeTimings? timings, string stage)