int m_areaLightCount = 0 ;
int m_lightCount = 0 ;
private ComputeShader buildScreenAABBShader { get { return m_Parent . renderPipelineSetup . buildScreenAABBShader ; } }
private ComputeShader buildPerTileLightListShader { get { return m_Parent . renderPipelineSetup . buildPerTileLightListShader ; } }
private ComputeShader buildPerBigTileLightListShader { get { return m_Parent . renderPipelineSetup . buildPerBigTileLightListShader ; } }
private ComputeShader buildPerVoxelLightListShader { get { return m_Parent . renderPipelineSetup . buildPerVoxelLightListShader ; } }
private ComputeShader shadeOpaqueShader { get { return m_Parent . renderPipelineSetup . shadeOpaqueShader ; } }
private ComputeShader buildScreenAABBShader { get { return m_PassResources . buildScreenAABBShader ; } }
private ComputeShader buildPerTileLightListShader { get { return m_PassResources . buildPerTileLightListShader ; } }
private ComputeShader buildPerBigTileLightListShader { get { return m_PassResources . buildPerBigTileLightListShader ; } }
private ComputeShader buildPerVoxelLightListShader { get { return m_PassResources . buildPerVoxelLightListShader ; } }
private ComputeShader shadeOpaqueShader { get { return m_PassResources . shadeOpaqueShader ; } }
static int s_GenAABBKernel ;
static int s_GenListPerTileKernel ;
get
{
bool isEnabledMSAA = false ;
var tileSettings = m_Parent . tileSettings ;
Debug . Assert ( ! isEnabledMSAA | | tileSettings . enableClustered ) ;
bool disableFptl = ( tileSettings . disableFptlWhenClustered & & tileSettings . enableClustered ) | | isEnabledMSAA ;
Debug . Assert ( ! isEnabledMSAA | | m_PassSettings . enableClustered ) ;
bool disableFptl = ( m_PassSettings . disableFptlWhenClustered & & m_PassSettings . enableClustered ) | | isEnabledMSAA ;
return ! disableFptl ;
}
}
}
}
Material m_DeferredDirectMaterial = null ;
Material m_DeferredIndirectMaterial = null ;
Material m_DeferredAllMaterial = null ;
const int k_TileSize = 1 6 ;
private readonly HDRenderPipeline m_Parent ;
int GetNumTileX ( Camera camera )
return ( camera . pixelHeight + ( k_TileSize - 1 ) ) / k_TileSize ;
}
public LightLoop ( HDRenderPipeline hdRenderPipeline )
TileLightLoopProducer . TileSettings m_PassSettings ;
private TilePassResources m_PassResources ;
public LightLoop ( TileLightLoopProducer producer )
m_Parent = hdRenderPipeline ;
m_PassSettings = producer . tileSettings ;
m_PassResources = producer . passResources ;
}
public override void Build ( TextureSettings textureSettings )
var tileSettings = m_Parent . tileSettings ;
s_DirectionalLightDatas = new ComputeBuffer ( k_MaxDirectionalLightsOnScreen , System . Runtime . InteropServices . Marshal . SizeOf ( typeof ( DirectionalLightData ) ) ) ;
s_LightDatas = new ComputeBuffer ( k_MaxPunctualLightsOnScreen + k_MaxAreaLightsOnSCreen , System . Runtime . InteropServices . Marshal . SizeOf ( typeof ( LightData ) ) ) ;
s_EnvLightDatas = new ComputeBuffer ( k_MaxEnvLightsOnScreen , System . Runtime . InteropServices . Marshal . SizeOf ( typeof ( EnvLightData ) ) ) ;
m_CubeReflTexArray . AllocTextureArray ( 3 2 , textureSettings . reflectionCubemapSize , TextureFormat . BC6H , true ) ;
s_GenAABBKernel = buildScreenAABBShader . FindKernel ( "ScreenBoundsAABB" ) ;
s_GenListPerTileKernel = buildPerTileLightListShader . FindKernel ( tile Settings. enableBigTilePrepass ? "TileLightListGen_SrcBigTile" : "TileLightListGen" ) ;
s_GenListPerTileKernel = buildPerTileLightListShader . FindKernel ( m_Pass Settings. enableBigTilePrepass ? "TileLightListGen_SrcBigTile" : "TileLightListGen" ) ;
s_AABBBoundsBuffer = new ComputeBuffer ( 2 * k_MaxLightsOnScreen , 3 * sizeof ( float ) ) ;
s_ConvexBoundsBuffer = new ComputeBuffer ( k_MaxLightsOnScreen , System . Runtime . InteropServices . Marshal . SizeOf ( typeof ( SFiniteLightBound ) ) ) ;
s_LightVolumeDataBuffer = new ComputeBuffer ( k_MaxLightsOnScreen , System . Runtime . InteropServices . Marshal . SizeOf ( typeof ( LightVolumeData ) ) ) ;
buildPerTileLightListShader . SetBuffer ( s_GenListPerTileKernel , "_LightVolumeData" , s_LightVolumeDataBuffer ) ;
buildPerTileLightListShader . SetBuffer ( s_GenListPerTileKernel , "g_data" , s_ConvexBoundsBuffer ) ;
if ( tile Settings. enableClustered )
if ( m_Pass Settings. enableClustered )
var kernelName = tile Settings. enableBigTilePrepass ? ( k_UseDepthBuffer ? "TileLightListGen_DepthRT_SrcBigTile" : "TileLightListGen_NoDepthRT_SrcBigTile" ) : ( k_UseDepthBuffer ? "TileLightListGen_DepthRT" : "TileLightListGen_NoDepthRT" ) ;
var kernelName = m_Pass Settings. enableBigTilePrepass ? ( k_UseDepthBuffer ? "TileLightListGen_DepthRT_SrcBigTile" : "TileLightListGen_NoDepthRT_SrcBigTile" ) : ( k_UseDepthBuffer ? "TileLightListGen_DepthRT" : "TileLightListGen_NoDepthRT" ) ;
s_GenListPerVoxelKernel = buildPerVoxelLightListShader . FindKernel ( kernelName ) ;
s_ClearVoxelAtomicKernel = buildPerVoxelLightListShader . FindKernel ( "ClearAtomic" ) ;
buildPerVoxelLightListShader . SetBuffer ( s_GenListPerVoxelKernel , "g_vBoundsBuffer" , s_AABBBoundsBuffer ) ;
s_GlobalLightListAtomic = new ComputeBuffer ( 1 , sizeof ( uint ) ) ;
}
if ( tile Settings. enableBigTilePrepass )
if ( m_Pass Settings. enableBigTilePrepass )
{
s_GenListPerBigTileKernel = buildPerBigTileLightListShader . FindKernel ( "BigTileLightListGen" ) ;
buildPerBigTileLightListShader . SetBuffer ( s_GenListPerBigTileKernel , "g_vBoundsBuffer" , s_AABBBoundsBuffer ) ;
public override bool NeedResize ( )
{
var tileSettings = m_Parent . tileSettings ;
( s_BigTileLightList = = null & & tileSettings . enableBigTilePrepass ) | |
( s_PerVoxelLightLists = = null & & tileSettings . enableClustered ) ;
( s_BigTileLightList = = null & & m_PassSettings . enableBigTilePrepass ) | |
( s_PerVoxelLightLists = = null & & m_PassSettings . enableClustered ) ;
}
public override void ReleaseResolutionDependentBuffers ( )
const int dwordsPerTile = ( capacityUShortsPerTile + 1 ) > > 1 ; // room for 31 lights and a nrLights value.
s_LightList = new ComputeBuffer ( ( int ) LightCategory . Count * dwordsPerTile * nrTiles , sizeof ( uint ) ) ; // enough list memory for a 4k x 4k display
var tileSettings = m_Parent . tileSettings ;
if ( tileSettings . enableClustered )
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 ) ) ;
}
}
if ( tile Settings. enableBigTilePrepass )
if ( m_Pass Settings. enableBigTilePrepass )
{
var nrBigTilesX = ( width + 6 3 ) / 6 4 ;
var nrBigTilesY = ( height + 6 3 ) / 6 4 ;
cmd . SetComputeBufferParam ( buildPerVoxelLightListShader , s_GenListPerVoxelKernel , "g_vLayeredLightList" , s_PerVoxelLightLists ) ;
cmd . SetComputeBufferParam ( buildPerVoxelLightListShader , s_GenListPerVoxelKernel , "g_LayeredOffset" , s_PerVoxelOffset ) ;
cmd . SetComputeBufferParam ( buildPerVoxelLightListShader , s_GenListPerVoxelKernel , "g_LayeredSingleIdxBuffer" , s_GlobalLightListAtomic ) ;
if ( m_Parent . tile Settings. enableBigTilePrepass )
if ( m_PassSettings . enableBigTilePrepass )
cmd . SetComputeBufferParam ( buildPerVoxelLightListShader , s_GenListPerVoxelKernel , "g_vBigTileLightList" , s_BigTileLightList ) ;
if ( k_UseDepthBuffer )
cmd . SetComputeBufferParam ( buildScreenAABBShader , s_GenAABBKernel , "g_vBoundsBuffer" , s_AABBBoundsBuffer ) ;
cmd . DispatchCompute ( buildScreenAABBShader , s_GenAABBKernel , ( m_lightCount + 7 ) / 8 , 1 , 1 ) ;
}
var tileSettings = m_Parent . tileSettings ;
if ( tileSettings . enableBigTilePrepass )
if ( m_PassSettings . enableBigTilePrepass )
{
cmd . SetComputeIntParams ( buildPerBigTileLightListShader , "g_viDimensions" , new int [ 2 ] { w , h } ) ;
cmd . SetComputeIntParam ( buildPerBigTileLightListShader , "_EnvLightIndexShift" , m_lightList . lights . Count ) ;
Utilities . SetMatrixCS ( cmd , buildPerTileLightListShader , "g_mInvScrProjection" , invProjscr ) ;
cmd . SetComputeTextureParam ( buildPerTileLightListShader , s_GenListPerTileKernel , "g_depth_tex" , cameraDepthBufferRT ) ;
cmd . SetComputeBufferParam ( buildPerTileLightListShader , s_GenListPerTileKernel , "g_vLightList" , s_LightList ) ;
if ( tile Settings. enableBigTilePrepass )
if ( m_Pass Settings. enableBigTilePrepass )
if ( tile Settings. enableClustered ) // works for transparencies too.
if ( m_Pass Settings. enableClustered ) // works for transparencies too.
{
VoxelLightListGeneration ( cmd , camera , projscr , invProjscr , cameraDepthBufferRT ) ;
}
SetGlobalInt ( "_NumTileX" , GetNumTileX ( camera ) ) ;
SetGlobalInt ( "_NumTileY" , GetNumTileY ( camera ) ) ;
var tileSettings = m_Parent . tileSettings ;
if ( tileSettings . enableBigTilePrepass )
if ( m_PassSettings . enableBigTilePrepass )
if ( tileSettings . enableClustered )
if ( m_PassSettings . enableClustered )
{
SetGlobalFloat ( "g_fClustScale" , m_ClustScale ) ;
SetGlobalFloat ( "g_fClustBase" , k_ClustLogBase ) ;
mousePixelCoord . y = ( hdCamera . screenSize . y - 1.0f ) - mousePixelCoord . y ;
}
#endif
var tileSettings = m_Parent . tileSettings ;
using ( new Utilities . ProfilingSample ( tileSettings . disableTileAndCluster ? "SinglePass - Deferred Lighting Pass" : "TilePass - Deferred Lighting Pass" , renderContext ) )
using ( new Utilities . ProfilingSample ( m_PassSettings . disableTileAndCluster ? "SinglePass - Deferred Lighting Pass" : "TilePass - Deferred Lighting Pass" , renderContext ) )
{
var cmd = new CommandBuffer ( ) ;
SetGlobalFloat ( "_UseTileLightList" , 0 ) ;
}
if ( tile Settings. disableTileAndCluster )
if ( m_Pass Settings. disableTileAndCluster )
{
// This is a debug brute force renderer to debug tile/cluster which render all the lights
Utilities . SetupMaterialHDCamera ( hdCamera , m_SingleDeferredMaterial ) ;
}
else
{
if ( ! tile Settings. disableDeferredShadingInCompute )
if ( ! m_Pass Settings. disableDeferredShadingInCompute )
{
// Compute shader evaluation
int kernel = bUseClusteredForDeferred ? s_shadeOpaqueClusteredKernel : s_shadeOpaqueFptlKernel ;
else
{
// Pixel shader evaluation
if ( tile Settings. enableSplitLightEvaluation )
if ( m_Pass Settings. enableSplitLightEvaluation )
{
Utilities . SetupMaterialHDCamera ( hdCamera , m_DeferredDirectMaterial ) ;
m_DeferredDirectMaterial . SetInt ( "_SrcBlend" , ( int ) UnityEngine . Rendering . BlendMode . One ) ;
}
// Draw tile debugging
if ( tile Settings. debugViewTilesFlags ! = 0 )
if ( m_Pass Settings. debugViewTilesFlags ! = 0 )
m_DebugViewTilesMaterial . SetInt ( "_ViewTilesFlags" , tile Settings. debugViewTilesFlags ) ;
m_DebugViewTilesMaterial . SetInt ( "_ViewTilesFlags" , m_Pass Settings. debugViewTilesFlags ) ;
m_DebugViewTilesMaterial . SetVector ( "_MousePixelCoord" , mousePixelCoord ) ;
m_DebugViewTilesMaterial . EnableKeyword ( bUseClusteredForDeferred ? "USE_CLUSTERED_LIGHTLIST" : "USE_FPTL_LIGHTLIST" ) ;
m_DebugViewTilesMaterial . DisableKeyword ( ! bUseClusteredForDeferred ? "USE_CLUSTERED_LIGHTLIST" : "USE_FPTL_LIGHTLIST" ) ;
var cmd = new CommandBuffer ( ) ;
if ( m_Parent . tile Settings. disableTileAndCluster )
if ( m_PassSettings . disableTileAndCluster )
{
cmd . name = "Forward pass" ;
cmd . EnableShaderKeyword ( "LIGHTLOOP_SINGLE_PASS" ) ;