public bool enableComputeMaterialVariants ;
// clustered light list specific buffers and data begin
public bool enableClustered ;
public bool enableFptlForOpaqueWhenClustered ; // still useful on opaques. Should be true by default to force tile on opaque.
public bool enableBigTilePrepass ;
[Range(0.0f, 1.0f)]
enableComputeLightVariants = true ;
enableComputeMaterialVariants = true ;
enableClustered = true ;
enableFptlForOpaqueWhenClustered = true ;
enableBigTilePrepass = true ;
diffuseGlobalDimmer = 1.0f ;
static int s_BuildMaterialFlagsWriteKernel ;
static int s_BuildMaterialFlagsOrKernel ;
static int s_shadeOpaqueDirectClusteredKernel ;
static int s_shadeOpaqueDirectClusteredDebugDisplayKernel ;
static int s_shadeOpaqueDirectShadowMaskClusteredKernel ;
static int s_shadeOpaqueDirectShadowMaskClusteredDebugDisplayKernel ;
// Tag: SUPPORT_COMPUTE_CLUSTER_OPAQUE - Uncomment this if you want to do cluster opaque with compute shader (by default we support only fptl on opaque)
//static int[] s_shadeOpaqueIndirectClusteredKernels = new int[LightDefinitions.s_NumFeatureVariants];
static int [ ] s_shadeOpaqueIndirectFptlKernels = new int [ LightDefinitions . s_NumFeatureVariants ] ;
static int [ ] s_shadeOpaqueIndirectShadowMaskFptlKernels = new int [ LightDefinitions . s_NumFeatureVariants ] ;
static ComputeBuffer s_GlobalLightListAtomic = null ;
// clustered light list specific buffers and data end
bool usingFptl
{
get
{
bool isEnabledMSAA = false ;
Debug . Assert ( ! isEnabledMSAA | | m_TileSettings . enableClustered ) ;
bool disableFptl = ( ! m_TileSettings . enableFptlForOpaqueWhenClustered & & m_TileSettings . enableClustered ) | | isEnabledMSAA ;
return ! disableFptl ;
}
}
// Following is an array of material of size eight for all combination of keyword: OUTPUT_SPLIT_LIGHTING - LIGHTLOOP_TILE_PASS - SHADOWS_SHADOWMASK - USE_FPTL_LIGHTLIST/USE_CLUSTERED_LIGHTLIST - DEBUG_DISPLAY
Material [ , , , , ] m_lightingMaterial ;
Material m_DebugViewTilesMaterial ;
public static bool GetFeatureVariantsEnabled ( TileSettings tileSettings )
{
return tileSettings . enableComputeLightEvaluation & & ( tileSettings . enableComputeLightVariants | | tileSettings . enableComputeMaterialVariants ) & & ! ( tileSettings . enableClustered & & ! tileSettings . enableFptlForOpaqueWhenClustered ) ;
return tileSettings . enableComputeLightEvaluation & & ( tileSettings . enableComputeLightVariants | | tileSettings . enableComputeMaterialVariants ) ;
}
TileSettings m_TileSettings = null ;
s_LightVolumeDataBuffer = new ComputeBuffer ( k_MaxLightsOnScreen , System . Runtime . InteropServices . Marshal . SizeOf ( typeof ( LightVolumeData ) ) ) ;
s_DispatchIndirectBuffer = new ComputeBuffer ( LightDefinitions . s_NumFeatureVariants * 3 , sizeof ( uint ) , ComputeBufferType . IndirectArguments ) ;
if ( m_TileSettings . enableClustered )
// Cluster
{
var kernelName = m_TileSettings . enableBigTilePrepass ? ( k_UseDepthBuffer ? "TileLightListGen_DepthRT_SrcBigTile" : "TileLightListGen_NoDepthRT_SrcBigTile" ) : ( k_UseDepthBuffer ? "TileLightListGen_DepthRT" : "TileLightListGen_NoDepthRT" ) ;
s_GenListPerVoxelKernel = buildPerVoxelLightListShader . FindKernel ( kernelName ) ;
s_BuildMaterialFlagsOrKernel = buildMaterialFlagsShader . FindKernel ( "MaterialFlagsGen_Or" ) ;
s_BuildMaterialFlagsWriteKernel = buildMaterialFlagsShader . FindKernel ( "MaterialFlagsGen_Write" ) ;
s_shadeOpaqueDirectClusteredKernel = deferredComputeShader . FindKernel ( "Deferred_Direct_Clustered" ) ;
s_shadeOpaqueDirectClusteredDebugDisplayKernel = deferredComputeShader . FindKernel ( "Deferred_Direct_Clustered_DebugDisplay" ) ;
s_shadeOpaqueDirectShadowMaskClusteredKernel = deferredComputeShader . FindKernel ( "Deferred_Direct_ShadowMask_Clustered" ) ;
s_shadeOpaqueDirectShadowMaskClusteredDebugDisplayKernel = deferredComputeShader . FindKernel ( "Deferred_Direct_ShadowMask_Clustered_DebugDisplay" ) ;
s_shadeOpaqueDirectShadowMaskFptlDebugDisplayKernel = deferredComputeShader . FindKernel ( "Deferred_Direct_ShadowMask_Fptl_DebugDisplay" ) ;
s_deferredDirectionalShadowKernel = deferredDirectionalShadowComputeShader . FindKernel ( "DeferredDirectionalShadow" ) ;
// Tag: SUPPORT_CLUSTER_OPAQUE - Uncomment this if you want to do cluster opaque (by default we support only fptl on opaque)
// s_shadeOpaqueIndirectClusteredKernels[variant] = deferredComputeShader.FindKernel("Deferred_Indirect_Clustered_Variant" + variant);
s_shadeOpaqueIndirectFptlKernels [ variant ] = deferredComputeShader . FindKernel ( "Deferred_Indirect_Fptl_Variant" + variant ) ;
s_shadeOpaqueIndirectShadowMaskFptlKernels [ variant ] = deferredComputeShader . FindKernel ( "Deferred_Indirect_ShadowMask_Fptl_Variant" + variant ) ;
}
{
return s_LightList = = null | | s_TileList = = null | | s_TileFeatureFlags = = null | |
( s_BigTileLightList = = null & & m_TileSettings . enableBigTilePrepass ) | |
( s_PerVoxelLightLists = = null & & m_TileSettings . enableClustered ) ;
( s_PerVoxelLightLists = = null ) ;
}
public void ReleaseResolutionDependentBuffers ( )
s_TileList = new ComputeBuffer ( ( int ) LightDefinitions . s_NumFeatureVariants * nrTiles , sizeof ( uint ) ) ;
s_TileFeatureFlags = new ComputeBuffer ( nrTilesX * nrTilesY , sizeof ( uint ) ) ;
if ( m_TileSettings . enableClustered )
// Cluster
{
var nrClustersX = ( width + LightDefinitions . s_TileSizeClustered - 1 ) / LightDefinitions . s_TileSizeClustered ;
var nrClustersY = ( height + LightDefinitions . s_TileSizeClustered - 1 ) / LightDefinitions . s_TileSizeClustered ;
var numTiles = numTilesX * numTilesY ;
bool enableFeatureVariants = GetFeatureVariantsEnabled ( m_TileSettings ) ;
if ( usingFptl ) // optimized for opaques only
// optimized for opaques only
{
cmd . SetComputeIntParam ( buildPerTileLightListShader , HDShaderIDs . g_isOrthographic , isOrthographic ? 1 : 0 ) ;
cmd . SetComputeIntParams ( buildPerTileLightListShader , HDShaderIDs . g_viDimensions , w , h ) ;
cmd . DispatchCompute ( buildPerTileLightListShader , s_GenListPerTileKernel , numTilesX , numTilesY , 1 ) ;
}
if ( m_TileSettings . enableClustered ) // works for transparencies too.
// Cluster
{
VoxelLightListGeneration ( cmd , camera , projscr , invProjscr , cameraDepthBufferRT ) ;
}
if ( m_TileSettings . enableBigTilePrepass )
cmd . SetGlobalBuffer ( HDShaderIDs . g_vBigTileLightList , s_BigTileLightList ) ;
if ( m_TileSettings . enableClustered )
// Cluster
{
cmd . SetGlobalFloat ( HDShaderIDs . g_fClustScale , m_ClustScale ) ;
cmd . SetGlobalFloat ( HDShaderIDs . g_fClustBase , k_ClustLogBase ) ;
m_ShadowMgr . RenderShadows ( m_FrameId , renderContext , cmd , cullResults , cullResults . visibleLights ) ;
}
public void RenderLightingDebug ( HDCamera hdCamera , CommandBuffer cmd , RenderTargetIdentifier colorBuffer , DebugDisplaySettings debugDisplaySettings )
public void RenderLightingDebug ( HDCamera hdCamera , CommandBuffer cmd , RenderTargetIdentifier colorBuffer , DebugDisplaySettings debugDisplaySettings , bool renderOpaque )
{
LightingDebugSettings lightingDebug = debugDisplaySettings . lightingDebugSettings ;
if ( lightingDebug . tileDebugByCategory = = TileSettings . TileDebug . None )
{
bool bUseClusteredForDeferred = ! usingFptl ;
bool bUseClusteredForDeferred = ! renderOpaque ;
int w = hdCamera . camera . pixelWidth ;
int h = hdCamera . camera . pixelHeight ;
RenderTargetIdentifier [ ] colorBuffers , RenderTargetIdentifier depthStencilBuffer , RenderTargetIdentifier depthTexture ,
LightingPassOptions options )
{
var bUseClusteredForDeferred = ! usingFptl ;
cmd . SetGlobalBuffer ( HDShaderIDs . g_vLightListGlobal , bUseClusteredForDeferred ? s_PerVoxelLightLists : s_LightList ) ;
cmd . SetGlobalBuffer ( HDShaderIDs . g_vLightListGlobal , s_LightList ) ;
if ( m_TileSettings . enableTileAndCluster & & m_TileSettings . enableComputeLightEvaluation & & options . outputSplitLighting )
{
if ( enableFeatureVariants )
{
// Tag: SUPPORT_COMPUTE_CLUSTER_OPAQUE - Update the code with following comment this if you want to do cluster opaque with compute shader (by default we support only fptl on opaque)
// kernel = usingFptl ? s_shadeOpaqueIndirectFptlKernels[variant] : s_shadeOpaqueIndirectClusteredKernels[variant];
if ( m_enableBakeShadowMask )
kernel = s_shadeOpaqueIndirectShadowMaskFptlKernels [ variant ] ;
else
{
if ( m_enableBakeShadowMask )
{
if ( debugDisplaySettings . IsDebugDisplayEnabled ( ) )
kernel = usingFptl ? s_shadeOpaqueDirectShadowMaskFptlDebugDisplayKernel : s_shadeOpaqueDirectShadowMaskClusteredDebugDisplayKernel ;
else
kernel = usingFptl ? s_shadeOpaqueDirectShadowMaskFptlKernel : s_shadeOpaqueDirectShadowMaskClusteredKernel ;
kernel = debugDisplaySettings . IsDebugDisplayEnabled ( ) ? s_shadeOpaqueDirectShadowMaskFptlDebugDisplayKernel : s_shadeOpaqueDirectShadowMaskFptlKernel ;
if ( debugDisplaySettings . IsDebugDisplayEnabled ( ) )
kernel = usingFptl ? s_shadeOpaqueDirectFptlDebugDisplayKernel : s_shadeOpaqueDirectClusteredDebugDisplayKernel ;
else
kernel = usingFptl ? s_shadeOpaqueDirectFptlKernel : s_shadeOpaqueDirectClusteredKernel ;
kernel = debugDisplaySettings . IsDebugDisplayEnabled ( ) ? s_shadeOpaqueDirectFptlDebugDisplayKernel : s_shadeOpaqueDirectFptlKernel ;
}
}
Material currentLightingMaterial = m_lightingMaterial [ options . outputSplitLighting ? 1 : 0 ,
m_TileSettings . enableTileAndCluster ? 1 : 0 ,
m_enableBakeShadowMask ? 1 : 0 ,
bUseClusteredForDeferred ? 1 : 0 ,
0 ,
debugDisplaySettings . IsDebugDisplayEnabled ( ) ? 1 : 0 ] ;
if ( options . outputSplitLighting )
else
{
// Only opaques can use FPTL, transparent must use clustered!
bool useFptl = renderOpaque & & usingFptl ;
bool useFptl = renderOpaque ;
using ( new ProfilingSample ( cmd , useFptl ? "Forward Tiled pass" : "Forward Clustered pass" , HDRenderPipeline . GetSampler ( CustomSamplerId . TPForwardTiledClusterpass ) ) )
{
cmd . SetGlobalFloat ( HDShaderIDs . _UseTileLightList , useFptl ? 1 : 0 ) ; // leaving this as a dynamic toggle for now for forward opaques to keep shader variants down.
cmd . SetGlobalBuffer ( HDShaderIDs . g_vLightListGlobal , useFptl ? s_LightList : s_PerVoxelLightLists ) ;
}
}