2
0

geometryPass_optimized.vert 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #version 430
  2. #pragma debug(on)
  3. layout(location = 0) in vec3 a_positions;
  4. layout(location = 1) in vec3 a_normals;
  5. layout(location = 2) in vec2 a_texCoord;
  6. layout(location = 3) in ivec4 a_jointsId;
  7. layout(location = 4) in vec4 a_weights;
  8. uniform mat4 u_transform; //full model view projection
  9. uniform mat4 u_modelTransform; //just model to world
  10. uniform mat4 u_motelViewTransform; //model to world to view
  11. out vec3 v_normals;
  12. out vec2 v_texCoord;
  13. out vec3 v_positionViewSpace;
  14. readonly restrict layout(std140) buffer u_jointTransforms
  15. {
  16. mat4 jointTransforms[];
  17. };
  18. uniform int u_hasAnimations;
  19. void main()
  20. {
  21. vec4 totalLocalPos = vec4(0.f);
  22. vec4 totalNorm = vec4(0.f);
  23. if(u_hasAnimations != 0)
  24. {
  25. for(int i=0; i<4; i++)
  26. {
  27. if(a_jointsId[i] < 0){break;}
  28. mat4 jointTransform = jointTransforms[a_jointsId[i]];
  29. vec4 posePosition = jointTransform * vec4(a_positions, 1);
  30. totalLocalPos += posePosition * a_weights[i];
  31. vec3 worldNormal = mat3(transpose(inverse(mat3(jointTransform)))) * a_normals.xyz;// jointTransform * vec4(a_normals, 1);
  32. totalNorm.xyz += worldNormal.xyz * a_weights[i];
  33. }
  34. totalNorm.xyz = normalize(totalNorm.xyz);
  35. }else
  36. {
  37. totalLocalPos = vec4(a_positions, 1.f);
  38. totalNorm = vec4(a_normals, 1);
  39. }
  40. v_positionViewSpace = vec3(u_motelViewTransform * totalLocalPos);
  41. gl_Position = u_transform * totalLocalPos;
  42. //v_normals = (u_modelTransform * vec4(a_normals,0)).xyz; //uniform scale
  43. v_normals = mat3(transpose(inverse(mat3(u_modelTransform)))) * totalNorm.xyz; //non uniform scale
  44. v_normals = normalize(v_normals);
  45. v_texCoord = a_texCoord;
  46. }