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.
171 lines
5.9 KiB
171 lines
5.9 KiB
#ifndef UNIVERSAL_INPUT_INCLUDED |
|
#define UNIVERSAL_INPUT_INCLUDED |
|
|
|
#define MAX_VISIBLE_LIGHTS_UBO 32 |
|
#define MAX_VISIBLE_LIGHTS_SSBO 256 |
|
|
|
// Keep in sync with RenderingUtils.useStructuredBuffer |
|
#define USE_STRUCTURED_BUFFER_FOR_LIGHT_DATA 0 |
|
|
|
#define RENDERING_LIGHT_LAYERS_MASK (255) |
|
#define RENDERING_LIGHT_LAYERS_MASK_SHIFT (0) |
|
#define DEFAULT_LIGHT_LAYERS (RENDERING_LIGHT_LAYERS_MASK >> RENDERING_LIGHT_LAYERS_MASK_SHIFT) |
|
|
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderTypes.cs.hlsl" |
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Deprecated.hlsl" |
|
|
|
// Must match: UniversalRenderPipeline.maxVisibleAdditionalLights |
|
#if defined(SHADER_API_MOBILE) && (defined(SHADER_API_GLES) || defined(SHADER_API_GLES30)) |
|
#define MAX_VISIBLE_LIGHTS 16 |
|
#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 |
|
#define MAX_VISIBLE_LIGHTS 32 |
|
#else |
|
#define MAX_VISIBLE_LIGHTS 256 |
|
#endif |
|
|
|
// Match with values in UniversalRenderPipeline.cs |
|
#define MAX_ZBIN_VEC4S 1024 |
|
#define MAX_TILE_VEC4S 4096 |
|
#if MAX_VISIBLE_LIGHTS < 32 |
|
#define LIGHTS_PER_TILE 32 |
|
#else |
|
#define LIGHTS_PER_TILE MAX_VISIBLE_LIGHTS |
|
#endif |
|
|
|
struct InputData |
|
{ |
|
float3 positionWS; |
|
float4 positionCS; |
|
float3 normalWS; |
|
half3 viewDirectionWS; |
|
float4 shadowCoord; |
|
half fogCoord; |
|
half3 vertexLighting; |
|
half3 bakedGI; |
|
float2 normalizedScreenSpaceUV; |
|
half4 shadowMask; |
|
half3x3 tangentToWorld; |
|
|
|
#if defined(DEBUG_DISPLAY) |
|
half2 dynamicLightmapUV; |
|
half2 staticLightmapUV; |
|
float3 vertexSH; |
|
|
|
half3 brdfDiffuse; |
|
half3 brdfSpecular; |
|
float2 uv; |
|
uint mipCount; |
|
|
|
// texelSize : |
|
// x = 1 / width |
|
// y = 1 / height |
|
// z = width |
|
// w = height |
|
float4 texelSize; |
|
|
|
// mipInfo : |
|
// x = quality settings minStreamingMipLevel |
|
// y = original mip count for texture |
|
// z = desired on screen mip level |
|
// w = loaded mip level |
|
float4 mipInfo; |
|
#endif |
|
}; |
|
|
|
/////////////////////////////////////////////////////////////////////////////// |
|
// Constant Buffers // |
|
/////////////////////////////////////////////////////////////////////////////// |
|
|
|
half4 _GlossyEnvironmentColor; |
|
half4 _SubtractiveShadowColor; |
|
|
|
half4 _GlossyEnvironmentCubeMap_HDR; |
|
TEXTURECUBE(_GlossyEnvironmentCubeMap); |
|
SAMPLER(sampler_GlossyEnvironmentCubeMap); |
|
|
|
#define _InvCameraViewProj unity_MatrixInvVP |
|
float4 _ScaledScreenParams; |
|
|
|
float4 _MainLightPosition; |
|
half4 _MainLightColor; |
|
half4 _MainLightOcclusionProbes; |
|
uint _MainLightLayerMask; |
|
|
|
// xyz are currently unused |
|
// w: directLightStrength |
|
half4 _AmbientOcclusionParam; |
|
|
|
half4 _AdditionalLightsCount; |
|
|
|
#if USE_CLUSTERED_LIGHTING |
|
// Directional lights would be in all clusters, so they don't go into the cluster structure. |
|
// Instead, they are stored first in the light buffer. |
|
uint _AdditionalLightsDirectionalCount; |
|
// The number of Z-bins to skip based on near plane distance. |
|
uint _AdditionalLightsZBinOffset; |
|
// Scale from view-space Z to Z-bin. |
|
float _AdditionalLightsZBinScale; |
|
// Scale from screen-space UV [0, 1] to tile coordinates [0, tile resolution]. |
|
float2 _AdditionalLightsTileScale; |
|
uint _AdditionalLightsTileCountX; |
|
#endif |
|
|
|
#if USE_STRUCTURED_BUFFER_FOR_LIGHT_DATA |
|
StructuredBuffer<LightData> _AdditionalLightsBuffer; |
|
StructuredBuffer<int> _AdditionalLightsIndices; |
|
#else |
|
// GLES3 causes a performance regression in some devices when using CBUFFER. |
|
#ifndef SHADER_API_GLES3 |
|
CBUFFER_START(AdditionalLights) |
|
#endif |
|
float4 _AdditionalLightsPosition[MAX_VISIBLE_LIGHTS]; |
|
half4 _AdditionalLightsColor[MAX_VISIBLE_LIGHTS]; |
|
half4 _AdditionalLightsAttenuation[MAX_VISIBLE_LIGHTS]; |
|
half4 _AdditionalLightsSpotDir[MAX_VISIBLE_LIGHTS]; |
|
half4 _AdditionalLightsOcclusionProbes[MAX_VISIBLE_LIGHTS]; |
|
float _AdditionalLightsLayerMasks[MAX_VISIBLE_LIGHTS]; // we want uint[] but Unity api does not support it. |
|
#ifndef SHADER_API_GLES3 |
|
CBUFFER_END |
|
#endif |
|
#endif |
|
|
|
#if USE_CLUSTERED_LIGHTING |
|
CBUFFER_START(AdditionalLightsZBins) |
|
float4 _AdditionalLightsZBins[MAX_ZBIN_VEC4S]; |
|
CBUFFER_END |
|
CBUFFER_START(AdditionalLightsTiles) |
|
float4 _AdditionalLightsTiles[MAX_TILE_VEC4S]; |
|
CBUFFER_END |
|
#endif |
|
|
|
#define UNITY_MATRIX_M unity_ObjectToWorld |
|
#define UNITY_MATRIX_I_M unity_WorldToObject |
|
#define UNITY_MATRIX_V unity_MatrixV |
|
#define UNITY_MATRIX_I_V unity_MatrixInvV |
|
#define UNITY_MATRIX_P OptimizeProjectionMatrix(glstate_matrix_projection) |
|
#define UNITY_MATRIX_I_P unity_MatrixInvP |
|
#define UNITY_MATRIX_VP unity_MatrixVP |
|
#define UNITY_MATRIX_I_VP unity_MatrixInvVP |
|
#define UNITY_MATRIX_MV mul(UNITY_MATRIX_V, UNITY_MATRIX_M) |
|
#define UNITY_MATRIX_T_MV transpose(UNITY_MATRIX_MV) |
|
#define UNITY_MATRIX_IT_MV transpose(mul(UNITY_MATRIX_I_M, UNITY_MATRIX_I_V)) |
|
#define UNITY_MATRIX_MVP mul(UNITY_MATRIX_VP, UNITY_MATRIX_M) |
|
#define UNITY_PREV_MATRIX_M unity_MatrixPreviousM |
|
#define UNITY_PREV_MATRIX_I_M unity_MatrixPreviousMI |
|
|
|
// Note: #include order is important here. |
|
// UnityInput.hlsl must be included before UnityInstancing.hlsl, so constant buffer |
|
// declarations don't fail because of instancing macros. |
|
// UniversalDOTSInstancing.hlsl must be included after UnityInstancing.hlsl |
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/UnityInput.hlsl" |
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/UnityInstancing.hlsl" |
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/UniversalDOTSInstancing.hlsl" |
|
|
|
// VFX may also redefine UNITY_MATRIX_M / UNITY_MATRIX_I_M as static per-particle global matrices. |
|
#ifdef HAVE_VFX_MODIFICATION |
|
#include "Packages/com.unity.visualeffectgraph/Shaders/VFXMatricesOverride.hlsl" |
|
#endif |
|
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/SpaceTransforms.hlsl" |
|
|
|
#endif
|
|
|