public static int USE_LEFTHAND_CAMERASPACE = 1 ;
public static int TILE_SIZE_FPTL = 1 6 ;
public static int TILE_SIZE_CLUSTERED = 3 2 ;
public static int TILE_SIZE_CLUSTERED = 1 6 ;
// flags
public static int IS_CIRCULAR_SPOT_SHAPE = 1 ;
if ( m_PassSettings . enableClustered )
{
s_PerVoxelOffset = new ComputeBuffer ( ( int ) LightCategory . Count * ( 1 < < k_Log2NumClusters ) * nrTiles , sizeof ( uint ) ) ;
s_PerVoxelLightLists = new ComputeBuffer ( NumLightIndicesPerClusteredTile ( ) * nrTiles , sizeof ( uint ) ) ;
var nrClustersX = ( width + LightDefinitions . TILE_SIZE_CLUSTERED - 1 ) / LightDefinitions . TILE_SIZE_CLUSTERED ;
var nrClustersY = ( height + LightDefinitions . TILE_SIZE_CLUSTERED - 1 ) / LightDefinitions . TILE_SIZE_CLUSTERED ;
var nrClusters = nrClustersX * nrClustersY ;
s_PerVoxelOffset = new ComputeBuffer ( ( int ) LightCategory . Count * ( 1 < < k_Log2NumClusters ) * nrClusters , sizeof ( uint ) ) ;
s_PerVoxelLightLists = new ComputeBuffer ( NumLightIndicesPerClusteredTile ( ) * nrClusters , sizeof ( uint ) ) ;
if ( k_UseDepthBuffer )
{
return shadowOutput . GetShadowSliceCountLightIndex ( lightIndex ) ;
}
public void GetDirectionalLightData ( ShadowSettings shadowSettings , GPULightType gpuLightType , VisibleLight light , AdditionalLightData additionalData , int lightIndex , ref ShadowOutput shadowOutput , ref int directionalShadowcount )
public bool GetDirectionalLightData ( ShadowSettings shadowSettings , GPULightType gpuLightType , VisibleLight light , AdditionalLightData additionalData , int lightIndex , ref ShadowOutput shadowOutput , ref int directionalShadowcount )
float diffuseDimmer = m_PassSettings . diffuseGlobalDimmer * additionalData . lightDimmer ;
float specularDimmer = m_PassSettings . specularGlobalDimmer * additionalData . lightDimmer ;
if ( diffuseDimmer < = 0.0f & & specularDimmer < = 0.0f )
return false ;
// Light direction for directional is opposite to the forward direction
directionalLightData . forward = light . light . transform . forward ;
directionalLightData . up = light . light . transform . up ;
directionalLightData . diffuseScale = additionalData . affectDiffuse ? 1.0f : 0.0f ;
directionalLightData . specularScale = additionalData . affectSpecular ? 1.0f : 0.0f ;
directionalLightData . diffuseScale = additionalData . affectDiffuse ? diffuseDimmer : 0.0f ;
directionalLightData . specularScale = additionalData . affectSpecular ? specularDimmer : 0.0f ;
directionalLightData . invScaleX = 1.0f / light . light . transform . localScale . x ;
directionalLightData . invScaleY = 1.0f / light . light . transform . localScale . y ;
directionalLightData . cosAngle = 0.0f ;
}
m_lightList . directionalLights . Add ( directionalLightData ) ;
return true ;
public void GetLightData ( ShadowSettings shadowSettings , GPULightType gpuLightType , VisibleLight light , AdditionalLightData additionalData , int lightIndex , ref ShadowOutput shadowOutput , ref int shadowCount )
float ComputeLinearDistanceFade ( float distanceToCamera , float fadeDistance )
{
// Fade with distance calculation is just a linear fade from 90% of fade distance to fade distance. 90% arbitrarly chosen but should work well enough.
float distanceFadeNear = 0.9f * fadeDistance ;
return 1.0f - Mathf . Clamp01 ( ( distanceToCamera - distanceFadeNear ) / ( fadeDistance - distanceFadeNear ) ) ;
}
public bool GetLightData ( ShadowSettings shadowSettings , Camera camera , GPULightType gpuLightType , VisibleLight light , AdditionalLightData additionalData , int lightIndex , ref ShadowOutput shadowOutput , ref int shadowCount )
{
var lightData = new LightData ( ) ;
lightData . angleOffset = 2.0f ;
}
lightData . diffuseScale = additionalData . affectDiffuse ? 1.0f : 0.0f ;
lightData . specularScale = additionalData . affectSpecular ? 1.0f : 0.0f ;
lightData . shadowDimmer = additionalData . shadowDimmer ;
float distanceToCamera = ( lightData . positionWS - camera . transform . position ) . magnitude ;
float distanceFade = ComputeLinearDistanceFade ( distanceToCamera , additionalData . fadeDistance ) ;
float lightScale = additionalData . lightDimmer * distanceFade ;
lightData . diffuseScale = additionalData . affectDiffuse ? lightScale * m_PassSettings . diffuseGlobalDimmer : 0.0f ;
lightData . specularScale = additionalData . affectSpecular ? lightScale * m_PassSettings . specularGlobalDimmer : 0.0f ;
if ( lightData . diffuseScale < = 0.0f & & lightData . specularScale < = 0.0f )
return false ;
lightData . IESIndex = - 1 ;
lightData . cookieIndex = - 1 ;
break ;
}
}
float shadowDistanceFade = ComputeLinearDistanceFade ( distanceToCamera , additionalData . shadowFadeDistance ) ;
lightData . shadowDimmer = additionalData . shadowDimmer * shadowDistanceFade ;
bool hasShadows = light . light . shadows ! = LightShadows . None & & shadowOutput . GetShadowSliceCountLightIndex ( lightIndex ) ! = 0 ;
// In case lightData.shadowDimmer == 0.0 we need to avoid rendering the shadow map... see how it can be done with the culling (and more specifically, how can we do that BEFORE sending for shadows)
bool hasShadows = lightData . shadowDimmer > 0.0f & & light . light . shadows ! = LightShadows . None & & shadowOutput . GetShadowSliceCountLightIndex ( lightIndex ) ! = 0 ;
bool hasNotReachMaxLimit = shadowCount + ( lightData . lightType = = GPULightType . Point ? 6 : 1 ) < = k_MaxShadowOnScreen ;
// TODO: Read the comment about shadow limit/management at the beginning of this loop
}
m_lightList . lights . Add ( lightData ) ;
return true ;
}
// TODO: we should be able to do this calculation only with LightData without VisibleLight light, but for now pass both
}
}
#endif
float oldSpecularGlobalDimmer = m_PassSettings . specularGlobalDimmer ;
// Change some parameters in case of "special" rendering (can be preview, reflection, etc.
if ( camera . cameraType = = CameraType . Reflection )
{
m_PassSettings . specularGlobalDimmer = 0.0f ;
}
// 1. Count the number of lights and sort all light by category, type and volume
int directionalLightcount = 0 ;
lightCategory = LightCategory . Punctual ;
gpuLightType = GPULightType . Point ;
lightVolumeType = LightVolumeType . Sphere ;
+ + punctualLightcount ;
break ;
case LightType . Spot :
gpuLightType = GPULightType . Spot ;
lightVolumeType = LightVolumeType . Cone ;
+ + punctualLightcount ;
break ;
case LightType . Directional :
gpuLightType = GPULightType . Directional ;
// No need to add volume, always visible
lightVolumeType = LightVolumeType . Count ; // Count is none
+ + directionalLightcount ;
break ;
default :
lightCategory = LightCategory . Area ;
gpuLightType = GPULightType . Rectangle ;
lightVolumeType = LightVolumeType . Box ;
+ + areaLightCount ;
break ;
case LightArchetype . Line :
gpuLightType = GPULightType . Line ;
lightVolumeType = LightVolumeType . Box ;
+ + areaLightCount ;
break ;
default :
// Directional rendering side, it is separated as it is always visible so no volume to handle here
if ( gpuLightType = = GPULightType . Directional )
{
GetDirectionalLightData ( shadowSettings , gpuLightType , light , additionalData , lightIndex , ref shadowOutput , ref directionalShadowcount ) ;
if ( GetDirectionalLightData ( shadowSettings , gpuLightType , light , additionalData , lightIndex , ref shadowOutput , ref directionalShadowcount ) )
directionalLightcount + + ;
#if (SHADOWS_ENABLED && SHADOWS_FIXSHADOWIDX)
// fix up shadow information
}
// Spot, point, rect, line light - Rendering side
GetLightData ( shadowSettings , gpuLightType , light , additionalData , lightIndex , ref shadowOutput , ref shadowCount ) ;
// 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 ] , worldToView ) ;
if ( GetLightData ( shadowSettings , camera , gpuLightType , light , additionalData , lightIndex , ref shadowOutput , ref shadowCount ) )
{
if ( lightCategory = = LightCategory . Punctual )
punctualLightcount + + ;
else if ( lightCategory = = LightCategory . Area )
areaLightCount + + ;
else
Debug . Assert ( false ) ; // Should not be anything else here.
// 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 ] , worldToView ) ;
}
#if (SHADOWS_ENABLED && SHADOWS_FIXSHADOWIDX)
// fix up shadow information
m_lightCount = m_lightList . lights . Count + m_lightList . envLights . Count ;
Debug . Assert ( m_lightList . bounds . Count = = m_lightCount ) ;
Debug . Assert ( m_lightList . lightVolumes . Count = = m_lightCount ) ;
// Restore values after "special rendering"
m_PassSettings . specularGlobalDimmer = oldSpecularGlobalDimmer ;
}
void VoxelLightListGeneration ( CommandBuffer cmd , Camera camera , Matrix4x4 projscr , Matrix4x4 invProjscr , RenderTargetIdentifier cameraDepthBufferRT )