LYGIA Shader Library

gaussian (lygia/math/gaussian)

gaussian coeficient

Use:

<vec4|vec3|vec2|float> gaussian(<float> sigma, <vec4|vec3|vec2|float> d)

Check it on Github


#ifndef FNC_GAUSSIAN
#define FNC_GAUSSIAN
float gaussian(float d, float s) { return exp(-(d*d) / (2.0 * s*s)); }
float gaussian( vec2 d, float s) { return exp(-( d.x*d.x + d.y*d.y) / (2.0 * s*s)); }
float gaussian( vec3 d, float s) { return exp(-( d.x*d.x + d.y*d.y + d.z*d.z ) / (2.0 * s*s)); }
float gaussian( vec4 d, float s) { return exp(-( d.x*d.x + d.y*d.y + d.z*d.z + d.w*d.w ) / (2.0 * s*s)); }
#endif

Use:

<float4|float3|float2|float> gaussian(<float4|float3|float2|float> d, <float> sigma)

Check it on Github


#ifndef FNC_GAUSSIAN
#define FNC_GAUSSIAN
inline float gaussian(float d, float sigma) { return exp(-(d * d) / (2.0 * sigma * sigma)); }
inline float gaussian(float2 d, float sigma) { return exp(-(d.x * d.x + d.y * d.y) / (2.0 * sigma * sigma)); }
inline float gaussian(float3 d, float sigma) { return exp(-(d.x * d.x + d.y * d.y + d.z * d.z) / (2.0 * sigma * sigma)); }
inline float gaussian(float4 d, float sigma) {
    return exp(-(d.x * d.x + d.y * d.y + d.z * d.z + d.w * d.w) / (2.0 * sigma * sigma));
}
#endif

Use:

<float4|float3|float2|float> gaussian(<float> sigma, <float4|float3|float2|float> d)

Check it on Github


#ifndef FNC_GAUSSIAN
#define FNC_GAUSSIAN
float gaussian(float d, float s) { return exp(-(d*d) / (2.0 * s*s)); }
float gaussian( float2 d, float s) { return exp(-( d.x*d.x + d.y*d.y) / (2.0 * s*s)); }
float gaussian( float3 d, float s) { return exp(-( d.x*d.x + d.y*d.y + d.z*d.z ) / (2.0 * s*s)); }
float gaussian( float4 d, float s) { return exp(-( d.x*d.x + d.y*d.y + d.z*d.z + d.w*d.w ) / (2.0 * s*s)); }
#endif

Check it on Github


fn gaussian(d: f32, sigma: f32) -> f32 { return exp(-(d*d) / (2.0 * sigma * sigma)); }
fn gaussian2(d: vec2f, sigma: f32) -> f32 { return exp(-(d.x*d.x + d.y*d.y) / (2.0 * sigma * sigma));  }
fn gaussian3(d: vec3f, sigma: f32) -> f32 { return exp(-(d.x*d.x + d.y*d.y + d.z*d.z) / (2.0 * sigma * sigma)); }
fn gaussian4(d: vec4f, sigma: f32) -> f32 { return exp(-(d.x*d.x + d.y*d.y + d.z*d.z + d.w*d.w) / (2.0 * sigma * sigma)); }

Dependencies:

Use:

<float4|float3|float2|float> gaussian(<float> sigma, <float4|float3|float2|float> d)

Check it on Github


#ifndef FNC_GAUSSIAN
#define FNC_GAUSSIAN

inline __host__ __device__ float gaussian(        float d, float sigma) { return exp(-(d*d) / (2.0f * sigma*sigma)); }
inline __host__ __device__ float gaussian(const float2& d, float sigma) { return exp(-( d.x*d.x + d.y*d.y) / (2.0f * sigma*sigma)); }
inline __host__ __device__ float gaussian(const float3& d, float sigma) { return exp(-( d.x*d.x + d.y*d.y + d.z*d.z ) / (2.0f * sigma*sigma)); }
inline __host__ __device__ float gaussian(const float4& d, float sigma) { return exp(-( d.x*d.x + d.y*d.y + d.z*d.z + d.w*d.w ) / (2.0f * sigma*sigma)); }
#endif

Examples

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