SelectionBase.bslinc 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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. layout(location = 0) out vec4 fragColor;
  109. layout(binding = 0) uniform FragUBO
  110. {
  111. vec4 selColor;
  112. };
  113. void main()
  114. {
  115. fragColor = selColor;
  116. }
  117. };
  118. };
  119. };
  120. Technique
  121. #ifdef USE_BLEND_SHAPES
  122. #ifdef USE_SKELETON
  123. : base("SelectionSkinnedMorph")
  124. #else
  125. : base("SelectionMorph")
  126. #endif
  127. #else
  128. #ifdef USE_SKELETON
  129. : base("SelectionSkinned")
  130. #else
  131. : base("Selection")
  132. #endif
  133. #endif
  134. : inherits("SelectionBase") =
  135. {
  136. Language = "GLSL";
  137. Vertex =
  138. {
  139. layout(location = 0) in vec3 bs_position;
  140. #ifdef USE_SKELETON
  141. layout(location = 1) in ivec4 bs_blendindices;
  142. layout(location = 2) in vec4 bs_blendweights;
  143. #endif
  144. #ifdef USE_BLEND_SHAPES
  145. layout(location = 3) in vec3 bs_position1;
  146. layout(location = 4) in vec4 bs_normal1;
  147. #endif
  148. out gl_PerVertex
  149. {
  150. vec4 gl_Position;
  151. };
  152. layout(binding = 1) uniform VertUBO
  153. {
  154. mat4 matWorldViewProj;
  155. };
  156. #ifdef USE_SKELETON
  157. layout(binding = 2) uniform samplerBuffer boneMatrices;
  158. void getBoneMatrix(int idx, out mat4x3 result)
  159. {
  160. mat3x4 temp;
  161. temp[0] = texelFetch(boneMatrices, idx * 3 + 0);
  162. temp[1] = texelFetch(boneMatrices, idx * 3 + 1);
  163. temp[2] = texelFetch(boneMatrices, idx * 3 + 2);
  164. result = transpose(temp);
  165. }
  166. void getBlendMatrix(out mat4x3 result)
  167. {
  168. mat4x3 boneMatrix;
  169. getBoneMatrix(bs_blendindices.x, boneMatrix);
  170. result = bs_blendweights.x * boneMatrix;
  171. getBoneMatrix(bs_blendindices.y, boneMatrix);
  172. result += bs_blendweights.y * boneMatrix;
  173. getBoneMatrix(bs_blendindices.z, boneMatrix);
  174. result += bs_blendweights.z * boneMatrix;
  175. getBoneMatrix(bs_blendindices.w, boneMatrix);
  176. result += bs_blendweights.w * boneMatrix;
  177. }
  178. #endif
  179. void main()
  180. {
  181. #ifdef USE_BLEND_SHAPES
  182. vec4 position = vec4(bs_position + bs_position1, 1.0f);
  183. #else
  184. vec4 position = vec4(bs_position, 1.0f);
  185. #endif
  186. #ifdef USE_SKELETON
  187. mat4x3 blendMatrix;
  188. getBlendMatrix(blendMatrix);
  189. position = vec4(blendMatrix * position, 1.0f);
  190. #endif
  191. gl_Position = matWorldViewProj * position;
  192. }
  193. };
  194. };