cc-skinning.chunk 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright (c) 2017-2020 Xiamen Yaji Software Co., Ltd.
  2. #pragma extension([GL_EXT_shader_explicit_arithmetic_types_int32, __VERSION__ > 310, require])
  3. #if CC_USE_BAKED_ANIMATION
  4. #pragma builtin(local)
  5. layout(set = 2, binding = 3) uniform CCSkinningTexture {
  6. highp vec4 cc_jointTextureInfo; // length, totalJoints, offset, invLength
  7. };
  8. #pragma builtin(local)
  9. layout(set = 2, binding = 2) uniform CCSkinningAnimation {
  10. highp vec4 cc_jointAnimInfo; // frameID
  11. };
  12. #pragma builtin(local)
  13. layout(set = 2, binding = 7) uniform highp sampler2D cc_jointTexture;
  14. /**
  15. * Although tempting, don't opt the offset arithmetics out to CPU (could
  16. * be reduced to a single MAD). The enlarged numerical range could require
  17. * more precision than what's actually provided on some devices.
  18. */
  19. void CCGetJointTextureCoords(float pixelsPerJoint, float jointIdx, out highp float x, out highp float y, out highp float invSize)
  20. {
  21. #if USE_INSTANCING
  22. highp float temp = pixelsPerJoint * (a_jointAnimInfo.x * a_jointAnimInfo.y + jointIdx) + a_jointAnimInfo.z;
  23. #else
  24. highp float temp = pixelsPerJoint * (cc_jointAnimInfo.x * cc_jointTextureInfo.y + jointIdx) + cc_jointTextureInfo.z;
  25. #endif
  26. invSize = cc_jointTextureInfo.w;
  27. highp float tempY = floor(temp * invSize);
  28. x = floor(temp - tempY * cc_jointTextureInfo.x);
  29. y = (tempY + 0.5) * invSize;
  30. }
  31. #else
  32. #if CC_USE_REAL_TIME_JOINT_TEXTURE
  33. #pragma builtin(local)
  34. layout(set = 2, binding = 7) uniform highp sampler2D cc_realtimeJoint;
  35. #else
  36. #pragma builtin(local)
  37. layout(set = 2, binding = 3) uniform CCSkinning {
  38. highp vec4 cc_joints[CC_JOINT_UNIFORM_CAPACITY * 3];
  39. };
  40. #endif
  41. #endif