Skip to content

Instantly share code, notes, and snippets.

@izzyaxel
Last active December 19, 2017 22:20
Show Gist options
  • Save izzyaxel/2a4df98f7ada0d1b9192845324430dc6 to your computer and use it in GitHub Desktop.
Save izzyaxel/2a4df98f7ada0d1b9192845324430dc6 to your computer and use it in GitHub Desktop.
#version 450
layout(local_size_x = 40, local_size_y = 20) in;
layout(rgba32f, binding = 0) uniform image2D imageIn;
layout(rgba32f, binding = 1) uniform image2D imageOut;
uniform float sigma;
const uint taps = 3, distToCenter = 1;
const float pi = 3.1415926535897932384626433832795, e = 2.71828;
float weights[taps];
void gaussianFunction()
{
float sigSq = sigma * sigma, div = sqrt(2 * pi * sigSq), sum = 0;
for(int i = 0; i < taps; i++)
{
uint dist = abs(distToCenter - i);
weights[i] = (1 / div) * pow(e, -((dist * dist) / (2 * sigSq)));
sum += weights[i];
}
sum = 1.0 / sum;
for(int i = 0; i < taps; i++) weights[i] = weights[i] * sum;
}
void main()
{
gaussianFunction();
ivec2 current = ivec2(gl_GlobalInvocationID.xy);
vec4 color = vec4(0);
for(int i = 0; i < taps; i++)
{
uint dist = distToCenter - i;
color += imageLoad(imageIn, current + ivec2(dist, 0)) * weights[i];
}
imageStore(imageOut, current, color);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment