SelectionBase.bslinc 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. mixin SelectionBase
  2. {
  3. raster
  4. {
  5. fill = wire;
  6. };
  7. depth
  8. {
  9. bias = 0.00001f;
  10. };
  11. blend
  12. {
  13. target
  14. {
  15. enabled = true;
  16. color = { srcA, srcIA, add };
  17. };
  18. };
  19. code
  20. {
  21. cbuffer FragParams
  22. {
  23. float4 selColor;
  24. };
  25. float4 fsmain(in float4 inPos : SV_Position) : SV_Target
  26. {
  27. return selColor;
  28. }
  29. };
  30. };
  31. mixin
  32. #ifdef USE_BLEND_SHAPES
  33. #ifdef USE_SKELETON
  34. SelectionSkinnedMorph
  35. #else
  36. SelectionMorph
  37. #endif
  38. #else
  39. #ifdef USE_SKELETON
  40. SelectionSkinned
  41. #else
  42. Selection
  43. #endif
  44. #endif
  45. {
  46. mixin SelectionBase;
  47. code
  48. {
  49. struct VertexInput
  50. {
  51. float3 position : POSITION;
  52. #ifdef USE_SKELETON
  53. uint4 blendIndices : BLENDINDICES;
  54. float4 blendWeights : BLENDWEIGHT;
  55. #endif
  56. #ifdef USE_BLEND_SHAPES
  57. float3 deltaPosition : POSITION1;
  58. float4 deltaNormal : NORMAL1;
  59. #endif
  60. };
  61. cbuffer VertParams
  62. {
  63. float4x4 matWorldViewProj;
  64. };
  65. #ifdef USE_SKELETON
  66. StructuredBuffer<float4> boneMatrices;
  67. float3x4 getBoneMatrix(uint idx)
  68. {
  69. float4 row0 = boneMatrices[idx * 3 + 0];
  70. float4 row1 = boneMatrices[idx * 3 + 1];
  71. float4 row2 = boneMatrices[idx * 3 + 2];
  72. return float3x4(row0, row1, row2);
  73. }
  74. float3x4 getBlendMatrix(VertexInput input)
  75. {
  76. float3x4 result = input.blendWeights.x * getBoneMatrix(input.blendIndices.x);
  77. result += input.blendWeights.y * getBoneMatrix(input.blendIndices.y);
  78. result += input.blendWeights.z * getBoneMatrix(input.blendIndices.z);
  79. result += input.blendWeights.w * getBoneMatrix(input.blendIndices.w);
  80. return result;
  81. }
  82. #endif
  83. void vsmain(VertexInput input, out float4 oPosition : SV_Position)
  84. {
  85. #ifdef USE_BLEND_SHAPES
  86. float4 position = float4(input.position + input.deltaPosition, 1.0f);
  87. #else
  88. float4 position = float4(input.position, 1.0f);
  89. #endif
  90. #ifdef USE_SKELETON
  91. float3x4 blendMatrix = getBlendMatrix(input);
  92. position = float4(mul(blendMatrix, position), 1.0f);
  93. #endif
  94. oPosition = mul(matWorldViewProj, position);
  95. }
  96. };
  97. };