HairRenderingSrgs.azsli 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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. // Shader code related to lighting and shadowing for TressFX
  10. //------------------------------------------------------------------------------
  11. //
  12. // Copyright (c) 2019 Advanced Micro Devices, Inc. All rights reserved.
  13. //
  14. // Permission is hereby granted, free of charge, to any person obtaining a copy
  15. // of this software and associated documentation files (the "Software"), to deal
  16. // in the Software without restriction, including without limitation the rights
  17. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  18. // copies of the Software, and to permit persons to whom the Software is
  19. // furnished to do so, subject to the following conditions:
  20. //
  21. // The above copyright notice and this permission notice shall be included in
  22. // all copies or substantial portions of the Software.
  23. //
  24. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  25. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  26. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  27. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  28. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  29. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  30. // THE SOFTWARE.
  31. //
  32. // originated from: TressFXRendering.hlsl
  33. #pragma once
  34. #include <viewsrg.srgi>
  35. //------------------------------------------------------------------------------
  36. #define g_mVP ViewSrg::m_viewProjectionMatrix
  37. #define g_vEye ViewSrg::m_worldPosition.xyz
  38. #define g_vViewport ViewSrg::m_unprojectionConstants // xy = normaliz scale, zw = offset in 0..1 scale
  39. #define cInvViewProjMatrix ViewSrg::m_viewProjectionInverseMatrix
  40. //------------------------------------------------------------------------------
  41. #define AMD_PI 3.1415926
  42. #define AMD_e 2.71828183
  43. #define AMD_TRESSFX_KERNEL_SIZE 5
  44. #define KBUFFER_SIZE 8
  45. #define MAX_FRAGMENTS 512
  46. // Using value 0 as indicator will skip the first hair fragment to allow
  47. // for clear screen value (0).
  48. // If Atom will allow other value (0xffffffff) this can be avoided.
  49. #define FRAGMENT_LIST_NULL 0
  50. //!=============================================================================
  51. //!
  52. //! Render Pass only
  53. //!
  54. //!=============================================================================
  55. // If you change this, you MUST also change TressFXRenderParams in TressFXConstantBuffers.h
  56. // originally: cbuffer TressFXParameters : register(b3, space0)
  57. struct TressFXRenderParameters
  58. {
  59. // General information
  60. float m_hairFiberRadius;
  61. // For deep approximated shadow lookup
  62. float m_shadowAlpha;
  63. float m_fiberSpacing;
  64. // Original TressFX Kajiya lighting model parameters
  65. float m_hairKs2;
  66. float m_hairEx2;
  67. float3 m_fPadding0;
  68. float4 m_matKValue;
  69. int m_maxShadowFibers;
  70. // Marschner lighting model parameters
  71. float m_roughness;
  72. float m_cuticleTilt;
  73. float m_fPadding1;
  74. };
  75. // Separate strand params from pixel render params (so we can index for PPLL)
  76. // If you change this, you MUST change TressFXStrandParams in TressFXConstantBuffers.h
  77. // originally: cbuffer TressFXStrandParameters : register(b4, space0)
  78. struct TressFXStrandParameters
  79. {
  80. float4 m_matBaseColor;
  81. float4 m_matTipColor;
  82. float m_tipPercentage;
  83. float m_strandUVTilingFactor;
  84. float m_fiberRatio;
  85. float m_fiberRadius;
  86. int m_numVerticesPerStrand;
  87. int m_enableThinTip;
  88. int m_nodePoolSize;
  89. int m_renderParamsIndex; // Material index in the hair material array
  90. // Other params
  91. int m_enableStrandUV;
  92. int m_enableStrandTangent;
  93. int2 m_iPadding1;
  94. };
  95. //!------------------------------ SRG Structure --------------------------------
  96. //! Used by the rendering raster pass only - might be possible to harness
  97. //! the material pipeline / tooling.
  98. //! This is the per draw Srg containing the specific per hair object parameters
  99. //! for the physics simulation and material rendering.
  100. //! Originally at space0 in TressFXRendering.hlsl
  101. //!-----------------------------------------------------------------------------
  102. ShaderResourceGroup HairRenderingMaterialSrg : SRG_PerMaterial
  103. {
  104. // Generated
  105. Buffer<float> m_hairThicknessCoeffs; // Does not seem to be used!
  106. Buffer<float2> m_hairStrandTexCd;
  107. //! The hair textures defining the color of the hair at its base
  108. Texture2D<float4> m_baseAlbedoTexture;
  109. Texture2D<float4> m_strandAlbedoTexture;
  110. //! The hair render material properties (combined with the above textures)
  111. TressFXRenderParameters m_tressFXRenderParameters;
  112. //! The hair object physical material properties.
  113. TressFXStrandParameters m_tressFXStrandParameters;
  114. Sampler LinearWrapSampler
  115. {
  116. MinFilter = Linear;
  117. MagFilter = Linear;
  118. MipFilter = Linear;
  119. AddressU = Wrap;
  120. AddressV = Wrap;
  121. AddressW = Wrap;
  122. };
  123. };
  124. //------------------------------------------------------------------------------
  125. #define g_HairThicknessCoeffs HairRenderingMaterialSrg::m_hairThicknessCoeffs
  126. #define g_HairStrandTexCd HairRenderingMaterialSrg::m_hairStrandTexCd
  127. #define BaseAlbedoTexture HairRenderingMaterialSrg::m_baseAlbedoTexture
  128. #define StrandAlbedoTexture HairRenderingMaterialSrg::m_strandAlbedoTexture
  129. #define LinearWrapSampler HairRenderingMaterialSrg::LinearWrapSampler
  130. #define HairFiberRadius HairRenderingMaterialSrg::m_tressFXRenderParameters.m_hairFiberRadius
  131. #define ShadowAlpha HairRenderingMaterialSrg::m_tressFXRenderParameters.m_shadowAlpha
  132. #define FiberSpacing HairRenderingMaterialSrg::m_tressFXRenderParameters.m_fiberSpacing
  133. #define HairKs2 HairRenderingMaterialSrg::m_tressFXRenderParameters.m_hairKs2
  134. #define HairEx2 HairRenderingMaterialSrg::m_tressFXRenderParameters.m_hairEx2
  135. #define MatKValue HairRenderingMaterialSrg::m_tressFXRenderParameters.m_matKValue
  136. #define MaxShadowFibers HairRenderingMaterialSrg::m_tressFXRenderParameters.m_maxShadowFibers
  137. #define MatBaseColor HairRenderingMaterialSrg::m_tressFXStrandParameters.m_matBaseColor
  138. #define MatTipColor HairRenderingMaterialSrg::m_tressFXStrandParameters.m_matTipColor
  139. #define TipPercentage HairRenderingMaterialSrg::m_tressFXStrandParameters.m_tipPercentage
  140. #define StrandUVTilingFactor HairRenderingMaterialSrg::m_tressFXStrandParameters.m_strandUVTilingFactor
  141. #define FiberRatio HairRenderingMaterialSrg::m_tressFXStrandParameters.m_fiberRatio
  142. #define FiberRadius HairRenderingMaterialSrg::m_tressFXStrandParameters.m_fiberRadius
  143. #define NumVerticesPerStrand HairRenderingMaterialSrg::m_tressFXStrandParameters.m_numVerticesPerStrand
  144. #define EnableThinTip HairRenderingMaterialSrg::m_tressFXStrandParameters.m_enableThinTip
  145. #define NodePoolSize HairRenderingMaterialSrg::m_tressFXStrandParameters.m_nodePoolSize
  146. #define RenderParamsIndex HairRenderingMaterialSrg::m_tressFXStrandParameters.m_renderParamsIndex
  147. #define EnableStrandUV HairRenderingMaterialSrg::m_tressFXStrandParameters.m_enableStrandUV
  148. #define EnableStrandTangent HairRenderingMaterialSrg::m_tressFXStrandParameters.m_enableStrandTangent
  149. //------------------------------------------------------------------------------
  150. //------------------------------------------------------------------------------
  151. //! If you change this, you MUST also change TressFXShadeParams in TressFXConstantBuffers.h
  152. //! and ShadeParams in TressFXShortcut.hlsl
  153. struct HairObjectShadeParams
  154. {
  155. // General information
  156. float m_fiberRadius;
  157. // For deep approximated shadow lookup
  158. float m_shadowAlpha;
  159. float m_fiberSpacing;
  160. // Original TressFX Kajiya lighting model parameters
  161. float m_hairEx2;
  162. float4 m_matKValue; // KAmbient, KDiffuse, KSpec1, Exp1
  163. float m_hairKs2;
  164. // Marschner lighting model parameters
  165. float m_roughness;
  166. float m_cuticleTilt;
  167. float fPadding0;
  168. };
  169. //------------------------------------------------------------------------------
  170. struct PPLL_STRUCT
  171. {
  172. uint depth;
  173. uint data;
  174. uint color;
  175. uint uNext;
  176. };
  177. //------------------------------------------------------------------------------