LYGIA Shader Library

select (lygia/math/select)

Returns A when cond is true, and B otherwise. This is in part to bring a compatibility layer with WGSL

Use:

<float|vec2|vec3|vec4> select(<float|vec2|vec3|vec4> A, <float|vec2|vec3|vec4> B, <bool> cond)

Check it on Github


#ifndef FNC_SELECT
#define FNC_SELECT
int select(int A, int B, bool cond) { return cond ? A : B; }
float select(float A, float B, bool cond) { return cond ? A : B; }
vec2 select(vec2 A, vec2 B, bool cond) { return cond ? A : B; }
vec3 select(vec3 A, vec3 B, bool cond) { return cond ? A : B; }
vec4 select(vec4 A, vec4 B, bool cond) { return cond ? A : B; }
#endif

Use:

<float|float2|float3|float4> select(<float|float2|float3|float4> A, <float|float2|float3|float4> B, <bool> cond)

Check it on Github


#ifndef FNC_SELECT
#define FNC_SELECT
int select(int A, int B, bool cond) { return cond ? A : B; }
float select(float A, float B, bool cond) { return cond ? A : B; }
float2 select(float2 A, float2 B, bool cond) { return cond ? A : B; }
float3 select(float3 A, float3 B, bool cond) { return cond ? A : B; }
float4 select(float4 A, float4 B, bool cond) { return cond ? A : B; }
#endif

License

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