test.vert.glsl 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #version 330
  2. in vec3 vertex;
  3. in vec3 normal;
  4. in vec2 uv;
  5. in vec4 tangent;
  6. in ivec2 weights[6];
  7. uniform mat4 model;
  8. uniform mat4 view;
  9. uniform mat4 proj;
  10. uniform mat4 groups[52];
  11. out FS_IN {
  12. vec3 normal;
  13. vec2 uv;
  14. vec3 pos;
  15. vec4 tangent;
  16. } vs_out;
  17. section Animation {
  18. uniform bool skinned;
  19. };
  20. void main()
  21. {
  22. vs_out.uv = uv;
  23. vec3 v;
  24. vec3 n;
  25. vec3 t;
  26. int i = 0;
  27. v = vec3(0);
  28. n = vec3(0);
  29. t = vec3(0);
  30. if (skinned) {
  31. float total_weight = 0;
  32. for(i = 0; i < 6; i++) {
  33. float weight = (weights[i].y / (16535.0 * 0.5));
  34. total_weight += weight;
  35. int j = weights[i].x;
  36. if (j < 0)
  37. break;
  38. v += weight * (groups[j] * vec4(vertex,1)).xyz;
  39. n += weight * (groups[j] * vec4(normal, 0)).xyz;
  40. t += weight * (groups[j] * vec4(tangent.xyz, 0)).xyz;
  41. }
  42. v /= total_weight;
  43. n /= total_weight;
  44. } else {
  45. v = vertex;
  46. n = normal;
  47. t = tangent.xyz;
  48. }
  49. mat4 modelview = view * model;
  50. vs_out.normal = (modelview * vec4(n, 0)).xyz;
  51. vs_out.pos = (modelview * vec4(v, 0)).xyz;
  52. vs_out.tangent = vec4((modelview * vec4(tangent.xyz, 0)).xyz, tangent.w);
  53. gl_Position = proj * modelview * vec4(v, 1);
  54. }