basicEntity.vert 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #version 430 core
  2. layout(location = 0) in vec3 shape;
  3. layout(location = 1) in vec3 normal;
  4. layout(location = 2) in vec2 uv;
  5. layout(location = 3) in int bone;
  6. layout(location = 4) in int textureIndex;
  7. uniform mat4 u_viewProjection;
  8. uniform mat4 u_modelMatrix;
  9. uniform ivec3 u_cameraPositionInt;
  10. uniform vec3 u_cameraPositionFloat;
  11. uniform int u_bonesPerModel;
  12. out vec2 v_uv;
  13. out vec3 v_vertexPosition;
  14. out vec3 v_normals;
  15. out vec3 v_color;
  16. flat out int test;
  17. readonly restrict layout(std430) buffer u_skinningMatrix
  18. {
  19. mat4 skinningMatrix[];
  20. };
  21. struct PerEntityData
  22. {
  23. int entityPositionIntX;
  24. int entityPositionIntY;
  25. int entityPositionIntZ;
  26. float entityPositionFloatX;
  27. float entityPositionFloatY;
  28. float entityPositionFloatZ;
  29. float colorR;
  30. float colorG;
  31. float colorB;
  32. float lightLevels;
  33. uvec2 textureSampler0;
  34. uvec2 textureSampler1;
  35. uvec2 textureSampler2;
  36. uvec2 textureSampler3;
  37. };
  38. flat out uvec2 v_textureSampler;
  39. readonly restrict layout(std430) buffer u_perEntityData
  40. {
  41. PerEntityData entityData[];
  42. };
  43. void main()
  44. {
  45. ivec3 entityPosInt = ivec3(entityData[gl_InstanceID].entityPositionIntX, entityData[gl_InstanceID].entityPositionIntY, entityData[gl_InstanceID].entityPositionIntZ);
  46. vec3 entityPosFloat = vec3(entityData[gl_InstanceID].entityPositionFloatX, entityData[gl_InstanceID].entityPositionFloatY, entityData[gl_InstanceID].entityPositionFloatZ);
  47. v_color = vec3(entityData[gl_InstanceID].colorR, entityData[gl_InstanceID].colorG, entityData[gl_InstanceID].colorB);
  48. v_color *= max(entityData[gl_InstanceID].lightLevels/15.0, 0.1);
  49. if(textureIndex == 1) {v_textureSampler = entityData[gl_InstanceID].textureSampler1;} else
  50. if(textureIndex == 2) {v_textureSampler = entityData[gl_InstanceID].textureSampler2;} else
  51. if(textureIndex == 3) {v_textureSampler = entityData[gl_InstanceID].textureSampler3;} else
  52. {v_textureSampler = entityData[gl_InstanceID].textureSampler0;}
  53. vec3 diffI = entityPosInt - u_cameraPositionInt;
  54. vec3 diffF = diffI - u_cameraPositionFloat + entityPosFloat;
  55. mat4 currentSkinningMatrix = skinningMatrix[bone + gl_InstanceID * u_bonesPerModel];
  56. test = bone;
  57. mat4 finalModel = u_modelMatrix * currentSkinningMatrix;
  58. vec4 posViewSemi = vec4(diffF + vec3(finalModel * vec4(shape, 1)), 1);
  59. vec4 posProjection = u_viewProjection * posViewSemi;
  60. gl_Position = posProjection;
  61. v_uv = uv;
  62. v_vertexPosition = posViewSemi.xyz;
  63. v_normals = normalize((transpose(inverse(finalModel)) * vec4(normal, 0.0)).xyz);
  64. }