Input.hlsl 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #ifndef UNIVERSAL_INPUT_INCLUDED
  2. #define UNIVERSAL_INPUT_INCLUDED
  3. #define MAX_VISIBLE_LIGHTS_SSBO 256
  4. #define MAX_VISIBLE_LIGHTS_UBO 32
  5. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderTypes.cs.hlsl"
  6. // There are some performance issues by using SSBO in mobile.
  7. // Also some GPUs don't supports SSBO in vertex shader.
  8. #if !defined(SHADER_API_MOBILE) && (defined(SHADER_API_METAL) || defined(SHADER_API_VULKAN) || defined(SHADER_API_PS4) || defined(SHADER_API_XBOXONE))
  9. #define USE_STRUCTURED_BUFFER_FOR_LIGHT_DATA 0
  10. #define MAX_VISIBLE_LIGHTS MAX_VISIBLE_LIGHTS_SSBO
  11. // We don't use SSBO in D3D because we can't figure out without adding shader variants if platforms is D3D10.
  12. // We don't use SSBO on Nintendo Switch as UBO path is faster.
  13. // However here we use same limits as SSBO path.
  14. #elif defined(SHADER_API_D3D11) || defined(SHADER_API_SWITCH)
  15. #define MAX_VISIBLE_LIGHTS MAX_VISIBLE_LIGHTS_SSBO
  16. #define USE_STRUCTURED_BUFFER_FOR_LIGHT_DATA 0
  17. // We use less limits for mobile as some mobile GPUs have small SP cache for constants
  18. // Using more than 32 might cause spilling to main memory.
  19. #else
  20. #define MAX_VISIBLE_LIGHTS MAX_VISIBLE_LIGHTS_UBO
  21. #define USE_STRUCTURED_BUFFER_FOR_LIGHT_DATA 0
  22. #endif
  23. struct InputData
  24. {
  25. float3 positionWS;
  26. half3 normalWS;
  27. half3 viewDirectionWS;
  28. float4 shadowCoord;
  29. half fogCoord;
  30. half3 vertexLighting;
  31. half3 bakedGI;
  32. };
  33. ///////////////////////////////////////////////////////////////////////////////
  34. // Constant Buffers //
  35. ///////////////////////////////////////////////////////////////////////////////
  36. half4 _GlossyEnvironmentColor;
  37. half4 _SubtractiveShadowColor;
  38. float4x4 _InvCameraViewProj;
  39. float4 _ScaledScreenParams;
  40. float4 _MainLightPosition;
  41. half4 _MainLightColor;
  42. half4 _AdditionalLightsCount;
  43. #if USE_STRUCTURED_BUFFER_FOR_LIGHT_DATA
  44. StructuredBuffer<LightData> _AdditionalLightsBuffer;
  45. StructuredBuffer<int> _AdditionalLightsIndices;
  46. #else
  47. float4 _AdditionalLightsPosition[MAX_VISIBLE_LIGHTS];
  48. half4 _AdditionalLightsColor[MAX_VISIBLE_LIGHTS];
  49. half4 _AdditionalLightsAttenuation[MAX_VISIBLE_LIGHTS];
  50. half4 _AdditionalLightsSpotDir[MAX_VISIBLE_LIGHTS];
  51. half4 _AdditionalLightsOcclusionProbes[MAX_VISIBLE_LIGHTS];
  52. #endif
  53. #define UNITY_MATRIX_M unity_ObjectToWorld
  54. #define UNITY_MATRIX_I_M unity_WorldToObject
  55. #define UNITY_MATRIX_V unity_MatrixV
  56. #define UNITY_MATRIX_I_V unity_MatrixInvV
  57. #define UNITY_MATRIX_P OptimizeProjectionMatrix(glstate_matrix_projection)
  58. #define UNITY_MATRIX_I_P ERROR_UNITY_MATRIX_I_P_IS_NOT_DEFINED
  59. #define UNITY_MATRIX_VP unity_MatrixVP
  60. #define UNITY_MATRIX_I_VP _InvCameraViewProj
  61. #define UNITY_MATRIX_MV mul(UNITY_MATRIX_V, UNITY_MATRIX_M)
  62. #define UNITY_MATRIX_T_MV transpose(UNITY_MATRIX_MV)
  63. #define UNITY_MATRIX_IT_MV transpose(mul(UNITY_MATRIX_I_M, UNITY_MATRIX_I_V))
  64. #define UNITY_MATRIX_MVP mul(UNITY_MATRIX_VP, UNITY_MATRIX_M)
  65. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/UnityInput.hlsl"
  66. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/UnityInstancing.hlsl"
  67. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/SpaceTransforms.hlsl"
  68. #endif