Input.hlsl 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. #ifndef UNIVERSAL_INPUT_INCLUDED
  2. #define UNIVERSAL_INPUT_INCLUDED
  3. #define MAX_VISIBLE_LIGHTS_UBO 32
  4. #define MAX_VISIBLE_LIGHTS_SSBO 256
  5. // Keep in sync with RenderingUtils.useStructuredBuffer
  6. #define USE_STRUCTURED_BUFFER_FOR_LIGHT_DATA 0
  7. #define RENDERING_LIGHT_LAYERS_MASK (255)
  8. #define RENDERING_LIGHT_LAYERS_MASK_SHIFT (0)
  9. #define DEFAULT_LIGHT_LAYERS (RENDERING_LIGHT_LAYERS_MASK >> RENDERING_LIGHT_LAYERS_MASK_SHIFT)
  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_GLES) || defined(SHADER_API_GLES30))
  14. #define MAX_VISIBLE_LIGHTS 16
  15. #elif defined(SHADER_API_MOBILE) || (defined(SHADER_API_GLCORE) && !defined(SHADER_API_SWITCH)) || defined(SHADER_API_GLES) || defined(SHADER_API_GLES3) // Workaround because SHADER_API_GLCORE is also defined when SHADER_API_SWITCH is
  16. #define MAX_VISIBLE_LIGHTS 32
  17. #else
  18. #define MAX_VISIBLE_LIGHTS 256
  19. #endif
  20. // Match with values in UniversalRenderPipeline.cs
  21. #define MAX_ZBIN_VEC4S 1024
  22. #define MAX_TILE_VEC4S 4096
  23. #if MAX_VISIBLE_LIGHTS < 32
  24. #define LIGHTS_PER_TILE 32
  25. #else
  26. #define LIGHTS_PER_TILE MAX_VISIBLE_LIGHTS
  27. #endif
  28. struct InputData
  29. {
  30. float3 positionWS;
  31. float4 positionCS;
  32. half3 normalWS;
  33. half3 viewDirectionWS;
  34. float4 shadowCoord;
  35. half fogCoord;
  36. half3 vertexLighting;
  37. half3 bakedGI;
  38. float2 normalizedScreenSpaceUV;
  39. half4 shadowMask;
  40. half3x3 tangentToWorld;
  41. #if defined(DEBUG_DISPLAY)
  42. half2 dynamicLightmapUV;
  43. half2 staticLightmapUV;
  44. float3 vertexSH;
  45. half3 brdfDiffuse;
  46. half3 brdfSpecular;
  47. float2 uv;
  48. uint mipCount;
  49. // texelSize :
  50. // x = 1 / width
  51. // y = 1 / height
  52. // z = width
  53. // w = height
  54. float4 texelSize;
  55. // mipInfo :
  56. // x = quality settings minStreamingMipLevel
  57. // y = original mip count for texture
  58. // z = desired on screen mip level
  59. // w = loaded mip level
  60. float4 mipInfo;
  61. #endif
  62. };
  63. ///////////////////////////////////////////////////////////////////////////////
  64. // Constant Buffers //
  65. ///////////////////////////////////////////////////////////////////////////////
  66. half4 _GlossyEnvironmentColor;
  67. half4 _SubtractiveShadowColor;
  68. half4 _GlossyEnvironmentCubeMap_HDR;
  69. TEXTURECUBE(_GlossyEnvironmentCubeMap);
  70. SAMPLER(sampler_GlossyEnvironmentCubeMap);
  71. #define _InvCameraViewProj unity_MatrixInvVP
  72. float4 _ScaledScreenParams;
  73. float4 _MainLightPosition;
  74. half4 _MainLightColor;
  75. half4 _MainLightOcclusionProbes;
  76. uint _MainLightLayerMask;
  77. // xyz are currently unused
  78. // w: directLightStrength
  79. half4 _AmbientOcclusionParam;
  80. half4 _AdditionalLightsCount;
  81. #if USE_CLUSTERED_LIGHTING
  82. // Directional lights would be in all clusters, so they don't go into the cluster structure.
  83. // Instead, they are stored first in the light buffer.
  84. uint _AdditionalLightsDirectionalCount;
  85. // The number of Z-bins to skip based on near plane distance.
  86. uint _AdditionalLightsZBinOffset;
  87. // Scale from view-space Z to Z-bin.
  88. float _AdditionalLightsZBinScale;
  89. // Scale from screen-space UV [0, 1] to tile coordinates [0, tile resolution].
  90. float2 _AdditionalLightsTileScale;
  91. uint _AdditionalLightsTileCountX;
  92. #endif
  93. #if USE_STRUCTURED_BUFFER_FOR_LIGHT_DATA
  94. StructuredBuffer<LightData> _AdditionalLightsBuffer;
  95. StructuredBuffer<int> _AdditionalLightsIndices;
  96. #else
  97. // GLES3 causes a performance regression in some devices when using CBUFFER.
  98. #ifndef SHADER_API_GLES3
  99. CBUFFER_START(AdditionalLights)
  100. #endif
  101. float4 _AdditionalLightsPosition[MAX_VISIBLE_LIGHTS];
  102. half4 _AdditionalLightsColor[MAX_VISIBLE_LIGHTS];
  103. half4 _AdditionalLightsAttenuation[MAX_VISIBLE_LIGHTS];
  104. half4 _AdditionalLightsSpotDir[MAX_VISIBLE_LIGHTS];
  105. half4 _AdditionalLightsOcclusionProbes[MAX_VISIBLE_LIGHTS];
  106. float _AdditionalLightsLayerMasks[MAX_VISIBLE_LIGHTS]; // we want uint[] but Unity api does not support it.
  107. #ifndef SHADER_API_GLES3
  108. CBUFFER_END
  109. #endif
  110. #endif
  111. #if USE_CLUSTERED_LIGHTING
  112. CBUFFER_START(AdditionalLightsZBins)
  113. float4 _AdditionalLightsZBins[MAX_ZBIN_VEC4S];
  114. CBUFFER_END
  115. CBUFFER_START(AdditionalLightsTiles)
  116. float4 _AdditionalLightsTiles[MAX_TILE_VEC4S];
  117. CBUFFER_END
  118. #endif
  119. #define UNITY_MATRIX_M unity_ObjectToWorld
  120. #define UNITY_MATRIX_I_M unity_WorldToObject
  121. #define UNITY_MATRIX_V unity_MatrixV
  122. #define UNITY_MATRIX_I_V unity_MatrixInvV
  123. #define UNITY_MATRIX_P OptimizeProjectionMatrix(glstate_matrix_projection)
  124. #define UNITY_MATRIX_I_P unity_MatrixInvP
  125. #define UNITY_MATRIX_VP unity_MatrixVP
  126. #define UNITY_MATRIX_PREV_VP unity_MatrixPrevVP
  127. #define UNITY_MATRIX_I_VP unity_MatrixInvVP
  128. #define UNITY_MATRIX_MV mul(UNITY_MATRIX_V, UNITY_MATRIX_M)
  129. #define UNITY_MATRIX_T_MV transpose(UNITY_MATRIX_MV)
  130. #define UNITY_MATRIX_IT_MV transpose(mul(UNITY_MATRIX_I_M, UNITY_MATRIX_I_V))
  131. #define UNITY_MATRIX_MVP mul(UNITY_MATRIX_VP, UNITY_MATRIX_M)
  132. #define UNITY_PREV_MATRIX_M unity_MatrixPreviousM
  133. #define UNITY_PREV_MATRIX_I_M unity_MatrixPreviousMI
  134. // Note: #include order is important here.
  135. // UnityInput.hlsl must be included before UnityInstancing.hlsl, so constant buffer
  136. // declarations don't fail because of instancing macros.
  137. // UniversalDOTSInstancing.hlsl must be included after UnityInstancing.hlsl
  138. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/UnityInput.hlsl"
  139. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/UnityInstancing.hlsl"
  140. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/UniversalDOTSInstancing.hlsl"
  141. // VFX may also redefine UNITY_MATRIX_M / UNITY_MATRIX_I_M as static per-particle global matrices.
  142. #ifdef HAVE_VFX_MODIFICATION
  143. #include "Packages/com.unity.visualeffectgraph/Shaders/VFXMatricesOverride.hlsl"
  144. #endif
  145. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/SpaceTransforms.hlsl"
  146. #endif