opengl_fragment.glsl 863 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #define rendered texture0
  2. uniform sampler2D rendered;
  3. uniform vec2 texelSize0;
  4. uniform mediump float bloomRadius;
  5. uniform mat3 bloomBlurWeights;
  6. #ifdef GL_ES
  7. varying mediump vec2 varTexCoord;
  8. #else
  9. centroid varying vec2 varTexCoord;
  10. #endif
  11. // smoothstep - squared
  12. float smstsq(float f)
  13. {
  14. f = f * f * (3. - 2. * f);
  15. return f;
  16. }
  17. void main(void)
  18. {
  19. // kernel distance and linear size
  20. mediump float n = 2. * bloomRadius + 1.;
  21. vec2 uv = varTexCoord.st - vec2(bloomRadius * texelSize0.x, 0.);
  22. vec4 color = vec4(0.);
  23. mediump float sum = 0.;
  24. for (mediump float i = 0.; i < n; i++) {
  25. mediump float weight = smstsq(1. - (abs(i / bloomRadius - 1.)));
  26. color.rgb += texture2D(rendered, uv).rgb * weight;
  27. sum += weight;
  28. uv += vec2(texelSize0.x, 0.);
  29. }
  30. color /= sum;
  31. gl_FragColor = vec4(color.rgb, 1.0); // force full alpha to avoid holes in the image.
  32. }