Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifdef GL_ES
- precision mediump float;
- #endif
- const float pi = 3.141592653589793238462643383279502884; // atan(1.0) * 4.0;
- uniform vec2 resolution;
- uniform sampler2D iChannel0;
- varying vec2 fragCoord;
- float normpdf(in float x, in float sigma) {
- return 0.39894 * exp(-0.5 * x * x / (sigma * sigma)) / sigma;
- }
- vec4 texture(sampler2D s, vec2 c) {
- return texture2D(s, c);
- }
- void mainImage(out vec4 fragColor, in vec2 fragCoord) {
- vec4 c = texture(iChannel0, fragCoord.xy / resolution.xy);
- //declare stuff
- const int mSize = 7;
- const int kSize = (mSize - 1) / 2;
- float kernel[mSize];
- vec4 final_colour = vec4(0.0);
- //create the 1-D kernel
- float sigma = 7.0;
- float Z = 0.0;
- for (int j = 0; j <= kSize; ++j) {
- kernel[kSize + j] = kernel[kSize - j] = normpdf(float(j), sigma);
- }
- //get the normalization factor (as the gaussian has been clamped)
- for (int j = 0; j < mSize; ++j) {
- Z += kernel[j];
- }
- //read out the texels
- for (int i = -kSize; i <= kSize; ++i) {
- for (int j=-kSize; j <= kSize; ++j) {
- final_colour += kernel[kSize + j] * kernel[kSize + i] * texture(iChannel0, (fragCoord.xy + vec2(float(i), float(j))) / resolution.xy);
- }
- }
- fragColor = (final_colour / (Z * Z));
- }
- void main(void) {
- mainImage(gl_FragColor, fragCoord.xy);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement