← Back

ofxCompositorKit

github.com/ofxyz/ofxCompositorKit · @ofxyz
OF 0.12 Graphics Utilities

ECS layer compositor

0 0 Last commit 2mo ago Created 2mo ago

README

ofxCompositorKit



FBO layer masks, nested bake groups, and SVG/CSS blend modes for the ofKitty stack.

example

CompositorSystem is a drop-in replacement for ofkitty::drawLayerContents(): it walks the same layer tree (layer_component roots, Relationship sibling order). Layers with a composite_pass_component render into an FBO and blit with ecs::BlendMode (SVG/CSS mix-blend-mode plus OF extras).

Nested composite passes recurse (each pass begins/ends its own FBOs). Use ecs::markCompositePassDirty(reg, entity) so ancestor passes rebuild when a child or mask changes.

Usage



#include "ofxCompositorKit.h"

ofxCompositorKit::CompositorKit m_compositorKit;

void ofApp::setup() {
    m_compositorKit.registerWith(ofkitty::runtime());
    m_compositorKit.system().setCanvasSize(1000, 1000);

    // Masked layer:
    reg.emplace<ecs::composite_pass_component>(layerEntity,
        ecs::composite_pass_component{
            .maskSource = ecs::MaskSource::PathEntity,
            .maskEntity = circleEntity,
            .blendMode  = ecs::BlendMode::Normal,
            .dirty      = true,
        });

    // Baked group (isolate children, Multiply onto parent):
    reg.emplace<ecs::composite_pass_component>(groupEntity,
        ecs::composite_pass_component{
            .maskSource = ecs::MaskSource::None,
            .blendMode  = ecs::BlendMode::Multiply,
            .dirty      = true,
        });
}

void ofApp::draw() {
    ofkitty::runtime().drawSystems(); // canvas-phase systems
}


registerWith() registers CompositorSystem with drawPhase = "canvas". Disable with system().setEnabled(false).

Mask sources



MaskSourceBehaviour
NoneBake children; blit color with blendMode only (layer group)
PathEntitymaskEntity drawn alone; rendered alpha is the mask
SubtreeAlphamaskEntity + Relationship descendants; accumulated alpha
PaintedFbomaskEntity’s fbo_component (or valid fbo_reference) texture
Keep path mask entities un-parented so the normal layer traversal never
draws them. Give path masks a fill paint — geometry alone draws nothing.

Helpers in LayerMaskOps.h: setPathLayerMask, clearLayerMask, hasPathLayerMask, findLayerForMask, markAllCompositePassesDirty.

Editors that hide paths while editing can call system().setSkipEntity(...) so color bake matches drawLayerContents.

Blend modes



composite_pass_component::blendMode uses ecs::BlendMode. Blitting samples a backdrop copy of the current framebuffer so non-separable modes (Overlay, Hue, …) match Compositing and Blending Level 1.

SVG / CSS mix-blend-mode (16):

EnumString
Normalnormal
Multiplymultiply
Screenscreen
Overlayoverlay
Darkendarken
Lightenlighten
ColorDodgecolor-dodge
ColorBurncolor-burn
HardLighthard-light
SoftLightsoft-light
Differencedifference
Exclusionexclusion
Huehue
Saturationsaturation
Colorcolor
Luminosityluminosity
And openFrameworks extras:

EnumString
Addadd
Subtractsubtract
Disableddisabled
Helpers: ecs::blendModeToString / ecs::blendModeFromString

Dependencies



Get this addon

HTTPS
SSH