LYGIA Shader Library

sampler (lygia/sampler)

It defines the default sampler type and function for the shader based on the version of GLSL.

Check it on Github

#ifndef SAMPLER_FNC
#if __VERSION__ >= 300
#define SAMPLER_FNC(TEX, UV) texture(TEX, UV)
#else
#define SAMPLER_FNC(TEX, UV) texture2D(TEX, UV)
#endif
#endif

#ifndef SAMPLER_TYPE
#define SAMPLER_TYPE sampler2D
#endif

Check it on Github


#if defined(__SHADER_TARGET_MAJOR) && __SHADER_TARGET_MAJOR < 4

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

    #ifndef SAMPLER_TYPE
    #define SAMPLER_TYPE sampler2D
    #endif

#else

    // https://docs.unity3d.com/Manual/SL-SamplerStates.html
    #ifndef SAMPLER_BILINEAR_CLAMP
    #define SAMPLER_BILINEAR_CLAMP defaultLinearClampSampler
    SamplerState SAMPLER_BILINEAR_CLAMP
    {
        Filter = MIN_MAG_LINEAR_MIP_POINT;
        AddressU = Clamp;
        AddressV = Clamp;
    };
    #endif

    #ifndef SAMPLER_TRILINEAR_CLAMP
    #define SAMPLER_TRILINEAR_CLAMP defaultTrilinearClampSampler
    SamplerState SAMPLER_TRILINEAR_CLAMP
    {
        Filter = MIN_MAG_MIP_LINEAR;
        AddressU = Clamp;
        AddressV = Clamp;
    };
    #endif

    #ifndef SAMPLER_FNC
    #define SAMPLER_FNC(TEX, UV) TEX.Sample(SAMPLER_BILINEAR_CLAMP, UV)
    #endif

    #ifndef SAMPLER_TYPE
    #define SAMPLER_TYPE Texture2D
    #endif

#endif

Check it on Github


#ifndef SAMPLER
#define SAMPLER sampler( min_filter::linear, mag_filter::linear )
#endif

#ifndef SAMPLER_FNC
#define SAMPLER_FNC(TEX, UV) TEX.sample(SAMPLER, UV)
#endif

#ifndef SAMPLER_TYPE
#define SAMPLER_TYPE texture2d<float>
#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