SelectionBase.bslinc 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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
  30. #ifdef USE_BLEND_SHAPES
  31. #ifdef USE_SKELETON
  32. : base("SelectionSkinnedMorph")
  33. #else
  34. : base("SelectionMorph")
  35. #endif
  36. #else
  37. #ifdef USE_SKELETON
  38. : base("SelectionSkinned")
  39. #else
  40. : base("Selection")
  41. #endif
  42. #endif
  43. : inherits("SelectionBase") =
  44. {
  45. Language = "HLSL11";
  46. Vertex =
  47. {
  48. struct VertexInput
  49. {
  50. float3 position : POSITION;
  51. #ifdef USE_SKELETON
  52. uint4 blendIndices : BLENDINDICES;
  53. float4 blendWeights : BLENDWEIGHT;
  54. #endif
  55. #ifdef USE_BLEND_SHAPES
  56. float3 deltaPosition : POSITION1;
  57. float4 deltaNormal : NORMAL1;
  58. #endif
  59. };
  60. float4x4 matWorldViewProj;
  61. #ifdef USE_SKELETON
  62. StructuredBuffer<float4> boneMatrices;
  63. float3x4 getBoneMatrix(uint idx)
  64. {
  65. float4 row0 = boneMatrices[idx * 3 + 0];
  66. float4 row1 = boneMatrices[idx * 3 + 1];
  67. float4 row2 = boneMatrices[idx * 3 + 2];
  68. return float3x4(row0, row1, row2);
  69. }
  70. float3x4 getBlendMatrix(VertexInput input)
  71. {
  72. float3x4 result = input.blendWeights.x * getBoneMatrix(input.blendIndices.x);
  73. result += input.blendWeights.y * getBoneMatrix(input.blendIndices.y);
  74. result += input.blendWeights.z * getBoneMatrix(input.blendIndices.z);
  75. result += input.blendWeights.w * getBoneMatrix(input.blendIndices.w);
  76. return result;
  77. }
  78. #endif
  79. void main(VertexInput input, out float4 oPosition : SV_Position)
  80. {
  81. #ifdef USE_BLEND_SHAPES
  82. float4 position = float4(input.position + input.deltaPosition, 1.0f);
  83. #else
  84. float4 position = float4(input.position, 1.0f);
  85. #endif
  86. #ifdef USE_SKELETON
  87. float3x4 blendMatrix = getBlendMatrix(input);
  88. position = float4(mul(blendMatrix, position), 1.0f);
  89. #endif
  90. oPosition = mul(matWorldViewProj, position);
  91. }
  92. };
  93. };
  94. Technique : base("SelectionBase") =
  95. {
  96. Language = "GLSL";
  97. Pass =
  98. {
  99. Fill = WIRE;
  100. DepthBias = 0.00001f;
  101. Target =
  102. {
  103. Blend = true;
  104. Color = { SRCA, SRCIA, ADD };
  105. };
  106. Fragment =
  107. {
  108. uniform vec4 selColor;
  109. out vec4 fragColor;
  110. void main()
  111. {
  112. fragColor = selColor;
  113. }
  114. };
  115. };
  116. };
  117. Technique
  118. #ifdef USE_BLEND_SHAPES
  119. #ifdef USE_SKELETON
  120. : base("SelectionSkinnedMorph")
  121. #else
  122. : base("SelectionMorph")
  123. #endif
  124. #else
  125. #ifdef USE_SKELETON
  126. : base("SelectionSkinned")
  127. #else
  128. : base("Selection")
  129. #endif
  130. #endif
  131. : inherits("SelectionBase") =
  132. {
  133. Language = "GLSL";
  134. Vertex =
  135. {
  136. uniform mat4 matWorldViewProj;
  137. in vec3 bs_position;
  138. #ifdef USE_SKELETON
  139. in uvec4 bs_blendindices;
  140. in vec4 bs_blendweights;
  141. #endif
  142. #ifdef USE_BLEND_SHAPES
  143. in vec3 bs_position1;
  144. in vec4 bs_normal1;
  145. #endif
  146. out gl_PerVertex
  147. {
  148. vec4 gl_Position;
  149. };
  150. #ifdef USE_SKELETON
  151. uniform samplerBuffer boneMatrices;
  152. void getBoneMatrix(uint idx, out mat4x3 result)
  153. {
  154. mat3x4 temp;
  155. temp[0] = texelFetch(boneMatrices, idx * 3 + 0);
  156. temp[1] = texelFetch(boneMatrices, idx * 3 + 1);
  157. temp[2] = texelFetch(boneMatrices, idx * 3 + 2);
  158. result = transpose(temp);
  159. }
  160. void getBlendMatrix(out mat4x3 result)
  161. {
  162. mat4x3 boneMatrix;
  163. getBoneMatrix(bs_blendindices.x, out boneMatrix);
  164. result = bs_blendweights.x * boneMatrix;
  165. getBoneMatrix(bs_blendindices.y, out boneMatrix);
  166. result += bs_blendweights.y * boneMatrix;
  167. getBoneMatrix(bs_blendindices.z, out boneMatrix);
  168. result += bs_blendweights.z * boneMatrix;
  169. getBoneMatrix(bs_blendindices.w, out boneMatrix);
  170. result += bs_blendweights.w * boneMatrix;
  171. }
  172. #endif
  173. void main()
  174. {
  175. #ifdef USE_BLEND_SHAPES
  176. vec4 position = vec4(bs_position + bs_position1, 1.0f);
  177. #else
  178. vec4 position = vec4(bs_position, 1.0f);
  179. #endif
  180. #ifdef USE_SKELETON
  181. mat3x4 blendMatrix;
  182. getBlendMatrix(blendMatrix);
  183. position = vec4(blendMatrix * position, 1.0f);
  184. #endif
  185. gl_Position = matWorldViewProj * position;
  186. }
  187. };
  188. };