gauss_horiz.fs 845 B

12345678910111213141516171819202122232425262728293031323334
  1. #version 150
  2. #define INV_SQRT_2_PI 0.38 // Doesn't have to be accurate.
  3. #define HORIZ_GAUSS_WIDTH 0.5
  4. uniform sampler2D source[];
  5. uniform vec4 sourceSize[];
  6. in Vertex {
  7. vec2 vTexCoord;
  8. float data_pix_no;
  9. float data_one;
  10. };
  11. out vec4 FragColor;
  12. void main() {
  13. float texel = floor(data_pix_no);
  14. float phase = data_pix_no - texel;
  15. float base_phase = phase - 0.5;
  16. vec2 tex = vec2((texel + 0.5) * sourceSize[0].z, vTexCoord.y);
  17. vec3 col = vec3(0.0);
  18. for (int i = -2; i <= 2; i++)
  19. {
  20. float phase = base_phase - float(i);
  21. float g = INV_SQRT_2_PI * exp(-0.5 * phase * phase / (HORIZ_GAUSS_WIDTH * HORIZ_GAUSS_WIDTH)) / HORIZ_GAUSS_WIDTH;
  22. col += texture(source[0], tex + vec2(float(i) * data_one, 0.0)).rgb * g;
  23. }
  24. FragColor = vec4(col, 1.0);
  25. }