GaussianBlur1D.glsl 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #define SAMPLES 8
  2. uniform float delta;
  3. uniform float sigma;
  4. uniform float direction; // 0.0 for x direction, 1.0 for y direction
  5. uniform sampler2D colorTexture;
  6. #ifdef USE_STEP_SIZE
  7. uniform float stepSize;
  8. #else
  9. uniform vec2 step;
  10. #endif
  11. varying vec2 v_textureCoordinates;
  12. // Incremental Computation of the Gaussian:
  13. // https://developer.nvidia.com/gpugems/GPUGems3/gpugems3_ch40.html
  14. void main()
  15. {
  16. vec2 st = v_textureCoordinates;
  17. vec2 dir = vec2(1.0 - direction, direction);
  18. #ifdef USE_STEP_SIZE
  19. vec2 step = vec2(stepSize * (czm_pixelRatio / czm_viewport.zw));
  20. #else
  21. vec2 step = step;
  22. #endif
  23. vec3 g;
  24. g.x = 1.0 / (sqrt(czm_twoPi) * sigma);
  25. g.y = exp((-0.5 * delta * delta) / (sigma * sigma));
  26. g.z = g.y * g.y;
  27. vec4 result = texture2D(colorTexture, st) * g.x;
  28. for (int i = 1; i < SAMPLES; ++i)
  29. {
  30. g.xy *= g.yz;
  31. vec2 offset = float(i) * dir * step;
  32. result += texture2D(colorTexture, st - offset) * g.x;
  33. result += texture2D(colorTexture, st + offset) * g.x;
  34. }
  35. gl_FragColor = result;
  36. }