LYGIA Shader Library

nyquist (lygia/math/nyquist)

A simple low-pass filter which attenuates high-frequencies.

Use:

nyquist(<float> value, <float> width, <float> strength)

Check it on Github


#ifndef FNC_NYQUIST
#define FNC_NYQUIST

#ifndef NYQUIST_FILTER_CENTER
#define NYQUIST_FILTER_CENTER 0.5
#endif

#ifndef NYQUIST_FILTER_WIDTH
#define NYQUIST_FILTER_WIDTH 0.25
#endif

float nyquist(float x, float width){
    float cutoffStart = NYQUIST_FILTER_CENTER - NYQUIST_FILTER_WIDTH;
    float cutoffEnd = NYQUIST_FILTER_CENTER + NYQUIST_FILTER_WIDTH;
    float f = smoothstep(cutoffEnd, cutoffStart, width);
    return mix(0.5, x, f);
}

#endif

Use:

nyquist(<float> value, <float> width, <float> strength)

Check it on Github


#ifndef FNC_NYQUIST
#define FNC_NYQUIST

#ifndef NYQUIST_FILTER_CENTER
#define NYQUIST_FILTER_CENTER 0.5
#endif

#ifndef NYQUIST_FILTER_WIDTH
#define NYQUIST_FILTER_WIDTH 0.25
#endif

float nyquist(float x, float width){
    float cutoffStart = NYQUIST_FILTER_CENTER - NYQUIST_FILTER_WIDTH;
    float cutoffEnd = NYQUIST_FILTER_CENTER + NYQUIST_FILTER_WIDTH;
    float f = smoothstep(cutoffEnd, cutoffStart, width);
    return lerp(0.5, x, f);
}

#endif

License

MIT License (MIT) Copyright (c) 2024 Shadi EL Hajj

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