Circle Image

Pixaflux

Sprite It - Sprite Context

The Sprite Context defines how the sprites are rendered to the final image.

Output

A Sprite It program can output multiple images, or one material that packs all images.

Images

The images table defines the images that will be rendered by the Sprite It node.

The channels dictionary defines the channels of the images.

The values table defines the values of the channels.

These 3 structures need to be consistent to allow the Sprite It node to correctly add the image outputs to the node, and render the sprites.

Opacity

Images with 1 channel are value images. Images with 4 channels are rgbo images.

Adding an opacity image with one channel modifies the rendering of monochromatic images to blending with opacity.

Each sprite has a values table that must match the number of values defined in the sprite context.

Examples

One value output

-- Sets output type as images.
spriteContext.output = "images"

-- One output: image
spriteContext.images = {"image"}

-- Output image has one channel. Item 1 in the values table.
spriteContext.channels = {image = {1}}

-- The output background values.
spriteContext.values = {0.0}

Two value outputs

-- Sets output type as images.
spriteContext.output = "images"

-- Two outputs: metalness and roughness
spriteContext.images = {"metalness", "roughness"}

-- Output metalness has one channel: Item 1 in the values table. 
-- Output roughness has one channel: Item 2 in the values table.
spriteContext.channels = {metalness = {1}, roughness = {2}}

-- The output background values.
spriteContext.values = {0.0, 0.0}

One value output and one rgbo output

-- Sets output type as images.
spriteContext.output = "images"

-- Two outputs: roughness and albedo
spriteContext.images = {"roughness", "albedo"}

-- Output roughness has one channel: Item 1 in the values table.
-- Output albedo has four channel: Items 2, 3, 4 and 5 in the values table.
spriteContext.channels = {roughness = {1}, albedo = {2, 3, 4, 5}}

-- The output background values.
spriteContext.values = {0.0, 0.0, 0.0, 0.0, 0.0}

With opacity channel

To share an opacity channel between all images, add an opacity entry to the channels table with one item in the values table. This opacity will be used to compose color and monochromatic images. The final opacity channel will be added to all rgbo images.

-- Sets output type as images.
spriteContext.output = "images"

-- Three outputs: albedo, roughness and height
spriteContext.images = {"albedo", "roughness", "height"}

-- Opacity is a shared channel.
-- Output albedo has four channels: Items 1, 2, 3 and opacity (6)
-- Output roughness has one channel: Item 4 in the values table.
-- Output height has one channel: Item 5 in the values table.
-- Output opacity will be added to the albedo image.
spriteContext.channels = { albedo = {1, 2, 3}, roughness = {4}, height = {5}, 
                           opacity = {6} }

-- The output background values.
spriteContext.values = {0.618, 0.500, 0.454, 0.500, 0.005, 0.500}

Material

Setting output to material adds one material input and output to the Sprite It node.

In this case the shape is restricted to image and mask, and the input material defines the output material and how it's rendered.

In material mode the node renderer uses a height based blending mode.

Layering

The sprites are sorted by level and layer. Lower levels and layers are render first, higher last:

Sprites on the same layer are shuffled to avoid patterns.

Depth Fade

The intensity of the levels is controlled with the depthFade and balance properties. The intensity multiplies the value of monochromatic sprites, and the opacity of rgbo sprites.

depthFade. sets the function used to compute the intensity:

balance. sets the coefficients used in the depth fade function. Positive values make higher levels more intense. Negative values make lower levels more intense. Zero makes all levels have the same intensity: 1.0 / levels.

Sample Script: Levels and Layers script.

Linear Neg Linear Neg Linear Neg Linear Depth Fade

Linear Neg Linear Neg Linear Neg Exponential Depth Fade

Seamless

If seamless is true, before rendering, the sprites crossing and outside the image are are duplicated as many times as needed to make them look continuous when the image is applied as a tileable texture.

Node Attributes

Image Position and Size

The image position and size can be accessed in the Lua script with four functions:

positionX = spriteIt.getPositionX()
positionY = spriteIt.getPositionY()
sizeX = spriteIt.getSizeX()
sizeY = spriteIt.getSizeY()

Seed

The Lua math module includes a set of random functions that are fed by a common random seed. The random seed is set in the Sprite It node, and accessed in Lua by the

-- Gets the seed from the PixaFlux node
seed = spriteIt.getSeed()

-- Initializes the random generator with the seed
math.randomseed(seed)

-- Get a new random value from 0.0 to 1.0
value = math.random()