private static ComputeBuffer s_AABBBoundsBuffer ;
private static ComputeBuffer s_LightList ;
private static ComputeBuffer s_DirLightList ;
private static ComputeBuffer s_LightIndices ;
private static ComputeBuffer s_BigTileLightList ; // used for pre-pass coarse culling on 64x64 tiles
private static int s_GenListPerBigTileKernel ;
s_AABBBoundsBuffer . Release ( ) ;
s_ConvexBoundsBuffer . Release ( ) ;
s_LightDataBuffer . Release ( ) ;
s_LightIndices . Release ( ) ;
ReleaseResolutionDependentBuffers ( ) ;
s_DirLightList . Release ( ) ;
if ( s_LightDataBuffer ! = null )
s_LightDataBuffer . Release ( ) ;
if ( s_LightIndices ! = null )
s_LightIndices . Release ( ) ;
ReleaseResolutionDependentBuffers ( ) ;
s_ConvexBoundsBuffer = new ComputeBuffer ( MaxNumLights , System . Runtime . InteropServices . Marshal . SizeOf ( typeof ( SFiniteLightBound ) ) ) ;
s_LightDataBuffer = new ComputeBuffer ( MaxNumLights , System . Runtime . InteropServices . Marshal . SizeOf ( typeof ( SFiniteLightData ) ) ) ;
s_DirLightList = new ComputeBuffer ( MaxNumDirLights , System . Runtime . InteropServices . Marshal . SizeOf ( typeof ( DirectionalLight ) ) ) ;
s_LightIndices = null ; // only used in traditional forward, will be created on demand
buildScreenAABBShader . SetBuffer ( s_GenAABBKernel , "g_data" , s_ConvexBoundsBuffer ) ;
//m_BuildScreenAABBShader.SetBuffer(kGenAABBKernel, "g_vBoundsBuffer", m_aabbBoundsBuffer);
{
sorting = { flags = SortFlags . CommonOpaque } ,
//@TODO: need to get light probes + LPPV too?
rendererConfiguration = RendererConfiguration . PerObjectLightmaps | RendererConfiguration . PerObjectLightProbe
rendererConfiguration = RendererConfiguration . PerObjectLightmaps | RendererConfiguration . PerObjectLightProbe | RendererConfiguration . ProvideLightIndices | RendererConfiguration . ProvideReflectionProbeIndices
} ;
var filterSettings = new FilterRenderersSettings ( true ) { renderQueueRange = RenderQueueRange . opaque } ;
loop . DrawRenderers ( cull . visibleRenderers , ref drawSettings , filterSettings ) ;
bool haveTiledSolution = opaquesOnly | | enableClustered ;
cmd . EnableShaderKeyword ( haveTiledSolution ? "TILED_FORWARD" : "REGULAR_FORWARD" ) ;
cmd . SetViewProjectionMatrices ( camera . worldToCameraMatrix , camera . projectionMatrix ) ;
cmd . SetGlobalBuffer ( "g_vLightListMeshInst" , s_LightIndices ) ;
loop . ExecuteCommandBuffer ( cmd ) ;
CommandBufferPool . Release ( cmd ) ;
var drawSettings = new DrawRendererSettings ( camera , new ShaderPassName ( "ForwardSinglePass" ) )
{
sorting = { flags = SortFlags . CommonOpaque } ,
rendererConfiguration = RendererConfiguration . PerObjectLightmaps | RendererConfiguration . PerObjectLightProbe
sorting = { flags = opaquesOnly ? SortFlags . CommonOpaque : SortFlags . CommonTransparent } ,
rendererConfiguration = RendererConfiguration . PerObjectLightmaps | RendererConfiguration . PerObjectLightProbe | RendererConfiguration . ProvideLightIndices | RendererConfiguration . ProvideReflectionProbeIndices
} ;
var filterSettings = new FilterRenderersSettings ( true ) { renderQueueRange = opaquesOnly ? RenderQueueRange . opaque : RenderQueueRange . transparent } ;
var boundData = new SFiniteLightBound [ numVolumes ] ;
var worldToView = WorldToCamera ( camera ) ;
var lightIndexMap = inputs . GetLightIndexMap ( ) ;
for ( int i = 0 ; i < lightIndexMap . Length ; i + + )
{
lightIndexMap [ i ] = - 1 ;
}
int lightIndexCount = inputs . GetLightIndicesCount ( ) ;
if ( s_LightIndices = = null | | lightIndexCount > s_LightIndices . count )
{
// The light indices buffer is too small, resize
if ( s_LightIndices ! = null )
s_LightIndices . Release ( ) ;
s_LightIndices = new ComputeBuffer ( lightIndexCount , System . Runtime . InteropServices . Marshal . SizeOf ( typeof ( int ) ) ) ;
}
uint lightIndex = 0 ;
foreach ( var cl in inputs . visibleLights )
{
var range = cl . range ;
{
boundData [ idxOut ] = bound ;
lightData [ idxOut ] = light ;
lightIndexMap [ lightIndex ] = idxOut ;
lightIndex + + ;
}
int numLightsOut = 0 ;
for ( int v = 0 ; v < numVolTypes ; v + + ) numLightsOut + = numEntries [ LightDefinitions . DIRECT_LIGHT , v ] ;
idxOut = numEntries2nd [ i , j ] + offsets [ i , j ] ; + + numEntries2nd [ i , j ] ;
boundData [ idxOut ] = bndData ;
lightData [ idxOut ] = lgtData ;
lightIndexMap [ lightIndex ] = idxOut ;
lightIndex + + ;
inputs . SetLightIndexMap ( lightIndexMap ) ;
int numProbesOut = 0 ;
for ( int v = 0 ; v < numVolTypes ; v + + ) numProbesOut + = numEntries [ LightDefinitions . REFLECTION_LIGHT , v ] ;
s_ConvexBoundsBuffer . SetData ( boundData ) ;
s_LightDataBuffer . SetData ( lightData ) ;
inputs . FillLightIndices ( s_LightIndices ) ;
return numLightsOut + numProbesOut ;
}
{
VoxelLightListGeneration ( cmd , camera , numLights , projscr , invProjscr ) ;
}
}
void PushGlobalParams ( Camera camera , ScriptableRenderContext loop , Matrix4x4 viewToWorld , Matrix4x4 scrProj , Matrix4x4 incScrProj , int numDirLights )