LYGIA Shader Library

fibonacciBokeh (lygia/filter/fibonacciBokeh)

Fibonacci Bokeh inspired on Xor's https://www.shadertoy.com/view/fljyWd

Dependencies:

Use:

<vec4> fibonacciBokeh(<SAMPLER_TYPE> tex, <vec2> st, <vec2> pixel, <float> amount)

Check it on Github



#ifndef FIBONACCIBOKEH_TYPE
#define FIBONACCIBOKEH_TYPE vec4
#endif

#ifndef FIBONACCIBOKEH_MAXSAMPLES
#define FIBONACCIBOKEH_MAXSAMPLES 100
#endif

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

#ifndef FNC_FIBONACCIBOKEH
#define FNC_FIBONACCIBOKEH

FIBONACCIBOKEH_TYPE fibonacciBokeh(SAMPLER_TYPE tex, vec2 st, vec2 pixel, float amount) {
    FIBONACCIBOKEH_TYPE color = FIBONACCIBOKEH_TYPE(0.0);
    const mat2 m = mat2(-0.737, -0.676, 0.676, -0.737) ;

    vec2 r = 1.0/pixel;
    vec2 uv = st * r;
    float f = 1.0 / (1.001 - amount);

    vec2 st2 = vec2( dot(uv + uv - r, vec2(.0002,-0.001)), 0.0 );

    float counter = 0.0;
    float s = 1.0;
    for (int i = 0; i < FIBONACCIBOKEH_MAXSAMPLES; i++) {
        s += 1.0/s;
        if (s >= 16.0)
            break;
        st2 *= m;
        color += gamma2linear( FIBONACCIBOKEH_SAMPLER_FNC(tex, st + st2 * s * pixel ) * f);
        counter++;
    }
    return linear2gamma(color / counter);
}

#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