Advertisement
Guest User

Untitled

a guest
Sep 26th, 2019
119
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 = atan(1.0) * 4.0;
  6. const int samples = 256;
  7. const float sigma = sqrt(float(samples));
  8. uniform float time;
  9. uniform vec2 resolution;
  10. uniform sampler2D iChannel0;
  11.  
  12. varying vec2 fragCoord;
  13.  
  14. float normpdf(in float x, in float sigma) {
  15.     return 0.39894 * exp(-0.5 * x * x / (sigma * sigma)) / sigma;
  16. }
  17.  
  18. vec4 texture(sampler2D s, vec2 c) {
  19.   return texture2D(s,c);
  20. }
  21.  
  22. void mainImage(out vec4 fragColor, in vec2 fragCoord) {
  23.     vec4 c = texture(iChannel0, fragCoord.xy / resolution.xy);
  24.  
  25.     //declare stuff
  26.     const int mSize = 11;
  27.     const int kSize = (mSize - 1) / 2;
  28.     float kernel[mSize];
  29.     vec4 final_colour = vec4(0.0);
  30.  
  31.     //create the 1-D kernel
  32.     float sigma = 7.0;
  33.     float Z = 0.0;
  34.     for (int j = 0; j <= kSize; ++j) {
  35.         kernel[kSize + j] = kernel[kSize - j] = normpdf(float(j), sigma);
  36.     }
  37.  
  38.     //get the normalization factor (as the gaussian has been clamped)
  39.     for (int j = 0; j < mSize; ++j) {
  40.         Z += kernel[j];
  41.     }
  42.  
  43.     //read out the texels
  44.     for (int i = -kSize; i <= kSize; ++i) {
  45.         for (int j=-kSize; j <= kSize; ++j) {
  46.             final_colour += kernel[kSize + j] * kernel[kSize + i] * texture(iChannel0, (fragCoord.xy + vec2(float(i), float(j))) / resolution.xy);
  47.         }
  48.     }
  49.  
  50.     fragColor = (final_colour / (Z * Z));
  51. }
  52.  
  53. void main(void) {
  54.     mainImage(gl_FragColor, fragCoord.xy);
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement