You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

66 lines
1.6 KiB

  1. [vert.glsl]
  2. #version 120
  3. attribute vec2 in_Position;
  4. varying vec4 pass_Position;
  5. void main(void)
  6. {
  7. pass_Position = vec4(0.5 * in_Position + 0.5, 0.0, 1.0);
  8. gl_Position = vec4(in_Position, 0.5, 1.0);
  9. }
  10. [frag.glsl]
  11. #version 120
  12. uniform sampler2D u_Texture;
  13. varying vec4 pass_Position;
  14. float segdist(vec2 p1, vec2 p2, vec2 a)
  15. {
  16. float d = max(1e-10, dot(p2 - p1, p2 - p1));
  17. float t = clamp(dot(a - p1, p2 - p1) / d, 0.0, 1.0);
  18. return distance(a, mix(p1, p2, t));
  19. }
  20. void main(void)
  21. {
  22. float width = 800.0;
  23. float height = 600.0;
  24. float line_width = 1.8;
  25. vec4 delta = vec4(1.0 / 128, 0.0,
  26. 2.0 / 128, 0.0);
  27. vec2 p = pass_Position.xy;
  28. vec2 tc = vec2(floor(p.x * 128.0) / 128.0, p.y);
  29. float t = p.x * 128.0 - floor(p.x * 128.0);
  30. vec4 c;
  31. c[0] = texture2D(u_Texture, tc - delta.xy).x;
  32. c[1] = texture2D(u_Texture, tc).x;
  33. c[2] = texture2D(u_Texture, tc + delta.xy).x;
  34. c[3] = texture2D(u_Texture, tc + delta.zw).x;
  35. /* Quick hack: artificially compress display in Y */
  36. c *= 0.3;
  37. vec2 p0 = vec2((tc.x - delta.x) * width, c[0] * height);
  38. vec2 p1 = vec2((tc.x) * width, c[1] * height);
  39. vec2 p2 = vec2((tc.x + delta.x) * width, c[2] * height);
  40. vec2 p3 = vec2((tc.x + delta.z) * width, c[3] * height);
  41. vec2 a = vec2(p.x * width, p.y * height);
  42. float d0 = segdist(p0, p1, a);
  43. float d1 = segdist(p1, p2, a);
  44. float d2 = segdist(p2, p3, a);
  45. float d = clamp(line_width - min(min(d0, d1), d2), 0.0, 1.0);
  46. /* Choose some funny colours */
  47. gl_FragColor = vec4(p.y, d, mix(p.x, 0.3, d), 1.0);
  48. }