LYGIA Shader Library

sprite (lygia/space/sprite)

returns a coordinate of a sprite cell

Use:

<vec2> sprite(<vec2> st, <vec2> grid, <float> index)

Check it on Github


#ifndef FNC_SPRITE
#define FNC_SPRITE

vec2 sprite(vec2 st, vec2 grid, float index) {
    index += grid.x; 
    vec2 f = 1.0/grid;
    vec2 cell = vec2(floor(index), grid.y - floor(index * f.x) );
    // cell.y = grid.y - cell.y;
    return fract( (st+cell)*f );
}

#endif

Use:

<float2> sprite(<float2> st, <float2> grid, <float> index)

Check it on Github


#ifndef FNC_SPRITE
#define FNC_SPRITE

float2 sprite(float2 st, float2 grid, float index) {
    float2 f = 1.0/grid;
    float2 cell = float2(floor(index), floor(index * f.x) );
    cell.y = grid.y - cell.y;
    return frac( (st+cell)*f );
}

#endif

Use:

<float2> sprite(<float2> st, <float2> grid, <float> index)

Check it on Github


#ifndef FNC_SPRITE
#define FNC_SPRITE

float2 sprite(float2 st, float2 grid, float index) {
    index += grid.x; 
    float2 f = 1.0/grid;
    float2 cell = float2(floor(index), grid.y - floor(index * f.x) );
    // cell.y = grid.y - cell.y;
    return fract( (st+cell)*f );
}

#endif

Licenses

LYGIA is dual-licensed under the Prosperity License and the Patron License for sponsors and contributors.

Sponsors and contributors are automatically added to the Patron License and they can ignore the any non-commercial rule of the Prosperity Licensed software (please take a look to the exception).

It's also possible to get a permanent comercial license hook to a single and specific version of LYGIA.

Get the latest news and releases

Sign up for the news letter bellow, joing the LYGIA's channel on Discord or follow the Github repository