LYGIA Shader Library

quilt (lygia/sample/quilt)

convertes QUILT of tiles into something the LookingGlass Volumetric display can render

Dependencies:

Use:

sampleQuilt(<SAMPLER_TYPE> texture, <vec4> calibration, <vec3> tile, <vec2> st, <vec2> resolution)

Check it on Github



#ifndef SAMPLEQUILT_SAMPLER_FNC
#define SAMPLEQUILT_SAMPLER_FNC(TEX, UV) SAMPLER_FNC(TEX, UV)
#endif

#ifndef FNC_SAMPLEQUILT
#define FNC_SAMPLEQUILT
vec2 mapQuilt(vec3 tile, vec2 pos, float a) {
    vec2 tile2 = tile.xy - 1.0;
    vec2 dir = vec2(-1.0);

    a = fract(a) * tile.y;
    tile2.y += dir.y * floor(a);
    a = fract(a) * tile.x;
    tile2.x += dir.x * floor(a);
    return (tile2 + pos) / tile.xy;
}

vec3 sampleQuilt(SAMPLER_TYPE tex, vec4 calibration, vec3 tile, vec2 st, vec2 resolution) {
    float pitch = -resolution.x / calibration.x  * calibration.y * sin(atan(abs(calibration.z)));
    float tilt = resolution.y / (resolution.x * calibration.z);
    float subp = 1.0 / (3.0 * resolution.x);
    float subp2 = subp * pitch;

    float a = (-st.x - st.y * tilt) * pitch - calibration.w;

    vec3 color = vec3(0.0);
    #ifdef SAMPLEQUILT_FLIPSUBP
    color.r = SAMPLEQUILT_SAMPLER_FNC(tex, mapQuilt(tile, st, a-2.0*subp2) ).r;
    color.g = SAMPLEQUILT_SAMPLER_FNC(tex, mapQuilt(tile, st, a-subp2) ).g;
    color.b = SAMPLEQUILT_SAMPLER_FNC(tex, mapQuilt(tile, st, a) ).b;
    #else
    color.r = SAMPLEQUILT_SAMPLER_FNC(tex, mapQuilt(tile, st, a) ).r;
    color.g = SAMPLEQUILT_SAMPLER_FNC(tex, mapQuilt(tile, st, a-subp2) ).g;
    color.b = SAMPLEQUILT_SAMPLER_FNC(tex, mapQuilt(tile, st, a-2.0*subp2) ).b;
    #endif
    return color;
}
#endif

Dependencies:

Use:

sampleQuilt(<SAMPLER_TYPE> texture, <float4> calibration, <float3> tile, <float2> st, <float2> resolution)

Check it on Github



#ifndef SAMPLEQUILT_SAMPLER_FNC
#define SAMPLEQUILT_SAMPLER_FNC(UV) SAMPLER_FNC(tex, UV)
#endif

#ifndef FNC_QUILT
#define FNC_QUILT
float2 mapQuilt(float3 tile, float2 pos, float a) {
    float2 tile2 = tile.xy - 1.0;
    float2 dir = float2(-1.0, -1.0);

    a = frac(a) * tile.y;
    tile2.y += dir.y * floor(a);
    a = frac(a) * tile.x;
    tile2.x += dir.x * floor(a);
    return (tile2 + pos) / tile.xy;
}

float3 sampleQuilt(SAMPLER_TYPE tex, float4 calibration, float3 tile, float2 st, float2 resolution) {
    float pitch = -resolution.x / calibration.x  * calibration.y * sin(atan(abs(calibration.z)));
    float tilt = resolution.y / (resolution.x * calibration.z);
    float subp = 1.0 / (3.0 * resolution.x);
    float subp2 = subp * pitch;

    float a = (-st.x - st.y * tilt) * pitch - calibration.w;

    float3 color = float3(0.0, 0.0, 0.0);
    #ifdef SAMPLEQUILT_FLIPSUBP
    color.r = SAMPLEQUILT_SAMPLER_FNC( mapQuilt(tile, st, a-2.0*subp2) ).r;
    color.g = SAMPLEQUILT_SAMPLER_FNC( mapQuilt(tile, st, a-subp2) ).g;
    color.b = SAMPLEQUILT_SAMPLER_FNC( mapQuilt(tile, st, a) ).b;
    #else
    color.r = SAMPLEQUILT_SAMPLER_FNC( mapQuilt(tile, st, a) ).r;
    color.g = SAMPLEQUILT_SAMPLER_FNC( mapQuilt(tile, st, a-subp2) ).g;
    color.b = SAMPLEQUILT_SAMPLER_FNC( mapQuilt(tile, st, a-2.0*subp2) ).b;
    #endif
    return color;
}
#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