Skip to content
This repository has been archived by the owner on May 5, 2018. It is now read-only.

natmlx/Compositor-API

Repository files navigation

Compositor API

Compositor

Compositor is a lightweight utility API for compositing images quickly and efficiently in Unity. Download the unitypackage here.

ICompositor

Compositor treats images as layers. First, you create a compositor:

ICompositor compositor = new RenderCompositor();

Then you add layers:

// Add a layer with no offset, no rotation, and default size (1, 1)
compositor.AddLayer(new Layer(texture1, Vector2.zero, 0f, Vector2.one));
// Add a layer with an offset
compositor.AddLayer(new Layer(texture1, new Point(40, 70), 0f, Vector2.one));
// Add a layer, but free the layer texture immediately it has been composited
compositor.AddLayer(new Layer(texture1, Vector2.zero, 0f, Vector2.one, Layer.Release));
// Add a layer, and execute a callback once the layer has been composited // This is useful for texture resource management
compositor.AddLayer(new Layer(texture1, Vector2.zero, 0f, Vector2.one, layerTexture => OnCompositeLayer(layerTexture)));

Then composite, providing a callback to be invoked with the resulting texture:

compositor.Composite(OnComposite);

void OnComposite (Texture2D result) {
    // Display it on a material
    material.mainTexture = result;
}

Finally, release the compositor's resources:

compositor.Dispose();

Compositors implement the IDisposable interface, so you can use it in a using block:

using (var compositor = new RenderCompositor()) {
    // Add layers...
    compositor.Composite(OnComposite);
} // The compositor is automatically freed at the end of this block

Credits

About

Compositor is a lightweight utility API for compositing images quickly and efficiently in Unity.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published