opengl_fragment.glsl 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. #define current texture0
  2. #define previous texture1
  3. uniform sampler2D current;
  4. uniform sampler2D previous;
  5. uniform vec2 texelSize0;
  6. uniform mediump float bloomRadius;
  7. #ifdef GL_ES
  8. varying mediump vec2 varTexCoord;
  9. #else
  10. centroid varying vec2 varTexCoord;
  11. #endif
  12. void main(void)
  13. {
  14. vec2 offset = bloomRadius * texelSize0;
  15. vec3 a = texture2D(previous, varTexCoord.st + vec2(-1., -1.) * offset).rgb;
  16. vec3 b = texture2D(previous, varTexCoord.st + vec2(0., -1.) * offset).rgb;
  17. vec3 c = texture2D(previous, varTexCoord.st + vec2(1., -1.) * offset).rgb;
  18. vec3 d = texture2D(previous, varTexCoord.st + vec2(-1., 0.) * offset).rgb;
  19. vec3 e = texture2D(previous, varTexCoord.st + vec2(0., 0.) * offset).rgb;
  20. vec3 f = texture2D(previous, varTexCoord.st + vec2(1., 0.) * offset).rgb;
  21. vec3 g = texture2D(previous, varTexCoord.st + vec2(-1., 1.) * offset).rgb;
  22. vec3 h = texture2D(previous, varTexCoord.st + vec2(0., 1.) * offset).rgb;
  23. vec3 i = texture2D(previous, varTexCoord.st + vec2(1., 1.) * offset).rgb;
  24. vec3 base = texture2D(current, varTexCoord.st).rgb;
  25. gl_FragColor = max(vec4(base +
  26. (a + c + g + i) * 0.0625 +
  27. (b + d + f + h) * 0.125 +
  28. e * 0.25, 1.), 1e-4);
  29. }