Selection.bsl 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. Parameters =
  2. {
  3. mat4x4 matWorldViewProj;
  4. float4 selColor;
  5. StructBuffer boneMatrices;
  6. };
  7. Technique : base("SelectionBase") =
  8. {
  9. Language = "HLSL11";
  10. Pass =
  11. {
  12. Fill = WIRE;
  13. DepthBias = 0.00001f;
  14. Target =
  15. {
  16. Blend = true;
  17. Color = { SRCA, SRCIA, ADD };
  18. };
  19. Fragment =
  20. {
  21. float4 selColor;
  22. float4 main(in float4 inPos : SV_Position) : SV_Target
  23. {
  24. return selColor;
  25. }
  26. };
  27. };
  28. };
  29. Technique : inherits("SelectionBase") =
  30. {
  31. Language = "HLSL11";
  32. Vertex =
  33. {
  34. float4x4 matWorldViewProj;
  35. void main(
  36. in float3 inPos : POSITION,
  37. out float4 oPosition : SV_Position)
  38. {
  39. oPosition = mul(matWorldViewProj, float4(inPos.xyz, 1));
  40. }
  41. };
  42. };
  43. Technique : inherits("SelectionBase") =
  44. {
  45. Language = "HLSL11";
  46. Tags = { "Animated" };
  47. Vertex =
  48. {
  49. struct VertexInput
  50. {
  51. float3 position : POSITION;
  52. uint4 blendIndices : BLENDINDICES;
  53. float4 blendWeights : BLENDWEIGHT;
  54. #if USE_BLEND_SHAPES
  55. float3 deltaPosition : POSITION1;
  56. float4 deltaNormal : NORMAL1;
  57. #endif
  58. };
  59. StructuredBuffer<float4> boneMatrices;
  60. float4x4 matWorldViewProj;
  61. float3x4 getBoneMatrix(uint idx)
  62. {
  63. float4 row0 = boneMatrices[idx * 3 + 0];
  64. float4 row1 = boneMatrices[idx * 3 + 1];
  65. float4 row2 = boneMatrices[idx * 3 + 2];
  66. return float3x4(row0, row1, row2);
  67. }
  68. float3x4 getBlendMatrix(VertexInput input)
  69. {
  70. float3x4 result = input.blendWeights.x * getBoneMatrix(input.blendIndices.x);
  71. result += input.blendWeights.y * getBoneMatrix(input.blendIndices.y);
  72. result += input.blendWeights.z * getBoneMatrix(input.blendIndices.z);
  73. result += input.blendWeights.w * getBoneMatrix(input.blendIndices.w);
  74. return result;
  75. }
  76. void main(VertexInput input, out float4 oPosition : SV_Position)
  77. {
  78. float3x4 blendMatrix = getBlendMatrix(input);
  79. float4 position = float4(mul(blendMatrix, float4(input.position, 1.0f)), 1.0f);
  80. oPosition = mul(matWorldViewProj, position);
  81. }
  82. };
  83. };
  84. Technique : base("SelectionBase") =
  85. {
  86. Language = "GLSL";
  87. Pass =
  88. {
  89. Fill = WIRE;
  90. DepthBias = 0.00001f;
  91. Target =
  92. {
  93. Blend = true;
  94. Color = { SRCA, SRCIA, ADD };
  95. };
  96. Fragment =
  97. {
  98. uniform vec4 selColor;
  99. out vec4 fragColor;
  100. void main()
  101. {
  102. fragColor = selColor;
  103. }
  104. };
  105. };
  106. };
  107. Technique : inherits("SelectionBase") =
  108. {
  109. Language = "GLSL";
  110. Vertex =
  111. {
  112. uniform mat4 matWorldViewProj;
  113. in vec3 bs_position;
  114. out gl_PerVertex
  115. {
  116. vec4 gl_Position;
  117. };
  118. void main()
  119. {
  120. gl_Position = matWorldViewProj * vec4(bs_position.xyz, 1);
  121. }
  122. };
  123. };
  124. Technique : inherits("SelectionBase") =
  125. {
  126. Language = "GLSL";
  127. Tags = { "Animated" };
  128. Vertex =
  129. {
  130. uniform mat4 matWorldViewProj;
  131. in vec3 bs_position;
  132. in uvec4 bs_blendindices;
  133. in vec4 bs_blendweights;
  134. #if USE_BLEND_SHAPES
  135. in vec3 bs_position1;
  136. in vec4 bs_normal1;
  137. #endif
  138. uniform samplerBuffer boneMatrices;
  139. out gl_PerVertex
  140. {
  141. vec4 gl_Position;
  142. };
  143. void getBoneMatrix(uint idx, out mat4x3 result)
  144. {
  145. mat3x4 temp;
  146. temp[0] = texelFetch(boneMatrices, idx * 3 + 0);
  147. temp[1] = texelFetch(boneMatrices, idx * 3 + 1);
  148. temp[2] = texelFetch(boneMatrices, idx * 3 + 2);
  149. result = transpose(temp);
  150. }
  151. void getBlendMatrix(out mat4x3 result)
  152. {
  153. mat4x3 boneMatrix;
  154. getBoneMatrix(bs_blendindices.x, out boneMatrix);
  155. result = bs_blendweights.x * boneMatrix;
  156. getBoneMatrix(bs_blendindices.y, out boneMatrix);
  157. result += bs_blendweights.y * boneMatrix;
  158. getBoneMatrix(bs_blendindices.z, out boneMatrix);
  159. result += bs_blendweights.z * boneMatrix;
  160. getBoneMatrix(bs_blendindices.w, out boneMatrix);
  161. result += bs_blendweights.w * boneMatrix;
  162. }
  163. void main()
  164. {
  165. mat3x4 blendMatrix;
  166. getBlendMatrix(blendMatrix);
  167. vec4 position = vec4(blendMatrix * vec4(bs_position, 1.0f), 1.0f);
  168. gl_Position = matWorldViewProj * position;
  169. }
  170. };
  171. };