sp_skinning_shadow.vert 4.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. uniform int layer;
  2. #ifdef GL_ES
  3. uniform sampler2D skinning_tex;
  4. #else
  5. uniform samplerBuffer skinning_tex;
  6. #endif
  7. layout(location = 0) in vec3 i_position;
  8. layout(location = 3) in vec2 i_uv;
  9. layout(location = 6) in ivec4 i_joint;
  10. layout(location = 7) in vec4 i_weight;
  11. layout(location = 8) in vec3 i_origin;
  12. layout(location = 9) in vec4 i_rotation;
  13. layout(location = 10) in vec4 i_scale;
  14. layout(location = 12) in ivec2 i_misc_data;
  15. #stk_include "utils/get_world_location.vert"
  16. out vec2 uv;
  17. void main()
  18. {
  19. vec4 idle_position = vec4(i_position, 1.0);
  20. vec4 skinned_position = vec4(0.0);
  21. int skinning_offset = i_misc_data.x;
  22. #ifdef GL_ES
  23. mat4 joint_matrix =
  24. i_weight[0] * mat4(
  25. texelFetch(skinning_tex, ivec2(0, clamp(i_joint[0] + skinning_offset, 0, MAX_BONES)), 0),
  26. texelFetch(skinning_tex, ivec2(1, clamp(i_joint[0] + skinning_offset, 0, MAX_BONES)), 0),
  27. texelFetch(skinning_tex, ivec2(2, clamp(i_joint[0] + skinning_offset, 0, MAX_BONES)), 0),
  28. texelFetch(skinning_tex, ivec2(3, clamp(i_joint[0] + skinning_offset, 0, MAX_BONES)), 0)) +
  29. i_weight[1] * mat4(
  30. texelFetch(skinning_tex, ivec2(0, clamp(i_joint[1] + skinning_offset, 0, MAX_BONES)), 0),
  31. texelFetch(skinning_tex, ivec2(1, clamp(i_joint[1] + skinning_offset, 0, MAX_BONES)), 0),
  32. texelFetch(skinning_tex, ivec2(2, clamp(i_joint[1] + skinning_offset, 0, MAX_BONES)), 0),
  33. texelFetch(skinning_tex, ivec2(3, clamp(i_joint[1] + skinning_offset, 0, MAX_BONES)), 0)) +
  34. i_weight[2] * mat4(
  35. texelFetch(skinning_tex, ivec2(0, clamp(i_joint[2] + skinning_offset, 0, MAX_BONES)), 0),
  36. texelFetch(skinning_tex, ivec2(1, clamp(i_joint[2] + skinning_offset, 0, MAX_BONES)), 0),
  37. texelFetch(skinning_tex, ivec2(2, clamp(i_joint[2] + skinning_offset, 0, MAX_BONES)), 0),
  38. texelFetch(skinning_tex, ivec2(3, clamp(i_joint[2] + skinning_offset, 0, MAX_BONES)), 0)) +
  39. i_weight[3] * mat4(
  40. texelFetch(skinning_tex, ivec2(0, clamp(i_joint[3] + skinning_offset, 0, MAX_BONES)), 0),
  41. texelFetch(skinning_tex, ivec2(1, clamp(i_joint[3] + skinning_offset, 0, MAX_BONES)), 0),
  42. texelFetch(skinning_tex, ivec2(2, clamp(i_joint[3] + skinning_offset, 0, MAX_BONES)), 0),
  43. texelFetch(skinning_tex, ivec2(3, clamp(i_joint[3] + skinning_offset, 0, MAX_BONES)), 0));
  44. #else
  45. mat4 joint_matrix =
  46. i_weight[0] * mat4(
  47. texelFetch(skinning_tex, clamp(i_joint[0] + skinning_offset, 0, MAX_BONES) * 4),
  48. texelFetch(skinning_tex, clamp(i_joint[0] + skinning_offset, 0, MAX_BONES) * 4 + 1),
  49. texelFetch(skinning_tex, clamp(i_joint[0] + skinning_offset, 0, MAX_BONES) * 4 + 2),
  50. texelFetch(skinning_tex, clamp(i_joint[0] + skinning_offset, 0, MAX_BONES) * 4 + 3)) +
  51. i_weight[1] * mat4(
  52. texelFetch(skinning_tex, clamp(i_joint[1] + skinning_offset, 0, MAX_BONES) * 4),
  53. texelFetch(skinning_tex, clamp(i_joint[1] + skinning_offset, 0, MAX_BONES) * 4 + 1),
  54. texelFetch(skinning_tex, clamp(i_joint[1] + skinning_offset, 0, MAX_BONES) * 4 + 2),
  55. texelFetch(skinning_tex, clamp(i_joint[1] + skinning_offset, 0, MAX_BONES) * 4 + 3)) +
  56. i_weight[2] * mat4(
  57. texelFetch(skinning_tex, clamp(i_joint[2] + skinning_offset, 0, MAX_BONES) * 4),
  58. texelFetch(skinning_tex, clamp(i_joint[2] + skinning_offset, 0, MAX_BONES) * 4 + 1),
  59. texelFetch(skinning_tex, clamp(i_joint[2] + skinning_offset, 0, MAX_BONES) * 4 + 2),
  60. texelFetch(skinning_tex, clamp(i_joint[2] + skinning_offset, 0, MAX_BONES) * 4 + 3)) +
  61. i_weight[3] * mat4(
  62. texelFetch(skinning_tex, clamp(i_joint[3] + skinning_offset, 0, MAX_BONES) * 4),
  63. texelFetch(skinning_tex, clamp(i_joint[3] + skinning_offset, 0, MAX_BONES) * 4 + 1),
  64. texelFetch(skinning_tex, clamp(i_joint[3] + skinning_offset, 0, MAX_BONES) * 4 + 2),
  65. texelFetch(skinning_tex, clamp(i_joint[3] + skinning_offset, 0, MAX_BONES) * 4 + 3));
  66. #endif
  67. skinned_position = joint_matrix * idle_position;
  68. vec4 world_position = getWorldPosition(i_origin, i_rotation, i_scale.xyz,
  69. skinned_position.xyz);
  70. uv = i_uv;
  71. gl_Position = u_shadow_projection_view_matrices[layer] * world_position;
  72. }