Input.hlsl 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. #define USE_STRUCTURED_BUFFER_FOR_LIGHT_DATA 0
  6. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderTypes.cs.hlsl"
  7. #if defined(SHADER_API_MOBILE) && (defined(SHADER_API_GLES) || defined(SHADER_API_GLES30))
  8. #define MAX_VISIBLE_LIGHTS 16
  9. #elif defined(SHADER_API_MOBILE) || (defined(SHADER_API_GLCORE) && !defined(SHADER_API_SWITCH)) || defined(SHADER_API_GLES) || defined(SHADER_API_GLES3) // Workaround for bug on Nintendo Switch where SHADER_API_GLCORE is mistakenly defined
  10. #define MAX_VISIBLE_LIGHTS 32
  11. #else
  12. #define MAX_VISIBLE_LIGHTS 256
  13. #endif
  14. struct InputData
  15. {
  16. float3 positionWS;
  17. half3 normalWS;
  18. half3 viewDirectionWS;
  19. float4 shadowCoord;
  20. half fogCoord;
  21. half3 vertexLighting;
  22. half3 bakedGI;
  23. float2 normalizedScreenSpaceUV;
  24. half4 shadowMask;
  25. };
  26. ///////////////////////////////////////////////////////////////////////////////
  27. // Constant Buffers //
  28. ///////////////////////////////////////////////////////////////////////////////
  29. half4 _GlossyEnvironmentColor;
  30. half4 _SubtractiveShadowColor;
  31. #define _InvCameraViewProj unity_MatrixInvVP
  32. float4 _ScaledScreenParams;
  33. float4 _MainLightPosition;
  34. half4 _MainLightColor;
  35. half4 _MainLightOcclusionProbes;
  36. // xyz are currently unused
  37. // w: directLightStrength
  38. half4 _AmbientOcclusionParam;
  39. half4 _AdditionalLightsCount;
  40. #if USE_STRUCTURED_BUFFER_FOR_LIGHT_DATA
  41. StructuredBuffer<LightData> _AdditionalLightsBuffer;
  42. StructuredBuffer<int> _AdditionalLightsIndices;
  43. #else
  44. // GLES3 causes a performance regression in some devices when using CBUFFER.
  45. #ifndef SHADER_API_GLES3
  46. CBUFFER_START(AdditionalLights)
  47. #endif
  48. float4 _AdditionalLightsPosition[MAX_VISIBLE_LIGHTS];
  49. half4 _AdditionalLightsColor[MAX_VISIBLE_LIGHTS];
  50. half4 _AdditionalLightsAttenuation[MAX_VISIBLE_LIGHTS];
  51. half4 _AdditionalLightsSpotDir[MAX_VISIBLE_LIGHTS];
  52. half4 _AdditionalLightsOcclusionProbes[MAX_VISIBLE_LIGHTS];
  53. #ifndef SHADER_API_GLES3
  54. CBUFFER_END
  55. #endif
  56. #endif
  57. #define UNITY_MATRIX_M unity_ObjectToWorld
  58. #define UNITY_MATRIX_I_M unity_WorldToObject
  59. #define UNITY_MATRIX_V unity_MatrixV
  60. #define UNITY_MATRIX_I_V unity_MatrixInvV
  61. #define UNITY_MATRIX_P OptimizeProjectionMatrix(glstate_matrix_projection)
  62. #define UNITY_MATRIX_I_P unity_MatrixInvP
  63. #define UNITY_MATRIX_VP unity_MatrixVP
  64. #define UNITY_MATRIX_I_VP unity_MatrixInvVP
  65. #define UNITY_MATRIX_MV mul(UNITY_MATRIX_V, UNITY_MATRIX_M)
  66. #define UNITY_MATRIX_T_MV transpose(UNITY_MATRIX_MV)
  67. #define UNITY_MATRIX_IT_MV transpose(mul(UNITY_MATRIX_I_M, UNITY_MATRIX_I_V))
  68. #define UNITY_MATRIX_MVP mul(UNITY_MATRIX_VP, UNITY_MATRIX_M)
  69. // Note: #include order is important here.
  70. // UnityInput.hlsl must be included before UnityInstancing.hlsl, so constant buffer
  71. // declarations don't fail because of instancing macros.
  72. // UniversalDOTSInstancing.hlsl must be included after UnityInstancing.hlsl
  73. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/UnityInput.hlsl"
  74. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/UnityInstancing.hlsl"
  75. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/UniversalDOTSInstancing.hlsl"
  76. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/SpaceTransforms.hlsl"
  77. #endif