SelectionBase.bslinc 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. Parameters =
  2. {
  3. mat4x4 matWorldViewProj;
  4. float4 selColor;
  5. StructBuffer boneMatrices;
  6. };
  7. Technique : base("SelectionBase") =
  8. {
  9. Pass =
  10. {
  11. Fill = WIRE;
  12. DepthBias = 0.00001f;
  13. Target =
  14. {
  15. Blend = true;
  16. Color = { SRCA, SRCIA, ADD };
  17. };
  18. Fragment =
  19. {
  20. cbuffer FragParams
  21. {
  22. float4 selColor;
  23. };
  24. float4 main(in float4 inPos : SV_Position) : SV_Target
  25. {
  26. return selColor;
  27. }
  28. };
  29. };
  30. };
  31. Technique
  32. #ifdef USE_BLEND_SHAPES
  33. #ifdef USE_SKELETON
  34. : base("SelectionSkinnedMorph")
  35. #else
  36. : base("SelectionMorph")
  37. #endif
  38. #else
  39. #ifdef USE_SKELETON
  40. : base("SelectionSkinned")
  41. #else
  42. : base("Selection")
  43. #endif
  44. #endif
  45. : inherits("SelectionBase") =
  46. {
  47. Vertex =
  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 main(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. };