defaultShader.vert 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. #version 430 core
  2. layout(location = 0) in int in_faceOrientation; //up down left etc
  3. layout(location = 1) in int in_textureIndex; //dirt grass stone etc
  4. layout(location = 2) in ivec3 in_facePosition; // int x y z
  5. layout(location = 3) in int in_skyLight;
  6. uniform mat4 u_viewProjection;
  7. uniform ivec3 u_positionInt;
  8. uniform vec3 u_positionFloat;
  9. uniform float u_time;
  10. float vertexColor[] = float[](
  11. //front
  12. 0.9,
  13. //back
  14. 0.8,
  15. //top
  16. 1.0,
  17. //bottom
  18. 0.7,
  19. //left
  20. 0.8,
  21. //right
  22. 0.9,
  23. //grass
  24. 0.9,
  25. 0.9,
  26. 0.9,
  27. 0.9,
  28. // leaves
  29. //front
  30. 0.9,
  31. //back
  32. 0.8,
  33. //top
  34. 1.0,
  35. //bottom
  36. 0.7,
  37. //left
  38. 0.8,
  39. //right
  40. 0.9
  41. );
  42. //geometry
  43. readonly restrict layout(std430) buffer u_vertexData
  44. {
  45. float vertexData[];
  46. };
  47. readonly restrict layout(std430) buffer u_vertexUV
  48. {
  49. float vertexUV[];
  50. };
  51. readonly restrict layout(std430) buffer u_textureSamplerers
  52. {
  53. uvec2 textureSamplerers[];
  54. };
  55. out vec2 v_uv;
  56. out float v_color;
  57. out flat uvec2 v_textureSampler;
  58. void main()
  59. {
  60. ivec3 intPosition = in_facePosition - u_positionInt;
  61. vec3 floatPosition = intPosition - u_positionFloat;
  62. vec4 pos = vec4(floatPosition.xyz,1);
  63. vec3 vertexShape;
  64. v_uv.x = vertexUV[(in_faceOrientation) * 2 * 6 + gl_VertexID * 2 + 0];
  65. v_uv.y = vertexUV[(in_faceOrientation) * 2 * 6 + gl_VertexID * 2 + 1];
  66. vertexShape.x = vertexData[in_faceOrientation * 3 * 6 + gl_VertexID * 3 + 0];
  67. vertexShape.y = vertexData[in_faceOrientation * 3 * 6 + gl_VertexID * 3 + 1];
  68. vertexShape.z = vertexData[in_faceOrientation * 3 * 6 + gl_VertexID * 3 + 2];
  69. if(in_faceOrientation >= 10) //animated
  70. {
  71. if(in_facePosition.y % 2 == 0)
  72. {
  73. vertexShape.x = -vertexShape.x;
  74. vertexShape.z = -vertexShape.z;
  75. //v_uv.x = 1.f-v_uv.x;
  76. }
  77. vertexShape.x += vertexData[(in_faceOrientation-10) * 3 * 6 + gl_VertexID * 3 + 0];
  78. vertexShape.y += vertexData[(in_faceOrientation-10) * 3 * 6 + gl_VertexID * 3 + 1];
  79. vertexShape.z += vertexData[(in_faceOrientation-10) * 3 * 6 + gl_VertexID * 3 + 2];
  80. //if(in_faceOrientation == 6)
  81. //{//front
  82. //
  83. //}else if(in_faceOrientation == 7)
  84. //{//back
  85. //
  86. //}else if(in_faceOrientation == 8)
  87. //{//top
  88. //
  89. //}else if(in_faceOrientation == 9)
  90. //{//bottom
  91. //
  92. //}else if(in_faceOrientation == 10)
  93. //{//left
  94. //
  95. //}else if(in_faceOrientation == 11)
  96. //{//right
  97. //
  98. //}
  99. //vertexShape *= 0.8+((sin(u_time)+1)/2.f)*0.2;
  100. }
  101. pos.xyz += vertexShape;
  102. pos = u_viewProjection * pos;
  103. gl_Position = pos;
  104. v_color = vertexColor[in_faceOrientation] * (in_skyLight/15.f);
  105. //v_color = vertexColor[in_faceOrientation];
  106. v_textureSampler = textureSamplerers[in_textureIndex];
  107. }