LYGIA Shader Library

1D (lygia/filter/boxBlur/1D)

Simple one dimentional box blur, to be applied in two passes

Dependencies:

Use:

boxBlur1D(<SAMPLER_TYPE> texture, <vec2> st, <vec2> pixel_offset, <int> kernelSize)

Check it on Github



#ifndef BOXBLUR1D_TYPE
#ifdef BOXBLUR_TYPE
#define BOXBLUR1D_TYPE BOXBLUR_TYPE
#else
#define BOXBLUR1D_TYPE vec4
#endif
#endif

#ifndef BOXBLUR1D_SAMPLER_FNC
#ifdef BOXBLUR_SAMPLER_FNC
#define BOXBLUR1D_SAMPLER_FNC(TEX, UV) BOXBLUR_SAMPLER_FNC(TEX, UV)
#else
#define BOXBLUR1D_SAMPLER_FNC(TEX, UV) SAMPLER_FNC(TEX, UV)
#endif
#endif

#ifndef FNC_BOXBLUR1D
#define FNC_BOXBLUR1D
BOXBLUR1D_TYPE boxBlur1D(in SAMPLER_TYPE tex, in vec2 st, in vec2 offset, const int kernelSize) {
    BOXBLUR1D_TYPE color = BOXBLUR1D_TYPE(0.);

    #ifndef BOXBLUR1D_KERNELSIZE

    #if defined(PLATFORM_WEBGL)
    #define BOXBLUR1D_KERNELSIZE 20
    float kernelSizef = float(kernelSize);
    #else
    #define BOXBLUR1D_KERNELSIZE kernelSize
    float kernelSizef = float(BOXBLUR1D_KERNELSIZE);
    #endif

    #else
    float kernelSizef = float(BOXBLUR1D_KERNELSIZE);
    #endif

    float weight = 1. / kernelSizef;
    for (int i = 0; i < BOXBLUR1D_KERNELSIZE; i++) {
        #if defined(PLATFORM_WEBGL)
        if (i >= kernelSize)
            break;
        #endif
        float x = -.5 * (kernelSizef - 1.) + float(i);
        color += BOXBLUR1D_SAMPLER_FNC(tex, st + offset * x ) * weight;
    }
    return color;
}
#endif

Dependencies:

Use:

boxBlur1D(<SAMPLER_TYPE> texture, <float2> st, <float2> pixel_offset, <int> kernelSize)

Check it on Github



#ifndef BOXBLUR1D_TYPE
#ifdef BOXBLUR_TYPE
#define BOXBLUR1D_TYPE BOXBLUR_TYPE
#else
#define BOXBLUR1D_TYPE float4
#endif
#endif

#ifndef BOXBLUR1D_SAMPLER_FNC
#ifdef BOXBLUR_SAMPLER_FNC
#define BOXBLUR1D_SAMPLER_FNC(TEX, UV) BOXBLUR_SAMPLER_FNC(TEX, UV)
#else
#define BOXBLUR1D_SAMPLER_FNC(TEX, UV) SAMPLER_FNC(TEX, UV)
#endif
#endif

#ifndef FNC_BOXBLUR1D
#define FNC_BOXBLUR1D
BOXBLUR1D_TYPE boxBlur1D(in SAMPLER_TYPE tex, in float2 st, in float2 offset, const int kernelSize) {
    BOXBLUR1D_TYPE color = float4(0.0, 0.0, 0.0, 0.0);
    #ifndef BOXBLUR1D_KERNELSIZE
    #define BOXBLUR1D_KERNELSIZE kernelSize
    #endif

    float f_kernelSize = float(BOXBLUR1D_KERNELSIZE);
    float weight = 1. / f_kernelSize;

    for (int i = 0; i < BOXBLUR1D_KERNELSIZE; i++) {
        float x = -.5 * (f_kernelSize - 1.) + float(i);
        color += BOXBLUR1D_SAMPLER_FNC(tex, st + offset * x ) * weight;
    }
    return color;
}
#endif

Dependencies:

Use:

boxBlur1D(<SAMPLER_TYPE> texture, <float2> st, <float2> pixel_offset, <int> kernelSize)

Check it on Github



#ifndef BOXBLUR1D_TYPE
#ifdef BOXBLUR_TYPE
#define BOXBLUR1D_TYPE BOXBLUR_TYPE
#else
#define BOXBLUR1D_TYPE float4
#endif
#endif

#ifndef BOXBLUR1D_SAMPLER_FNC
#ifdef BOXBLUR_SAMPLER_FNC
#define BOXBLUR1D_SAMPLER_FNC(TEX, UV) BOXBLUR_SAMPLER_FNC(TEX, UV)
#else
#define BOXBLUR1D_SAMPLER_FNC(TEX, UV) SAMPLER_FNC(TEX, UV)
#endif
#endif

#ifndef FNC_BOXBLUR1D
#define FNC_BOXBLUR1D
BOXBLUR1D_TYPE boxBlur1D(SAMPLER_TYPE tex, float2 st, float2 offset, const int kernelSize) {
    BOXBLUR1D_TYPE color = BOXBLUR1D_TYPE(0.);

    #ifndef BOXBLUR1D_KERNELSIZE

    #if defined(PLATFORM_WEBGL)
    #define BOXBLUR1D_KERNELSIZE 20
    float kernelSizef = float(kernelSize);
    #else
    #define BOXBLUR1D_KERNELSIZE kernelSize
    float kernelSizef = float(BOXBLUR1D_KERNELSIZE);
    #endif

    #else
    float kernelSizef = float(BOXBLUR1D_KERNELSIZE);
    #endif

    float weight = 1. / kernelSizef;
    for (int i = 0; i < BOXBLUR1D_KERNELSIZE; i++) {
        #if defined(PLATFORM_WEBGL)
        if (i >= kernelSize)
            break;
        #endif
        float x = -.5 * (kernelSizef - 1.) + float(i);
        color += BOXBLUR1D_SAMPLER_FNC(tex, st + offset * x ) * weight;
    }
    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