Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

12 роки тому
12 роки тому
12 роки тому
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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 texture_width = 256.0;
  25. float line_width = 1.2;
  26. float dot_size = 1.0;
  27. vec4 delta = vec4(1.0 / texture_width, 0.0,
  28. 2.0 / texture_width, 0.0);
  29. vec2 p = pass_Position.xy;
  30. vec2 tc = vec2(floor(p.x * texture_width) / texture_width, p.y);
  31. float t = p.x * texture_width - floor(p.x * texture_width);
  32. vec4 c;
  33. c[0] = texture2D(u_Texture, tc - delta.xy).x;
  34. c[1] = texture2D(u_Texture, tc).x;
  35. c[2] = texture2D(u_Texture, tc + delta.xy).x;
  36. c[3] = texture2D(u_Texture, tc + delta.zw).x;
  37. /* Find the 4 closest points in screen space */
  38. vec2 p0 = vec2((tc.x - delta.x) * width, c[0] * height);
  39. vec2 p1 = vec2((tc.x ) * width, c[1] * height);
  40. vec2 p2 = vec2((tc.x + delta.x) * width, c[2] * height);
  41. vec2 p3 = vec2((tc.x + delta.z) * width, c[3] * height);
  42. vec2 a = vec2(p.x * width, p.y * height);
  43. /* Compute distance to segments */
  44. float d = segdist(p0, p1, a);
  45. d = min(d, segdist(p1, p2, a));
  46. d = min(d, segdist(p2, p3, a));
  47. /* Compute distance to dots */
  48. d = min(d, length(a - p0) - dot_size);
  49. d = min(d, length(a - p1) - dot_size);
  50. d = min(d, length(a - p2) - dot_size);
  51. d = min(d, length(a - p3) - dot_size);
  52. /* Add line width */
  53. float lum = clamp(line_width - d, 0.0, 1.0);
  54. /* Compensate for sRGB */
  55. lum = pow(1.0 - lum, 1.0 / 2.4);
  56. /* Choose some funny colours */
  57. gl_FragColor = vec4(mix(p.x, 1.0, lum), lum, lum, 1.0);
  58. }
  59. [vert.hlsl]
  60. void main(float2 in_Position : POSITION,
  61. out float4 out_Position : POSITION,
  62. out float4 pass_Position : TEXCOORD0)
  63. {
  64. pass_Position = float4(0.5 * in_Position + 0.5, 0.0, 1.0);
  65. out_Position = float4(in_Position, 0.5, 1.0);
  66. }
  67. [frag.hlsl]
  68. float segdist(float2 p1, float2 p2, float2 a)
  69. {
  70. float d = max(1e-10, dot(p2 - p1, p2 - p1));
  71. float t = clamp(dot(a - p1, p2 - p1) / d, 0.0, 1.0);
  72. return distance(a, lerp(p1, p2, t));
  73. }
  74. void main(in float4 pass_Position : TEXCOORD0,
  75. uniform sampler2D u_Texture,
  76. out float4 out_FragColor : COLOR)
  77. {
  78. float width = 800.0;
  79. float height = 600.0;
  80. float texture_width = 256.0;
  81. float line_width = 1.2;
  82. float dot_size = 1.0;
  83. float4 delta = float4(1.0 / texture_width, 0.0,
  84. 2.0 / texture_width, 0.0);
  85. float2 p = pass_Position.xy;
  86. float2 tc = float2(floor(p.x * texture_width) / texture_width, p.y);
  87. float t = p.x * texture_width - floor(p.x * texture_width);
  88. float4 c;
  89. c[0] = tex2D(u_Texture, tc - delta.xy).x;
  90. c[1] = tex2D(u_Texture, tc).x;
  91. c[2] = tex2D(u_Texture, tc + delta.xy).x;
  92. c[3] = tex2D(u_Texture, tc + delta.zw).x;
  93. /* Find the 4 closest points in screen space */
  94. float2 p0 = float2((tc.x - delta.x) * width, c[0] * height);
  95. float2 p1 = float2((tc.x ) * width, c[1] * height);
  96. float2 p2 = float2((tc.x + delta.x) * width, c[2] * height);
  97. float2 p3 = float2((tc.x + delta.z) * width, c[3] * height);
  98. float2 a = float2(p.x * width, p.y * height);
  99. /* Compute distance to segments */
  100. float d = segdist(p0, p1, a);
  101. d = min(d, segdist(p1, p2, a));
  102. d = min(d, segdist(p2, p3, a));
  103. /* Compute distance to dots */
  104. d = min(d, length(a - p0) - dot_size);
  105. d = min(d, length(a - p1) - dot_size);
  106. d = min(d, length(a - p2) - dot_size);
  107. d = min(d, length(a - p3) - dot_size);
  108. /* Add line width */
  109. float lum = clamp(line_width - d, 0.0, 1.0);
  110. /* Compensate for sRGB */
  111. lum = pow(1.0 - lum, 1.0 / 2.4);
  112. /* Choose some funny colours */
  113. out_FragColor = float4(lerp(p.x, 1.0, lum), lum, lum, 1.0);
  114. }