Files
rose-ash/artdag/l1/sexp_effects/effects/xector_feathered_blend.sexp
giles 1a74d811f7
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 2m33s
Incorporate art-dag-mono repo into artdag/ subfolder
Merges full history from art-dag/mono.git into the monorepo
under the artdag/ directory. Contains: core (DAG engine),
l1 (Celery rendering server), l2 (ActivityPub registry),
common (shared templates/middleware), client (CLI), test (e2e).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

git-subtree-dir: artdag
git-subtree-mainline: 1a179de547
git-subtree-split: 4c2e716558
2026-02-27 09:07:23 +00:00

45 lines
1.8 KiB
Common Lisp
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
;; Feathered blend - blend two same-size frames with distance-based falloff
;; Center shows overlay, edges show background, with smooth transition
(require-primitives "xector")
(define-effect xector_feathered_blend
:params (
(inner-radius :type float :default 0.3 :range [0 1] :desc "Radius where overlay is 100% (fraction of size)")
(fade-width :type float :default 0.2 :range [0 0.5] :desc "Width of fade region (fraction of size)")
(overlay :type frame :default nil :desc "Frame to blend in center")
)
(let* (
;; Get normalized distance from center (0 at center, ~1 at corners)
(dist (dist-from-center frame))
(max-dist (βmax dist))
(dist-norm (α/ dist max-dist))
;; Calculate blend factor:
;; - 1.0 when dist-norm < inner-radius (fully overlay)
;; - 0.0 when dist-norm > inner-radius + fade-width (fully background)
;; - linear ramp between
(t (α/ (α- dist-norm inner-radius) fade-width))
(blend (α- 1 (αclamp t 0 1)))
(inv-blend (α- 1 blend))
;; Background channels
(bg-r (red frame))
(bg-g (green frame))
(bg-b (blue frame)))
(if (nil? overlay)
;; No overlay - visualize the blend mask
(let ((vis (α* blend 255)))
(rgb vis vis vis))
;; Blend overlay with background using the mask
(let* ((ov-r (red overlay))
(ov-g (green overlay))
(ov-b (blue overlay))
;; lerp: bg * (1-blend) + overlay * blend
(r-out (α+ (α* bg-r inv-blend) (α* ov-r blend)))
(g-out (α+ (α* bg-g inv-blend) (α* ov-g blend)))
(b-out (α+ (α* bg-b inv-blend) (α* ov-b blend))))
(rgb r-out g-out b-out)))))