Açıklama Yok
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Input.hlsl 8.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. #ifndef UNIVERSAL_INPUT_INCLUDED
  2. #define UNIVERSAL_INPUT_INCLUDED
  3. // URP package specific shader input variables and defines.
  4. // Unity Engine specific built-in shader input variables are defined in .universal/ShaderLibrary/UnityInput.hlsl
  5. #include "Packages/com.unity.render-pipelines.universal-config/Runtime/ShaderConfig.cs.hlsl"
  6. #define MAX_VISIBLE_LIGHTS_UBO 32
  7. #define MAX_VISIBLE_LIGHTS_SSBO 256
  8. // Keep in sync with RenderingUtils.useStructuredBuffer
  9. #define USE_STRUCTURED_BUFFER_FOR_LIGHT_DATA 0
  10. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderTypes.cs.hlsl"
  11. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Deprecated.hlsl"
  12. // Must match: UniversalRenderPipeline.maxVisibleAdditionalLights
  13. #if defined(SHADER_API_MOBILE) && defined(SHADER_API_GLES30)
  14. #define MAX_VISIBLE_LIGHTS MAX_VISIBLE_LIGHT_COUNT_LOW_END_MOBILE
  15. // WebGPU's minimal limits are based on mobile rather than desktop, so it will need to assume mobile.
  16. #elif defined(SHADER_API_MOBILE) || (defined(SHADER_API_GLCORE) && !defined(SHADER_API_SWITCH)) || defined(SHADER_API_GLES3) || defined(SHADER_API_WEBGPU) // Workaround because SHADER_API_GLCORE is also defined when SHADER_API_SWITCH is
  17. #define MAX_VISIBLE_LIGHTS MAX_VISIBLE_LIGHT_COUNT_MOBILE
  18. #else
  19. #define MAX_VISIBLE_LIGHTS MAX_VISIBLE_LIGHT_COUNT_DESKTOP
  20. #endif
  21. // Match with values in UniversalRenderPipeline.cs
  22. #define MAX_ZBIN_VEC4S 1024
  23. #if MAX_VISIBLE_LIGHTS <= 16
  24. #define MAX_LIGHTS_PER_TILE 32
  25. #define MAX_TILE_VEC4S 1024
  26. #define MAX_REFLECTION_PROBES 16
  27. #elif MAX_VISIBLE_LIGHTS <= 32
  28. #define MAX_LIGHTS_PER_TILE 32
  29. #define MAX_TILE_VEC4S 1024
  30. #define MAX_REFLECTION_PROBES 32
  31. #else
  32. #define MAX_LIGHTS_PER_TILE MAX_VISIBLE_LIGHTS
  33. #define MAX_TILE_VEC4S 4096
  34. #define MAX_REFLECTION_PROBES 64
  35. #endif
  36. struct InputData
  37. {
  38. float3 positionWS;
  39. float4 positionCS;
  40. float3 normalWS;
  41. half3 viewDirectionWS;
  42. float4 shadowCoord;
  43. half fogCoord;
  44. half3 vertexLighting;
  45. half3 bakedGI;
  46. float2 normalizedScreenSpaceUV;
  47. half4 shadowMask;
  48. half3x3 tangentToWorld;
  49. #if defined(DEBUG_DISPLAY)
  50. half2 dynamicLightmapUV;
  51. half2 staticLightmapUV;
  52. float3 vertexSH;
  53. half3 brdfDiffuse;
  54. half3 brdfSpecular;
  55. // Mipmap Streaming Debug
  56. float2 uv;
  57. uint mipCount;
  58. // texelSize :
  59. // x = 1 / width
  60. // y = 1 / height
  61. // z = width
  62. // w = height
  63. float4 texelSize;
  64. // mipInfo :
  65. // x = quality settings minStreamingMipLevel
  66. // y = original mip count for texture
  67. // z = desired on screen mip level
  68. // w = loaded mip level
  69. float4 mipInfo;
  70. // streamInfo :
  71. // x = streaming priority
  72. // y = time stamp of the latest texture upload
  73. // z = streaming status
  74. // w = 0
  75. float4 streamInfo;
  76. float3 originalColor;
  77. #endif
  78. };
  79. ///////////////////////////////////////////////////////////////////////////////
  80. // Constant Buffers //
  81. ///////////////////////////////////////////////////////////////////////////////
  82. half4 _GlossyEnvironmentColor;
  83. half4 _SubtractiveShadowColor;
  84. half4 _GlossyEnvironmentCubeMap_HDR;
  85. TEXTURECUBE(_GlossyEnvironmentCubeMap);
  86. SAMPLER(sampler_GlossyEnvironmentCubeMap);
  87. #define _InvCameraViewProj unity_MatrixInvVP
  88. float4 _ScaledScreenParams;
  89. // x = Mip Bias
  90. // y = 2.0 ^ [Mip Bias]
  91. float2 _GlobalMipBias;
  92. // 1.0 if it's possible for AlphaToMask to be enabled for this draw and 0.0 otherwise
  93. float _AlphaToMaskAvailable;
  94. float4 _MainLightPosition;
  95. // In Forward+, .a stores whether the main light is using subtractive mixed mode.
  96. half4 _MainLightColor;
  97. half4 _MainLightOcclusionProbes;
  98. uint _MainLightLayerMask;
  99. // x: SSAO Enabled/Disabled (Needed for situations when OFF keyword is stripped out but feature disabled in runtime)
  100. // yz are currently unused
  101. // w: directLightStrength
  102. half4 _AmbientOcclusionParam;
  103. half4 _AdditionalLightsCount;
  104. uint _RenderingLayerMaxInt;
  105. float _RenderingLayerRcpMaxInt;
  106. // Screen coord override.
  107. float4 _ScreenCoordScaleBias;
  108. float4 _ScreenSizeOverride;
  109. uint _EnableProbeVolumes;
  110. #if USE_FORWARD_PLUS
  111. float4 _FPParams0;
  112. float4 _FPParams1;
  113. float4 _FPParams2;
  114. #define URP_FP_ZBIN_SCALE (_FPParams0.x)
  115. #define URP_FP_ZBIN_OFFSET (_FPParams0.y)
  116. #define URP_FP_PROBES_BEGIN ((uint)_FPParams0.z)
  117. // Directional lights would be in all clusters, so they don't go into the cluster structure.
  118. // Instead, they are stored first in the light buffer.
  119. #define URP_FP_DIRECTIONAL_LIGHTS_COUNT ((uint)_FPParams0.w)
  120. // Scale from screen-space UV [0, 1] to tile coordinates [0, tile resolution].
  121. #define URP_FP_TILE_SCALE ((float2)_FPParams1.xy)
  122. #define URP_FP_TILE_COUNT_X ((uint)_FPParams1.z)
  123. #define URP_FP_WORDS_PER_TILE ((uint)_FPParams1.w)
  124. #define URP_FP_ZBIN_COUNT ((uint)_FPParams2.x)
  125. #define URP_FP_TILE_COUNT ((uint)_FPParams2.y)
  126. #endif
  127. #if USE_STRUCTURED_BUFFER_FOR_LIGHT_DATA
  128. StructuredBuffer<LightData> _AdditionalLightsBuffer;
  129. StructuredBuffer<int> _AdditionalLightsIndices;
  130. #else
  131. // GLES3 causes a performance regression in some devices when using CBUFFER.
  132. #ifndef SHADER_API_GLES3
  133. CBUFFER_START(AdditionalLights)
  134. #endif
  135. float4 _AdditionalLightsPosition[MAX_VISIBLE_LIGHTS];
  136. // In Forward+, .a stores whether the light is using subtractive mixed mode.
  137. half4 _AdditionalLightsColor[MAX_VISIBLE_LIGHTS];
  138. half4 _AdditionalLightsAttenuation[MAX_VISIBLE_LIGHTS];
  139. half4 _AdditionalLightsSpotDir[MAX_VISIBLE_LIGHTS];
  140. half4 _AdditionalLightsOcclusionProbes[MAX_VISIBLE_LIGHTS];
  141. float _AdditionalLightsLayerMasks[MAX_VISIBLE_LIGHTS]; // we want uint[] but Unity api does not support it.
  142. #ifndef SHADER_API_GLES3
  143. CBUFFER_END
  144. #endif
  145. #endif
  146. #if USE_FORWARD_PLUS
  147. CBUFFER_START(urp_ZBinBuffer)
  148. float4 urp_ZBins[MAX_ZBIN_VEC4S];
  149. CBUFFER_END
  150. CBUFFER_START(urp_TileBuffer)
  151. float4 urp_Tiles[MAX_TILE_VEC4S];
  152. CBUFFER_END
  153. TEXTURE2D(urp_ReflProbes_Atlas);
  154. float urp_ReflProbes_Count;
  155. // 2023.3 Deprecated. This is for backwards compatibility. Remove in the future.
  156. #define samplerurp_ReflProbes_Atlas sampler_LinearClamp
  157. #ifndef SHADER_API_GLES3
  158. CBUFFER_START(urp_ReflectionProbeBuffer)
  159. #endif
  160. float4 urp_ReflProbes_BoxMax[MAX_REFLECTION_PROBES]; // w contains the blend distance
  161. float4 urp_ReflProbes_BoxMin[MAX_REFLECTION_PROBES]; // w contains the importance
  162. float4 urp_ReflProbes_ProbePosition[MAX_REFLECTION_PROBES]; // w is positive for box projection, |w| is max mip level
  163. float4 urp_ReflProbes_MipScaleOffset[MAX_REFLECTION_PROBES * 7];
  164. #ifndef SHADER_API_GLES3
  165. CBUFFER_END
  166. #endif
  167. #endif
  168. #define UNITY_MATRIX_M unity_ObjectToWorld
  169. #define UNITY_MATRIX_I_M unity_WorldToObject
  170. #define UNITY_MATRIX_V unity_MatrixV
  171. #define UNITY_MATRIX_I_V unity_MatrixInvV
  172. #define UNITY_MATRIX_P OptimizeProjectionMatrix(glstate_matrix_projection)
  173. #define UNITY_MATRIX_I_P unity_MatrixInvP
  174. #define UNITY_MATRIX_VP unity_MatrixVP
  175. #define UNITY_MATRIX_I_VP unity_MatrixInvVP
  176. #define UNITY_MATRIX_MV mul(UNITY_MATRIX_V, UNITY_MATRIX_M)
  177. #define UNITY_MATRIX_T_MV transpose(UNITY_MATRIX_MV)
  178. #define UNITY_MATRIX_IT_MV transpose(mul(UNITY_MATRIX_I_M, UNITY_MATRIX_I_V))
  179. #define UNITY_MATRIX_MVP mul(UNITY_MATRIX_VP, UNITY_MATRIX_M)
  180. #define UNITY_PREV_MATRIX_M unity_MatrixPreviousM
  181. #define UNITY_PREV_MATRIX_I_M unity_MatrixPreviousMI
  182. // Note: #include order is important here.
  183. // UnityInput.hlsl must be included before UnityInstancing.hlsl, so constant buffer
  184. // declarations don't fail because of instancing macros.
  185. // UniversalDOTSInstancing.hlsl must be included after UnityInstancing.hlsl
  186. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/UnityInput.hlsl"
  187. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/UnityInstancing.hlsl"
  188. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/UniversalDOTSInstancing.hlsl"
  189. // VFX may also redefine UNITY_MATRIX_M / UNITY_MATRIX_I_M as static per-particle global matrices.
  190. #ifdef HAVE_VFX_MODIFICATION
  191. #include "Packages/com.unity.visualeffectgraph/Shaders/VFXMatricesOverride.hlsl"
  192. #endif
  193. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/SpaceTransforms.hlsl"
  194. #endif