SelectionBase.bslinc 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. float4 selColor;
  21. float4 main(in float4 inPos : SV_Position) : SV_Target
  22. {
  23. return selColor;
  24. }
  25. };
  26. };
  27. };
  28. Technique
  29. #ifdef USE_BLEND_SHAPES
  30. #ifdef USE_SKELETON
  31. : base("SelectionSkinnedMorph")
  32. #else
  33. : base("SelectionMorph")
  34. #endif
  35. #else
  36. #ifdef USE_SKELETON
  37. : base("SelectionSkinned")
  38. #else
  39. : base("Selection")
  40. #endif
  41. #endif
  42. : inherits("SelectionBase") =
  43. {
  44. Vertex =
  45. {
  46. struct VertexInput
  47. {
  48. float3 position : POSITION;
  49. #ifdef USE_SKELETON
  50. uint4 blendIndices : BLENDINDICES;
  51. float4 blendWeights : BLENDWEIGHT;
  52. #endif
  53. #ifdef USE_BLEND_SHAPES
  54. float3 deltaPosition : POSITION1;
  55. float4 deltaNormal : NORMAL1;
  56. #endif
  57. };
  58. cbuffer VertParams
  59. {
  60. float4x4 matWorldViewProj;
  61. };
  62. #ifdef USE_SKELETON
  63. StructuredBuffer<float4> boneMatrices;
  64. float3x4 getBoneMatrix(uint idx)
  65. {
  66. float4 row0 = boneMatrices[idx * 3 + 0];
  67. float4 row1 = boneMatrices[idx * 3 + 1];
  68. float4 row2 = boneMatrices[idx * 3 + 2];
  69. return float3x4(row0, row1, row2);
  70. }
  71. float3x4 getBlendMatrix(VertexInput input)
  72. {
  73. float3x4 result = input.blendWeights.x * getBoneMatrix(input.blendIndices.x);
  74. result += input.blendWeights.y * getBoneMatrix(input.blendIndices.y);
  75. result += input.blendWeights.z * getBoneMatrix(input.blendIndices.z);
  76. result += input.blendWeights.w * getBoneMatrix(input.blendIndices.w);
  77. return result;
  78. }
  79. #endif
  80. void main(VertexInput input, out float4 oPosition : SV_Position)
  81. {
  82. #ifdef USE_BLEND_SHAPES
  83. float4 position = float4(input.position + input.deltaPosition, 1.0f);
  84. #else
  85. float4 position = float4(input.position, 1.0f);
  86. #endif
  87. #ifdef USE_SKELETON
  88. float3x4 blendMatrix = getBlendMatrix(input);
  89. position = float4(mul(blendMatrix, position), 1.0f);
  90. #endif
  91. oPosition = mul(matWorldViewProj, position);
  92. }
  93. };
  94. };