Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. varying float blurSize;
  2.  
  3. uniform sampler2D tex;
  4.  
  5. // Gaussian Blur
  6. // 512x512 and smaller textures give best results
  7. // 2 passes required
  8. void main()
  9. {
  10. // Echelon9 - Due to Apple not implementing array constructors in OS X's
  11. // GLSL implementation we need to setup the arrays this way as a workaround
  12. float BlurWeights[11];
  13.  
  14. BlurWeights[0] = 0.0402;
  15. BlurWeights[1] = 0.0623;
  16. BlurWeights[2] = 0.0877;
  17. BlurWeights[3] = 0.1120;
  18. BlurWeights[4] = 0.1297;
  19. BlurWeights[5] = 0.1362;
  20. BlurWeights[6] = 0.1297;
  21. BlurWeights[7] = 0.1120;
  22. BlurWeights[8] = 0.0877;
  23. BlurWeights[9] = 0.0623;
  24. BlurWeights[10] = 0.0402;
  25.  
  26.  
  27. vec4 sum = texture2D(tex, gl_TexCoord[0].xy) * BlurWeights[0];
  28.  
  29. #ifdef PASS_0
  30. for (int i = 1; i < 11; i++) {
  31. sum += texture2D(tex, vec2(clamp(gl_TexCoord[0].x - float(i) * (blurSize/2), 0.0, 1.0), gl_TexCoord[0].y)) * BlurWeights[i];
  32. sum += texture2D(tex, vec2(clamp(gl_TexCoord[0].x + float(i) * (blurSize/2), 0.0, 1.0), gl_TexCoord[0].y)) * BlurWeights[i];
  33. }
  34. #endif
  35.  
  36. #ifdef PASS_1
  37. for (int i = 1; i < 11; i++) {
  38. sum += texture2D(tex, vec2(gl_TexCoord[0].x, clamp(gl_TexCoord[0].y - float(i) * (blurSize/2), 0.0, 1.0))) * BlurWeights[i];
  39. sum += texture2D(tex, vec2(gl_TexCoord[0].x, clamp(gl_TexCoord[0].y + float(i) * (blurSize/2), 0.0, 1.0))) * BlurWeights[i];
  40. }
  41. #endif
  42.  
  43. gl_FragColor = sum;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement