LYGIA Shader Library

sum (lygia/math/sum)

Sum elements of a vector

Use:

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

Check it on Github


#ifndef FNC_SUM
#define FNC_SUM
float sum( float v ) { return v; }
float sum( vec2 v ) { return v.x+v.y; }
float sum( vec3 v ) { return v.x+v.y+v.z; }
float sum( vec4 v ) { return v.x+v.y+v.z+v.w; }
#endif

Use:

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

Check it on Github


#ifndef FNC_SUM
#define FNC_SUM
float sum( float v ) { return v; }
float sum( float2 v ) { return v.x+v.y; }
float sum( float3 v ) { return v.x+v.y+v.z; }
float sum( float4 v ) { return v.x+v.y+v.z+v.w; }
#endif

Check it on Github


fn sum(v: f32 ) -> f32 { return v; }
fn sum2(v: vec2f ) -> f32 { return v.x+v.y; }
fn sum3(v: vec3f ) -> f32 { return v.x+v.y+v.z; }
fn sum4(v: vec4f ) -> f32 { return v.x+v.y+v.z+v.w; }


Dependencies:

Use:

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

Check it on Github



#ifndef FNC_SUM
#define FNC_SUM

inline __host__ __device__ float sum( float v ) { return v; }
inline __host__ __device__ float sum( const float2& v ) { return v.x+v.y; }
inline __host__ __device__ float sum( const float3& v ) { return v.x+v.y+v.z; }
inline __host__ __device__ float sum( const float4& v ) { return v.x+v.y+v.z+v.w; }

inline __host__ __device__ int sum( int v ) { return v; }
inline __host__ __device__ int sum( int2 v ) { return v.x+v.y; }
inline __host__ __device__ int sum( int3 v ) { return v.x+v.y+v.z; }
inline __host__ __device__ int sum( int4 v ) { return v.x+v.y+v.z+v.w; }

inline __host__ __device__ uint sum( uint v ) { return v; }
inline __host__ __device__ uint sum( uint2 v ) { return v.x+v.y; }
inline __host__ __device__ uint sum( uint3 v ) { return v.x+v.y+v.z; }
inline __host__ __device__ uint sum( uint4 v ) { return v.x+v.y+v.z+v.w; }

#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