break ;
case 2 :
m_ShadowSettings . directionalLightCascades = new Vector3 ( m_Asset . CascadeSplit . x , 1.0f , 0.0f ) ;
m_ShadowSettings . directionalLightCascades = new Vector3 ( m_Asset . Cascade2 Split , 1.0f , 0.0f ) ;
m_ShadowSettings . directionalLightCascades = m_Asset . CascadeSplit ;
m_ShadowSettings . directionalLightCascades = m_Asset . Cascade4 Split ;
break ;
}
}
Vector4 [ ] lightAttenuations = new Vector4 [ kMaxLights ] ;
Vector4 [ ] lightSpotDirections = new Vector4 [ kMaxLights ] ;
int pixelLightCount = Mathf . Min ( lights . Length , QualitySettings . pixelLightCount ) ;
int pixelLightCount = Mathf . Min ( lights . Length , m_Asset . MaxSupportedPixelLights ) ;
int vertexLightCount = ( m_Asset . SupportsVertexLight ) ? Mathf . Min ( lights . Length - pixelLightCount , kMaxLights ) : 0 ;
int totalLightCount = pixelLightCount + vertexLightCount ;
int shadowResolution = 0 ;
int lightIndex = - 1 ;
float shadowBias = 0.0f ;
for ( int i = 0 ; i < lightCount ; + + i )
{
if ( lights [ i ] . light . shadows ! = LightShadows . None & & lights [ i ] . lightType = = LightType . Directional )
m_ShadowSettings . shadowAtlasHeight , cascadeCount ) ;
shadowBias = lights [ i ] . light . shadowBias ;
break ;
}
}
float shadowNearPlane = m_Asset . ShadowNearOffset ;
Vector3 splitRatio = m_ShadowSettings . directionalLightCascades ;
Vector3 lightDir = lights [ lightIndex ] . light . transform . forward ;
for ( int cascadeIdx = 0 ; cascadeIdx < cascadeCount ; + + cascadeIdx )
{
Matrix4x4 view , proj ;
if ( needRendering )
{
SetupShadowSliceTransform ( cascadeIdx , shadowResolution , proj , view ) ;
RenderShadowSlice ( ref context , cascadeIdx , proj , view , settings , shadowBia s ) ;
RenderShadowSlice ( ref context , lightDir , cascadeIdx , proj , view , settings ) ;
}
}
m_ShadowSlices [ cascadeIndex ] . shadowTransform = matTile * matScaleBias * proj * view ;
}
private void RenderShadowSlice ( ref ScriptableRenderContext context , int cascadeIndex , Matrix4x4 proj , Matrix4x4 view , DrawShadowsSettings settings , float shadowBia s )
{
private void RenderShadowSlice ( ref ScriptableRenderContext context , Vector3 lightDir , int cascadeIndex , Matrix4x4 proj , Matrix4x4 view , DrawShadowsSettings settings )
{
buffer . SetGlobalVector ( "_Shadow Bias" , new Vector4 ( shadowBias , 0.0f , 0.0f , 0.0f ) ) ;
buffer . SetGlobalVector ( "_WorldLightDirAnd Bias" , new Vector4 ( - lightDir . x , - lightDir . y , - lightDir . z , m_Asset . ShadowBias ) ) ;
context . ExecuteCommandBuffer ( buffer ) ;
buffer . Dispose ( ) ;
void SetShadowKeywords ( CommandBuffer cmd )
{
if ( m_Asset . CurrShadowType = = LowEndRenderPipeline . ShadowType . NO_SHADOW )
cmd . DisableShaderKeyword ( "SHADOWS_DEPTH" ) ;
else
cmd . EnableShaderKeyword ( "SHADOWS_DEPTH" ) ;
switch ( m_Asset . CurrShadowType )
{
case LowEndRenderPipeline . ShadowType . NO_SHADOW :
cmd . DisableShaderKeyword ( "HARD_SHADOWS" ) ;
cmd . DisableShaderKeyword ( "SOFT_SHADOWS" ) ;
break ;
switch ( m_Asset . CurrShadowFiltering )
{
case LowEndRenderPipeline . ShadowFiltering . PCF :
cmd . EnableShaderKeyword ( "SHADOWS_FILTERING_PCF" ) ;
case LowEndRenderPipeline . ShadowType . HARD_SHADOWS :
cmd . EnableShaderKeyword ( "HARD_SHADOWS" ) ;
cmd . DisableShaderKeyword ( "SOFT_SHADOWS" ) ;
default :
cmd . DisableShaderKeyword ( "SHADOWS_FILTERING_PCF" ) ;
case LowEndRenderPipeline . ShadowType . SOFT_SHADOWS :
cmd . DisableShaderKeyword ( "HARD_SHADOWS" ) ;
cmd . EnableShaderKeyword ( "SOFT_SHADOWS" ) ;
break ;
}
}
#endregion
#region PipelineAssetSettings
public enum ShadowFiltering
{
PCF = 0 ,
NONE
}
public enum ShadowCascades
{
NO_CASCADES = 1 ,
{
NO_SHADOW = 0 ,
HARD_SHADOWS ,
SOFT_SHADOWS ,
public enum ShadowResolution
{
_512 = 5 1 2 ,
_1024 = 1 0 2 4 ,
_2048 = 2 0 4 8
}
[SerializeField]
private int m_MaxPixelLights = 1 ;
[SerializeField]
private bool m_SupportsVertexLight = true ;
private ShadowType m_ShadowType = ShadowType . HARD_SHADOWS ;
[SerializeField]
private ShadowResolution m_ShadowAtlasResolution = ShadowResolution . _1024 ;
[SerializeField]
private float m_ShadowNearPlaneOffset = 2.0f ;
[SerializeField]
private int m_ShadowAtlasResolution = 1 0 2 4 ;
private float m_ShadowBias = 0.0005f ;
private Vector3 m_CascadeSplit = new Vector3 ( 0.067f , 0.2f , 0.467f ) ;
private float m_Cascade2Split = 0.25f ;
private ShadowFiltering m_ShadowFiltering = ShadowFiltering . NONE ;
private Vector3 m_Cascade4Split = new Vector3 ( 0.067f , 0.2f , 0.467f ) ;
public int MaxSupportedPixelLights { get { return m_MaxPixelLights ; } private set { m_MaxPixelLights = value ; } }
public bool SupportsVertexLight { get { return m_SupportsVertexLight ; } private set { m_SupportsVertexLight = value ; } }
public ShadowType CurrShadowType { get { return m_ShadowType ; } private set { m_ShadowType = value ; } }
public int ShadowAtlasResolution { get { return ( int ) m_ShadowAtlasResolution ; } private set { m_ShadowAtlasResolution = ( ShadowResolution ) value ; } }
public float ShadowBias { get { return m_ShadowBias ; } private set { m_ShadowBias = value ; } }
public Vector3 CascadeSplit { get { return m_CascadeSplit ; } private set { m_CascadeSplit = value ; } }
public float Cascade2Split { get { return m_Cascade2Split ; } private set { m_Cascade2Split = value ; } }
public ShadowFiltering CurrShadowFiltering { get { return m_ShadowFiltering ; } private set { m_ShadowFiltering = value ; } }
public Vector3 Cascade4Split { get { return m_Cascade4Split ; } private set { m_Cascade4Split = value ; } }
public int ShadowAtlasResolution { get { return m_ShadowAtlasResolution ; } private set { m_ShadowAtlasResolution = value ; } }
#endregion
}