Light m_CurrentSunLight ;
int m_CurrentSunLightShadowIndex = - 1 ;
LightData m_DominantLightData ;
int m_DominantLightIndex = - 1 ;
public Light GetCurrentSunLight ( ) { return m_CurrentSunLight ; }
var lightData = new LightData ( ) ;
lightData . lightType = gpuLightType ;
lightData . disableContactShadow = 1 ;
lightData . positionWS = light . light . transform . position ;
// Setting 0 for invSqrAttenuationRadius mean we have no range attenuation, but still have inverse square attenuation.
// We need to properly reset this here otherwise if we go from 1 light to no visible light we would keep the old reference active.
m_CurrentSunLight = null ;
m_CurrentSunLightShadowIndex = - 1 ;
m_DominantLightIndex = - 1 ;
var stereoEnabled = m_FrameSettings . enableStereo ;
//TODO: move this upwards
float biggestLight = 0 ;
int dominantLightDataIndex = 0 ;
for ( int sortIndex = 0 ; sortIndex < sortCount ; + + sortIndex )
{
lightData . positionWS - = camPosWS ;
m_lightList . directionalLights [ last ] = lightData ;
}
if ( additionalShadowData . contactShadows )
biggestLight = Single . PositiveInfinity ;
}
continue ;
}
// Punctual, area, projector lights - the rendering side.
if ( GetLightData ( cmd , shadowSettings , camera , gpuLightType , light , additionalLightData , additionalShadowData , lightIndex , ref lightDimensions ) )
{
int last = m_lightList . lights . Count - 1 ;
switch ( lightCategory )
{
case LightCategory . Punctual :
Debug . Assert ( false , "TODO: encountered an unknown LightCategory." ) ;
break ;
}
if ( additionalShadowData ! = null & & additionalShadowData . contactShadows & & lightDimensions . magnitude > biggestLight )
{
m_DominantLightIndex = lightIndex ;
biggestLight = lightDimensions . magnitude ;
}
// Then culling side. Must be call in this order as we pass the created Light data to the function
GetLightVolumeDataAndBound ( lightCategory , gpuLightType , lightVolumeType , light , m_lightList . lights [ m_lightList . lights . Count - 1 ] , lightDimensions , worldToView ) ;
if ( ShaderConfig . s_CameraRelativeRendering ! = 0 )
{
// Caution: 'LightData.positionWS' is camera-relative after this point.
int last = m_lightList . lights . Count - 1 ;
if ( additionalShadowData ! = null & & additionalShadowData . contactShadows & & lightDimensions . magnitude > biggestLight )
{
m_DominantLightData = m_lightList . lights [ m_lightList . lights . Count - 1 ] ;
m_DominantLightIndex = lightIndex ;
dominantLightDataIndex = last ;
biggestLight = lightDimensions . magnitude ;
}
}
//Activate contact shadows on dominant light
if ( m_DominantLightIndex ! = - 1 )
{
m_DominantLightData . disableContactShadow = 0 ;
m_lightList . lights [ dominantLightDataIndex ] = m_DominantLightData ;
}
// Sanity check
cmd . SetGlobalTexture ( HDShaderIDs . _DeferredShadowTexture , RuntimeUtilities . blackTexture ) ;
return ;
}
using ( new ProfilingSample ( cmd , "Deferred Directional Shadow" , CustomSamplerId . TPDeferredDirectionalShadow . GetSampler ( ) ) )
{
ContactShadows contactShadows = VolumeManager . instance . stack . GetComponent < ContactShadows > ( ) ;
// Debug.Log("contactShadowsSettings: " + contactShadows.enable);
Debug . Log ( "Contact shadows enabled !" ) ;
{
}
else
kernel = s_deferredDirectionalShadow_Contact_Kernel ;
}
if ( m_CurrentSunLight ! = null )
lightDirection = - m_CurrentSunLight . transform . forward ;
else
lightDirection = Vector3 . one ; //TODO: put dominant light direction here
lightDirection = m_DominantLightData . positionWS ;
m_ShadowMgr . BindResources ( cmd , deferredDirectionalShadowComputeShader , kernel ) ;