HairSimulationComputeSrgs.azsli 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /*
  2. * Modifications Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. //-----------------------------------------------------------------------------------------------------------
  9. //
  10. // Copyright (c) 2019 Advanced Micro Devices, Inc. All rights reserved.
  11. //
  12. // Permission is hereby granted, free of charge, to any person obtaining a copy
  13. // of this software and associated documentation files (the "Software"), to deal
  14. // in the Software without restriction, including without limitation the rights
  15. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  16. // copies of the Software, and to permit persons to whom the Software is
  17. // furnished to do so, subject to the following conditions:
  18. //
  19. // The above copyright notice and this permission notice shall be included in
  20. // all copies or substantial portions of the Software.
  21. //
  22. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  23. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  24. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  25. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  26. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  27. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  28. // THE SOFTWARE.
  29. //
  30. //------------------------------------------------------------------------------
  31. // File: HairSimulationComputeSrgs.azsli
  32. //
  33. // Declarations of SRGs used by the hair shaders.
  34. //------------------------------------------------------------------------------
  35. #pragma once
  36. #include <HairComputeSrgs.azsli>
  37. //!-----------------------------------------------------------------------------
  38. //!
  39. //! Skinning / Simulation Render Usage
  40. //! Per Objects Space 0 - Static Buffers for Hair Generation
  41. //!
  42. //! ----------------------------------------------------------------------------
  43. struct TressFXSimulationParams
  44. {
  45. float4 m_Wind;
  46. float4 m_Wind1;
  47. float4 m_Wind2;
  48. float4 m_Wind3;
  49. float4 m_Shape; // damping, local stiffness, global stiffness, global range.
  50. float4 m_GravTimeTip; // gravity maginitude (assumed to be in negative y direction.)
  51. int4 m_SimInts; // Length iterations, local iterations, collision flag.
  52. int4 m_Counts; // num strands per thread group, num follow hairs per guid hair, num verts per strand.
  53. float4 m_VSP; // VSP parameters - controls how Velocity Shock Propogation will dictate how
  54. // fast velocities are handled and can be compensated using the hair root velocity
  55. float m_ResetPositions;
  56. float m_ClampPositionDelta;
  57. float m_pad1;
  58. float m_pad2;
  59. #if TRESSFX_DQ // this option is currently not functional
  60. float4 m_BoneSkinningDQ[AMD_TRESSFX_MAX_NUM_BONES * 2];
  61. #else
  62. row_major float4x4 m_BoneSkinningMatrix[AMD_TRESSFX_MAX_NUM_BONES];
  63. #endif
  64. };
  65. struct BoneSkinningData
  66. {
  67. float4 boneIndex; // x, y, z and w component are four bone indices per strand
  68. float4 boneWeight; // x, y, z and w component are four bone weights per strand
  69. };
  70. //!------------------------------ SRG Structure --------------------------------
  71. //! This is the static Srg required for the hair genration per hair object draw.
  72. //! The data is used only for skinning / simulation and doesn't change between
  73. //! the object's passes.
  74. //! To match to the original TressFX naming follow the global defines bellow.
  75. ShaderResourceGroup HairGenerationSrg : SRG_PerDraw
  76. {
  77. // Buffers containing hair generation properties.
  78. Buffer<float4> m_initialHairPositions;
  79. Buffer<float> m_hairRestLengthSRV;
  80. Buffer<float> m_hairStrandType;
  81. Buffer<float4> m_followHairRootOffset;
  82. StructuredBuffer<BoneSkinningData> m_boneSkinningData;
  83. // Constant buffer structure reflected in code as 'TressFXSimulationParams'
  84. TressFXSimulationParams m_tressfxSimParameters;
  85. };
  86. //------------------------------------------------------------------------------
  87. // Allow for the code to run with minimal changes - compute passes usage
  88. #define g_InitialHairPositions HairGenerationSrg::m_initialHairPositions
  89. #define g_HairRestLengthSRV HairGenerationSrg::m_hairRestLengthSRV
  90. #define g_HairStrandType HairGenerationSrg::m_hairStrandType
  91. #define g_FollowHairRootOffset HairGenerationSrg::m_followHairRootOffset
  92. #define g_BoneSkinningData HairGenerationSrg::m_boneSkinningData
  93. #define g_NumOfStrandsPerThreadGroup HairGenerationSrg::m_tressfxSimParameters.m_Counts.x
  94. #define g_NumFollowHairsPerGuideHair HairGenerationSrg::m_tressfxSimParameters.m_Counts.y
  95. #define g_NumVerticesPerStrand HairGenerationSrg::m_tressfxSimParameters.m_Counts.z
  96. #define g_NumLocalShapeMatchingIterations HairGenerationSrg::m_tressfxSimParameters.m_SimInts.y
  97. #define g_GravityMagnitude HairGenerationSrg::m_tressfxSimParameters.m_GravTimeTip.x
  98. #define g_TimeStep HairGenerationSrg::m_tressfxSimParameters.m_GravTimeTip.y
  99. #define g_TipSeparationFactor HairGenerationSrg::m_tressfxSimParameters.m_GravTimeTip.z
  100. #define g_Wind HairGenerationSrg::m_tressfxSimParameters.m_Wind
  101. #define g_Wind1 HairGenerationSrg::m_tressfxSimParameters.m_Wind1
  102. #define g_Wind2 HairGenerationSrg::m_tressfxSimParameters.m_Wind2
  103. #define g_Wind3 HairGenerationSrg::m_tressfxSimParameters.m_Wind3
  104. #define g_ResetPositions HairGenerationSrg::m_tressfxSimParameters.m_ResetPositions
  105. #define g_ClampPositionDelta HairGenerationSrg::m_tressfxSimParameters.m_ClampPositionDelta
  106. #define g_BoneSkinningDQ HairGenerationSrg::m_tressfxSimParameters.m_BoneSkinningDQ
  107. #define g_BoneSkinningMatrix HairGenerationSrg::m_tressfxSimParameters.m_BoneSkinningMatrix
  108. // We no longer support groups (indirection).
  109. int GetStrandType(int globalThreadIndex)
  110. {
  111. return 0;
  112. }
  113. float GetDamping(int strandType)
  114. {
  115. // strand type unused.
  116. // In the future, we may create an array and use indirection.
  117. return HairGenerationSrg::m_tressfxSimParameters.m_Shape.x;
  118. }
  119. float GetLocalStiffness(int strandType)
  120. {
  121. // strand type unused.
  122. // In the future, we may create an array and use indirection.
  123. return HairGenerationSrg::m_tressfxSimParameters.m_Shape.y;
  124. }
  125. float GetGlobalStiffness(int strandType)
  126. {
  127. // strand type unused.
  128. // In the future, we may create an array and use indirection.
  129. return HairGenerationSrg::m_tressfxSimParameters.m_Shape.z;
  130. }
  131. float GetGlobalRange(int strandType)
  132. {
  133. // strand type unused.
  134. // In the future, we may create an array and use indirection.
  135. return HairGenerationSrg::m_tressfxSimParameters.m_Shape.w;
  136. }
  137. float GetVelocityShockPropogation()
  138. {
  139. return HairGenerationSrg::m_tressfxSimParameters.m_VSP.x;
  140. }
  141. float GetVSPAccelThreshold()
  142. {
  143. return HairGenerationSrg::m_tressfxSimParameters.m_VSP.y;
  144. }
  145. int GetLocalConstraintIterations()
  146. {
  147. return (int)HairGenerationSrg::m_tressfxSimParameters.m_SimInts.y;
  148. }
  149. int GetLengthConstraintIterations()
  150. {
  151. return (int)HairGenerationSrg::m_tressfxSimParameters.m_SimInts.x;
  152. }
  153. //------------------------------------------------------------------------------