Advertisement
Guest User

Untitled

a guest
Dec 12th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1. //shader dotmatrix2_vertex
  2.  
  3. #version 440 core
  4. layout(location = 0) in vec3 aPos;
  5. layout(location = 1) in vec2 aUV;
  6.  
  7. out VS_OUT {
  8. vec2 uv;
  9. } vs_out;
  10.  
  11. uniform mat4 transform;
  12.  
  13. void main() {
  14. gl_Position = transform * vec4(aPos, 1);
  15. vs_out.uv = aUV;
  16. }
  17.  
  18. //shader dotmatrix2_fragment
  19. #version 440 core
  20. out vec4 FragColor;
  21. in vec2 uv2;
  22. in vec2 dots2;
  23. flat in uvec2 dots3;
  24.  
  25. layout(shared, binding = 2) uniform DotMatrix {
  26. uvec2 dots;
  27. float k1;
  28. float k2;
  29. float k3;
  30. float max;
  31. };
  32.  
  33. float fc(float x) { return (x+1)/2; }
  34. float fd(float x) { return (2*x-1); }
  35.  
  36. float ntsf(float x,float k) {
  37. x = clamp(x,-1.0,1.0);
  38. return (x-x*k)/(k - abs(x) * 2.0 * k + 1.0);
  39. }
  40.  
  41. float ntsf3(float x,float k1,float k2,float k3) {
  42. return fd(ntsf(fc(ntsf(fd(ntsf(fc(x),k1)),k2)),k3));
  43. }
  44.  
  45. float ntsf3s(float x,float k1,float k2,float k3) {
  46. return sign(x) * ntsf3(2*abs(x)-1,k1,k2,k3)/2+0.5;
  47. }
  48.  
  49. void main() {
  50. // unsigned int c2 = int(dots2.x*4096);
  51. //unsigned int c1 = int(dots2.y*4096);
  52. unsigned int c2 = dots3.x;
  53. unsigned int c1 = dots3.y;
  54.  
  55. //c1=0xaaaaaaaa;
  56. //c2=0x55555555;
  57.  
  58. #if 1
  59. float s = 1.0/8.0;
  60. unsigned int i=0;
  61. float v=0;
  62. for(float y=0;y<1;y+=s) {
  63. for(float x=0;x<1;x+=s) {
  64. vec2 p = (uv2-1.0/16.0);
  65. if((((i<32?c1:c2)>>(31-(i&31))) & 1) != 0) {
  66. float e = distance(vec2(x,y),p);
  67. if(e<max) {
  68. v += clamp(ntsf3s(1-e,k1,k2,k3),0,1)*1.5;
  69. }
  70. }
  71. i++;
  72. }
  73. }
  74. #endif
  75.  
  76. FragColor = vec4(vec3(0,1,0),v*0.5);
  77. //FragColor = vec4(vec3(1,0,0),1);
  78. }
  79.  
  80. //shader dotmatrix2_geometry
  81. #version 440 core
  82. layout (triangles) in;
  83. layout (triangle_strip, max_vertices = 100) out;
  84. layout(shared, binding = 3) uniform DotMatrixFont {
  85. int px;
  86. int py;
  87. float size;
  88. uvec2 patterns[256];
  89. };
  90. layout(shared, binding = 4) uniform String {
  91. int string[256];
  92. };
  93.  
  94. in VS_OUT {
  95. vec2 uv;
  96. } gs_in[];
  97.  
  98. out vec2 uv2;
  99. out vec2 dots2;
  100. flat out uvec2 dots3;
  101.  
  102. void main() {
  103. int i;
  104.  
  105. int count=0;
  106. for(int ci=0;;ci++) {
  107. int ch4 = string[ci];
  108. for(int bi=0;bi<4;bi++,ch4>>=8) {
  109. int ch = ch4 & 0xff;
  110. if(ch==0) {
  111. return;
  112. }
  113. dots3 = patterns[ch];
  114. for(i = 0; i < 3; i++) {
  115. uv2 = gs_in[i].uv;
  116. gl_Position = gl_in[i].gl_Position + vec4(count*size*6.0/8,0,0,0);
  117. EmitVertex();
  118. }
  119. EndPrimitive();
  120. count++;
  121. }
  122. }
  123.  
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement