ccShader_3D_PositionTex.vert 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. const char* cc3D_PositionTex_vert = R"(
  2. attribute vec4 a_position;
  3. attribute vec2 a_texCoord;
  4. varying vec2 TextureCoordOut;
  5. void main(void)
  6. {
  7. gl_Position = CC_MVPMatrix * a_position;
  8. TextureCoordOut = a_texCoord;
  9. TextureCoordOut.y = 1.0 - TextureCoordOut.y;
  10. }
  11. )";
  12. const char* cc3D_SkinPositionTex_vert = R"(
  13. attribute vec3 a_position;
  14. attribute vec4 a_blendWeight;
  15. attribute vec4 a_blendIndex;
  16. attribute vec2 a_texCoord;
  17. const int SKINNING_JOINT_COUNT = 60;
  18. // Uniforms
  19. uniform vec4 u_matrixPalette[SKINNING_JOINT_COUNT * 3];
  20. // Varyings
  21. varying vec2 TextureCoordOut;
  22. vec4 getPosition()
  23. {
  24. float blendWeight = a_blendWeight[0];
  25. int matrixIndex = int (a_blendIndex[0]) * 3;
  26. vec4 matrixPalette1 = u_matrixPalette[matrixIndex] * blendWeight;
  27. vec4 matrixPalette2 = u_matrixPalette[matrixIndex + 1] * blendWeight;
  28. vec4 matrixPalette3 = u_matrixPalette[matrixIndex + 2] * blendWeight;
  29. blendWeight = a_blendWeight[1];
  30. if (blendWeight > 0.0)
  31. {
  32. matrixIndex = int(a_blendIndex[1]) * 3;
  33. matrixPalette1 += u_matrixPalette[matrixIndex] * blendWeight;
  34. matrixPalette2 += u_matrixPalette[matrixIndex + 1] * blendWeight;
  35. matrixPalette3 += u_matrixPalette[matrixIndex + 2] * blendWeight;
  36. blendWeight = a_blendWeight[2];
  37. if (blendWeight > 0.0)
  38. {
  39. matrixIndex = int(a_blendIndex[2]) * 3;
  40. matrixPalette1 += u_matrixPalette[matrixIndex] * blendWeight;
  41. matrixPalette2 += u_matrixPalette[matrixIndex + 1] * blendWeight;
  42. matrixPalette3 += u_matrixPalette[matrixIndex + 2] * blendWeight;
  43. blendWeight = a_blendWeight[3];
  44. if (blendWeight > 0.0)
  45. {
  46. matrixIndex = int(a_blendIndex[3]) * 3;
  47. matrixPalette1 += u_matrixPalette[matrixIndex] * blendWeight;
  48. matrixPalette2 += u_matrixPalette[matrixIndex + 1] * blendWeight;
  49. matrixPalette3 += u_matrixPalette[matrixIndex + 2] * blendWeight;
  50. }
  51. }
  52. }
  53. vec4 _skinnedPosition;
  54. vec4 position = vec4(a_position, 1.0);
  55. _skinnedPosition.x = dot(position, matrixPalette1);
  56. _skinnedPosition.y = dot(position, matrixPalette2);
  57. _skinnedPosition.z = dot(position, matrixPalette3);
  58. _skinnedPosition.w = position.w;
  59. return _skinnedPosition;
  60. }
  61. void main()
  62. {
  63. vec4 position = getPosition();
  64. gl_Position = CC_MVPMatrix * position;
  65. TextureCoordOut = a_texCoord;
  66. TextureCoordOut.y = 1.0 - TextureCoordOut.y;
  67. }
  68. )";