Advertisement
Guest User

Untitled

a guest
Sep 27th, 2019
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #ifdef GL_ES
  2. precision mediump float;
  3. #endif
  4.  
  5. const float pi = 3.141592653589793238462643383279502884; // atan(1.0) * 4.0;
  6. uniform vec2 resolution;
  7. uniform sampler2D iChannel0;
  8.  
  9. varying vec2 fragCoord;
  10.  
  11. float normpdf(in float x, in float sigma) {
  12.     return 0.39894 * exp(-0.5 * x * x / (sigma * sigma)) / sigma;
  13. }
  14.  
  15. vec4 texture(sampler2D s, vec2 c) {
  16.   return texture2D(s, c);
  17. }
  18.  
  19. void mainImage(out vec4 fragColor, in vec2 fragCoord) {
  20.     vec4 c = texture(iChannel0, fragCoord.xy / resolution.xy);
  21.  
  22.     //declare stuff
  23.     const int mSize = 7;
  24.     const int kSize = (mSize - 1) / 2;
  25.     float kernel[mSize];
  26.     vec4 final_colour = vec4(0.0);
  27.  
  28.     //create the 1-D kernel
  29.     float sigma = 7.0;
  30.     float Z = 0.0;
  31.     for (int j = 0; j <= kSize; ++j) {
  32.         kernel[kSize + j] = kernel[kSize - j] = normpdf(float(j), sigma);
  33.     }
  34.  
  35.     //get the normalization factor (as the gaussian has been clamped)
  36.     for (int j = 0; j < mSize; ++j) {
  37.         Z += kernel[j];
  38.     }
  39.  
  40.     //read out the texels
  41.     for (int i = -kSize; i <= kSize; ++i) {
  42.         for (int j=-kSize; j <= kSize; ++j) {
  43.             final_colour += kernel[kSize + j] * kernel[kSize + i] * texture(iChannel0, (fragCoord.xy + vec2(float(i), float(j))) / resolution.xy);
  44.         }
  45.     }
  46.  
  47.     fragColor = (final_colour / (Z * Z));
  48. }
  49.  
  50. void main(void) {
  51.     mainImage(gl_FragColor, fragCoord.xy);
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement