LYGIA Shader Library

round (lygia/math/round)

round a value to the nearest integer

Use:

<float|vec2|vec3|vec4> round(<float|vec2|vec3|vec4> value)

Check it on Github


#ifndef FNC_ROUND
#define FNC_ROUND
float round(float x) { return sign(x)*floor(abs(x)+0.5); }
vec2 round(vec2 x) { return sign(x)*floor(abs(x)+0.5); }
vec3 round(vec3 x) { return sign(x)*floor(abs(x)+0.5); }
vec4 round(vec4 x) { return sign(x)*floor(abs(x)+0.5); }
#endif

Use:

<float|float2|float3|float4> round(<float|float2|float3|float4> value)

Check it on Github


#ifndef FNC_ROUND
#define FNC_ROUND
float round(float x) { return sign(x)*floor(abs(x)+0.5); }
float2 round(float2 x) { return sign(x)*floor(abs(x)+0.5); }
float3 round(float3 x) { return sign(x)*floor(abs(x)+0.5); }
float4 round(float4 x) { return sign(x)*floor(abs(x)+0.5); }
#endif

Check it on Github


fn round(x: f32) -> f32 { return sign(x)*floor(abs(x)+0.5); }
fn round2(x: vec2f) -> vec2f { return sign(x)*floor(abs(x)+0.5); }
fn round3(x: vec3f) -> vec3f { return sign(x)*floor(abs(x)+0.5); }
fn round4(x: vec4f) -> vec4f { return sign(x)*floor(abs(x)+0.5); }

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