LYGIA Shader Library

radialBlur (lygia/filter/radialBlur)

Make a radial blur, with dir as the direction to the center and strength as the amount

Dependencies:

Use:

radialBlur(<SAMPLER_TYPE> texture, <vec2> st, <vec2> dir [, <float> strength])

Check it on Github



#ifndef RADIALBLUR_KERNELSIZE
#define RADIALBLUR_KERNELSIZE 64
#endif

#ifndef RADIALBLUR_STRENGTH
#define RADIALBLUR_STRENGTH .125
#endif

#ifndef RADIALBLUR_TYPE
#define RADIALBLUR_TYPE vec4
#endif

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

#ifndef FNC_RADIALBLUR
#define FNC_RADIALBLUR
RADIALBLUR_TYPE radialBlur(in SAMPLER_TYPE tex, in vec2 st, in vec2 dir, in float strength) {
    RADIALBLUR_TYPE color = RADIALBLUR_TYPE(0.);
    float f_samples = float(RADIALBLUR_KERNELSIZE);
    float f_factor = 1./f_samples;
    for (int i = 0; i < RADIALBLUR_KERNELSIZE; i += 2) {
        color += RADIALBLUR_SAMPLER_FNC(tex, st + float(i) * f_factor * dir * strength);
        color += RADIALBLUR_SAMPLER_FNC(tex, st + float(i+1) * f_factor * dir * strength);
    }
    return color * f_factor;
}

RADIALBLUR_TYPE radialBlur(in SAMPLER_TYPE tex, in vec2 st, in vec2 dir) {
    return radialBlur(tex, st, dir, RADIALBLUR_STRENGTH);
}
#endif

Dependencies:

Use:

radialBlur(<SAMPLER_TYPE> texture, <float2> st, <float2> dir [, <float> strength])

Check it on Github



#ifndef RADIALBLUR_KERNELSIZE
#define RADIALBLUR_KERNELSIZE 64
#endif

#ifndef RADIALBLUR_STRENGTH
#define RADIALBLUR_STRENGTH .125
#endif

#ifndef RADIALBLUR_TYPE
#define RADIALBLUR_TYPE float4
#endif

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

#ifndef FNC_RADIALBLUR
#define FNC_RADIALBLUR
RADIALBLUR_TYPE radialBlur(in SAMPLER_TYPE tex, in float2 st, in float2 dir, in float strength) {
    RADIALBLUR_TYPE color = float4(0.0, 0.0, 0.0, 0.0);
    float f_samples = float(RADIALBLUR_KERNELSIZE);
    float f_factor = 1./f_samples;
    for (int i = 0; i < RADIALBLUR_KERNELSIZE; i += 2) {
        color += RADIALBLUR_SAMPLER_FNC(tex, st + float(i) * f_factor * dir * strength);
        color += RADIALBLUR_SAMPLER_FNC(tex, st + float(i+1) * f_factor * dir * strength);
    }
    return color * f_factor;
}

RADIALBLUR_TYPE radialBlur(in SAMPLER_TYPE tex, in float2 st, in float2 dir) {
    return radialBlur(tex, st, dir, RADIALBLUR_STRENGTH);
}
#endif

Examples

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