Advertisement
Guest User

x

a guest
Jul 23rd, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #shader vertex
  2. #version 330 core
  3.  
  4. uniform int Time;
  5. uniform vec4 Camera;
  6.  
  7. layout(location = 0) in ivec2 InPosition;
  8. layout(location = 1) in ivec2 InIndexes;
  9. layout(location = 2) in uvec4 InData;
  10.  
  11. flat out vec4 TilePosition;
  12. flat out ivec2 TexIndexes;
  13.  
  14. float rand(int x, int y)
  15. {
  16.     return fract(sin(x) * cos(y) * 43758.5453123);
  17. }
  18. void main()
  19. {
  20.     vec2 pos = InPosition - Camera.xy;
  21.     TilePosition = vec4(pos - 0.5f, pos + 0.5f) / Camera.zwzw;
  22.  
  23.     int back_delay =  int((InData.y >> 16) & 0xffffu);
  24.     int back_count =  int((InData.y >> 8) & 0xffu);
  25.     int back_dist =   int((InData.y) & 0xffu);
  26.     int back_offset = int((InData.x >> 16) & 0xffffu);
  27.    
  28.     int front_delay =  int((InData.w >> 16) & 0xffffu);
  29.     int front_count =  int((InData.w >> 8) & 0xffu);
  30.     int front_dist =   int((InData.w) & 0xffu);
  31.     int front_offset = int((InData.z >> 16) & 0xffffu);
  32.    
  33.     int back_time =  Time;
  34.     int front_time = Time;
  35.    
  36.     if (back_dist != 0)
  37.         back_time += abs((((InPosition.x ^ InPosition.y) % 100) * 100 + (InPosition.x << 8) *
  38.             (InPosition.y << 8) + (InPosition.x % 10) * 50 + (InPosition.y % 10) * 50) % 65536);
  39.     if (front_dist != 0)
  40.         front_time += abs((((InPosition.x ^ InPosition.y) % 100) * 100 + (InPosition.x << 8) *
  41.             (InPosition.y << 8) + (InPosition.x % 10) * 50 + (InPosition.y % 10) * 50) % 65536);
  42.  
  43.     TexIndexes = InIndexes + ivec2(((back_time / back_delay) % back_count) * back_offset,
  44.         ((front_time / front_delay) % front_count) * front_offset);
  45. }
  46.  
  47.  
  48. #shader geometry
  49. #version 330 core
  50.  
  51. layout (points) in;
  52. layout (triangle_strip, max_vertices = 4) out;
  53.  
  54. flat in vec4 TilePosition[1];
  55. flat in ivec2 TexIndexes[1];
  56.  
  57. out vec2 TexPixel;
  58. flat out ivec3 BackPixel;
  59. flat out ivec3 FrontPixel;
  60.  
  61. void main()
  62. {
  63.     if (TexIndexes[0].x >= 0) BackPixel = ivec3(TexIndexes[0].x % 64 * 16,
  64.         TexIndexes[0].x / 64 % 64 * 16, TexIndexes[0].x / 4096);
  65.     else BackPixel = ivec3(-1, -1, -1);
  66.     if (TexIndexes[0].y >= 0) FrontPixel = ivec3(TexIndexes[0].y % 64 * 16,
  67.         TexIndexes[0].y / 64 % 64 * 16, TexIndexes[0].y / 4096);
  68.     else FrontPixel = ivec3(-1, -1, -1);
  69.  
  70.     gl_Position = vec4(TilePosition[0].zy, 0.0f, 1.0f);
  71.     TexPixel = vec2(16.0f, 16.0f);
  72.     EmitVertex();
  73.     gl_Position = vec4(TilePosition[0].xy, 0.0f, 1.0f);
  74.     TexPixel = vec2(0.0f, 16.0f);
  75.     EmitVertex();
  76.     gl_Position = vec4(TilePosition[0].zw, 0.0f, 1.0f);
  77.     TexPixel = vec2(16.0f, 0.0f);
  78.     EmitVertex();
  79.     gl_Position = vec4(TilePosition[0].xw, 0.0f, 1.0f);
  80.     TexPixel = vec2(0.0f, 0.0f);
  81.     EmitVertex();
  82.     EndPrimitive();
  83. }
  84.  
  85.  
  86. #shader fragment
  87. #version 330 core
  88.  
  89. uniform sampler2DArray TextureArray;
  90.  
  91. in vec2 TexPixel;
  92. flat in ivec3 BackPixel;
  93. flat in ivec3 FrontPixel;
  94.  
  95. out vec4 FragColor;
  96.  
  97. void main()
  98. {
  99.     ivec3 offset = ivec3(TexPixel, 0);
  100.     if (offset.x >= 16) offset.x = 15;
  101.     if (offset.y >= 16) offset.y = 15;
  102.     if (offset.x < 0) offset.x = 0;
  103.     if (offset.y < 0) offset.y = 0;
  104.     vec4 BackFrag = vec4(0.0f, 0.0f, 0.0f, 0.0f);
  105.     if (BackPixel.x >= 0 && BackPixel.y >= 0) BackFrag =
  106.         texelFetch(TextureArray, BackPixel + offset, 0) * vec4(0.4f, 0.4f, 0.4f, 1.0f);
  107.     vec4 FrontFrag = vec4(0.0f, 0.0f, 0.0f, 0.0f);
  108.     if (FrontPixel.x >= 0 && FrontPixel.y >= 0) FrontFrag =
  109.         texelFetch(TextureArray, FrontPixel + offset, 0);
  110.     FragColor = mix(BackFrag, FrontFrag, FrontFrag.w);
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement