Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 

178 wiersze
5.1 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. #if defined GL_ES
  13. precision highp float;
  14. #endif
  15. uniform sampler2D u_Texture;
  16. varying vec4 pass_Position;
  17. float segdist(vec2 p1, vec2 p2, vec2 a)
  18. {
  19. float d = max(1e-10, dot(p2 - p1, p2 - p1));
  20. float t = clamp(dot(a - p1, p2 - p1) / d, 0.0, 1.0);
  21. return distance(a, mix(p1, p2, t));
  22. }
  23. vec3 hsv2rgb(vec3 c)
  24. {
  25. vec3 tmp = abs(fract(c[0] + vec3(3.0, 2.0, 1.0) / 3.0) * 6.0 - 3.0);
  26. return c[2] * mix(vec3(1.0), clamp((tmp - 1.0), 0.0, 1.0), c[1]);
  27. }
  28. vec3 rgb2hsv(vec3 c)
  29. {
  30. vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
  31. vec4 v1 = mix(vec4(c.bg, K.wz),
  32. vec4(c.gb, K.xy),
  33. step(c.b, c.g));
  34. vec4 v3 = mix(vec4(v1.x, v1.yw, c.r),
  35. vec4(c.r, v1.yzx),
  36. step(v1.x, c.r));
  37. float chroma = v3.r - min(v3.a, v3.g);
  38. float h = abs(v3.b + (v3.a - v3.g) / (6.0 * chroma + 1.0e-10));
  39. float s = chroma / (v3.r + 1.0e-10);
  40. float v = v3.r;
  41. return vec3(h, s, v);
  42. }
  43. void main(void)
  44. {
  45. float width = 800.0;
  46. float height = 600.0;
  47. float texture_width = 256.0;
  48. float line_width = 1.2;
  49. float dot_size = 1.0;
  50. vec4 delta = vec4(1.0 / texture_width, 0.0,
  51. 2.0 / texture_width, 0.0);
  52. vec2 p = pass_Position.xy;
  53. vec2 tc = vec2(floor(p.x * texture_width) / texture_width, p.y);
  54. float t = p.x * texture_width - floor(p.x * texture_width);
  55. vec4 c;
  56. c[0] = texture2D(u_Texture, tc - delta.xy).x;
  57. c[1] = texture2D(u_Texture, tc).x;
  58. c[2] = texture2D(u_Texture, tc + delta.xy).x;
  59. c[3] = texture2D(u_Texture, tc + delta.zw).x;
  60. /* Find the 4 closest points in screen space */
  61. vec2 p0 = vec2((tc.x - delta.x) * width, c[0] * height);
  62. vec2 p1 = vec2((tc.x ) * width, c[1] * height);
  63. vec2 p2 = vec2((tc.x + delta.x) * width, c[2] * height);
  64. vec2 p3 = vec2((tc.x + delta.z) * width, c[3] * height);
  65. vec2 a = vec2(p.x * width, p.y * height);
  66. /* Compute distance to segments */
  67. float d = segdist(p0, p1, a);
  68. d = min(d, segdist(p1, p2, a));
  69. d = min(d, segdist(p2, p3, a));
  70. /* Compute distance to dots */
  71. d = min(d, length(a - p0) - dot_size);
  72. d = min(d, length(a - p1) - dot_size);
  73. d = min(d, length(a - p2) - dot_size);
  74. d = min(d, length(a - p3) - dot_size);
  75. /* Add line width */
  76. float lum = clamp(line_width - d, 0.0, 1.0);
  77. /* Compensate for sRGB */
  78. lum = pow(1.0 - lum, 1.0 / 2.4);
  79. /* Choose some funny colours */
  80. vec4 col = vec4(mix(p.x, 1.0, lum), lum, lum, 1.0);
  81. col.rgb = hsv2rgb(rgb2hsv(col.rgb) * vec3(1.0, 1.0, 0.5) + vec3(p.x, 0.5, 0.0));
  82. col.rgb = hsv2rgb(rgb2hsv(col.rgb));
  83. col.rgb = hsv2rgb(rgb2hsv(col.rgb));
  84. col.rgb = hsv2rgb(rgb2hsv(col.rgb));
  85. gl_FragColor = col;
  86. }
  87. [vert.hlsl]
  88. void main(float2 in_Position : POSITION,
  89. out float4 out_Position : POSITION,
  90. out float4 pass_Position : TEXCOORD0)
  91. {
  92. pass_Position = float4(0.5 * in_Position + 0.5, 0.0, 1.0);
  93. out_Position = float4(in_Position, 0.5, 1.0);
  94. }
  95. [frag.hlsl]
  96. float segdist(float2 p1, float2 p2, float2 a)
  97. {
  98. float d = max(1e-10, dot(p2 - p1, p2 - p1));
  99. float t = clamp(dot(a - p1, p2 - p1) / d, 0.0, 1.0);
  100. return distance(a, lerp(p1, p2, t));
  101. }
  102. void main(in float4 pass_Position : TEXCOORD0,
  103. uniform sampler2D u_Texture,
  104. out float4 out_FragColor : COLOR)
  105. {
  106. float width = 800.0;
  107. float height = 600.0;
  108. float texture_width = 256.0;
  109. float line_width = 1.2;
  110. float dot_size = 1.0;
  111. float4 delta = float4(1.0 / texture_width, 0.0,
  112. 2.0 / texture_width, 0.0);
  113. float2 p = pass_Position.xy;
  114. float2 tc = float2(floor(p.x * texture_width) / texture_width, p.y);
  115. float t = p.x * texture_width - floor(p.x * texture_width);
  116. float4 c;
  117. c[0] = tex2D(u_Texture, tc - delta.xy).x;
  118. c[1] = tex2D(u_Texture, tc).x;
  119. c[2] = tex2D(u_Texture, tc + delta.xy).x;
  120. c[3] = tex2D(u_Texture, tc + delta.zw).x;
  121. /* Find the 4 closest points in screen space */
  122. float2 p0 = float2((tc.x - delta.x) * width, c[0] * height);
  123. float2 p1 = float2((tc.x ) * width, c[1] * height);
  124. float2 p2 = float2((tc.x + delta.x) * width, c[2] * height);
  125. float2 p3 = float2((tc.x + delta.z) * width, c[3] * height);
  126. float2 a = float2(p.x * width, p.y * height);
  127. /* Compute distance to segments */
  128. float d = segdist(p0, p1, a);
  129. d = min(d, segdist(p1, p2, a));
  130. d = min(d, segdist(p2, p3, a));
  131. /* Compute distance to dots */
  132. d = min(d, length(a - p0) - dot_size);
  133. d = min(d, length(a - p1) - dot_size);
  134. d = min(d, length(a - p2) - dot_size);
  135. d = min(d, length(a - p3) - dot_size);
  136. /* Add line width */
  137. float lum = clamp(line_width - d, 0.0, 1.0);
  138. /* Compensate for sRGB */
  139. lum = pow(1.0 - lum, 1.0 / 2.4);
  140. /* Choose some funny colours */
  141. out_FragColor = float4(lerp(p.x, 1.0, lum), lum, lum, 1.0);
  142. }