} ;
[GenerateHLSL]
public struct SFiniteLightData
public struct LightShapeData
public uint lightIndex ; // Index in light tabs like LightData / EnvLightData
public Vector3 lightAxisX ;
public uint lightType ;
public float cotan ;
public Vector3 boxInnerDist ;
public uint lightModel ; // DIRECT_LIGHT=0, REFLECTION_LIGHT=1
public uint lightCategory ; // DIRECT_LIGHT=0, REFLECTION_LIGHT=1
public Vector3 boxInvRange ;
public float unused2 ;
private static int s_GenListPerTileKernel ;
private static int s_GenListPerVoxelKernel ;
private static int s_ClearVoxelAtomicKernel ;
private static ComputeBuffer s_LightDataBuffer ;
private static ComputeBuffer s_LightShape DataBuffer ;
private static ComputeBuffer s_ConvexBoundsBuffer ;
private static ComputeBuffer s_AABBBoundsBuffer ;
private static ComputeBuffer s_LightList ;
// clustered light list specific buffers and data end
SFiniteLightBound [ ] m_boundData ;
SFinite LightData[ ] m_lightData ;
LightShape Data [ ] m_lightShape Data ;
int m_lightCount ;
bool usingFptl
if ( s_ConvexBoundsBuffer ! = null )
s_ConvexBoundsBuffer . Release ( ) ;
if ( s_LightDataBuffer ! = null )
s_LightDataBuffer . Release ( ) ;
if ( s_LightShape DataBuffer ! = null )
s_LightShape DataBuffer . Release ( ) ;
if ( enableClustered )
{
s_GenListPerTileKernel = buildPerTileLightListShader . FindKernel ( enableBigTilePrepass ? "TileLightListGen_SrcBigTile" : "TileLightListGen" ) ;
s_AABBBoundsBuffer = new ComputeBuffer ( 2 * MaxNumLights , 3 * sizeof ( float ) ) ;
s_ConvexBoundsBuffer = new ComputeBuffer ( MaxNumLights , System . Runtime . InteropServices . Marshal . SizeOf ( typeof ( SFiniteLightBound ) ) ) ;
s_LightDataBuffer = new ComputeBuffer ( MaxNumLights , System . Runtime . InteropServices . Marshal . SizeOf ( typeof ( SFinite LightData) ) ) ;
s_LightShape DataBuffer = new ComputeBuffer ( MaxNumLights , System . Runtime . InteropServices . Marshal . SizeOf ( typeof ( LightShape Data ) ) ) ;
buildPerTileLightListShader . SetBuffer ( s_GenListPerTileKernel , "g _v LightData" , s_LightDataBuffer ) ;
buildPerTileLightListShader . SetBuffer ( s_GenListPerTileKernel , "_LightShape Data" , s_LightShape DataBuffer ) ;
buildPerTileLightListShader . SetBuffer ( s_GenListPerTileKernel , "g_data" , s_ConvexBoundsBuffer ) ;
if ( enableClustered )
s_ClearVoxelAtomicKernel = buildPerVoxelLightListShader . FindKernel ( "ClearAtomic" ) ;
buildPerVoxelLightListShader . SetBuffer ( s_GenListPerVoxelKernel , "g_vBoundsBuffer" , s_AABBBoundsBuffer ) ;
buildPerVoxelLightListShader . SetBuffer ( s_GenListPerVoxelKernel , "g _v LightData" , s_LightDataBuffer ) ;
buildPerVoxelLightListShader . SetBuffer ( s_GenListPerVoxelKernel , "_LightShape Data" , s_LightShape DataBuffer ) ;
buildPerVoxelLightListShader . SetBuffer ( s_GenListPerVoxelKernel , "g_data" , s_ConvexBoundsBuffer ) ;
s_GlobalLightListAtomic = new ComputeBuffer ( 1 , sizeof ( uint ) ) ;
{
s_GenListPerBigTileKernel = buildPerBigTileLightListShader . FindKernel ( "BigTileLightListGen" ) ;
buildPerBigTileLightListShader . SetBuffer ( s_GenListPerBigTileKernel , "g_vBoundsBuffer" , s_AABBBoundsBuffer ) ;
buildPerBigTileLightListShader . SetBuffer ( s_GenListPerBigTileKernel , "g _v LightData" , s_LightDataBuffer ) ;
buildPerBigTileLightListShader . SetBuffer ( s_GenListPerBigTileKernel , "_LightShape Data" , s_LightShape DataBuffer ) ;
m_lightData = new SFinite LightData[ MaxNumLights ] ;
m_lightShape Data = new LightShape Data [ MaxNumLights ] ;
m_lightCount = 0 ;
s_DirectionalLights = new ComputeBuffer ( HDRenderLoop . k_MaxDirectionalLightsOnSCreen , System . Runtime . InteropServices . Marshal . SizeOf ( typeof ( DirectionalLightData ) ) ) ;
s_AABBBoundsBuffer . Release ( ) ;
s_ConvexBoundsBuffer . Release ( ) ;
s_LightDataBuffer . Release ( ) ;
s_LightShape DataBuffer . Release ( ) ;
ReleaseResolutionDependentBuffers ( ) ;
if ( enableClustered )
// add decals here too similar to the above
// establish offsets
for ( var m = 0 ; m < numModels ; m + + )
for ( int m = 0 ; m < numModels ; m + + )
for ( var v = 1 ; v < numVolTypes ; v + + )
for ( int v = 1 ; v < numVolTypes ; v + + )
{
offsets [ m , v ] = numEntries [ m , v - 1 ] + offsets [ m , v - 1 ] ;
}
// Fill bounds
var bound = new SFiniteLightBound ( ) ;
var lightData = new SFiniteLightData ( ) ;
var lightShapeData = new LightShapeData ( ) ;
lightData . lightModel = ( uint ) LightDefinitions . DIRECT_LIGHT ;
lightShapeData . lightCategory = ( uint ) LightDefinitions . DIRECT_LIGHT ;
lightShapeData . lightIndex = ( uint ) lightIndex ;
if ( punctualLightData . lightType = = GPULightType . Spot | | punctualLightData . lightType = = GPULightType . ProjectorPyramid )
{
bound . scaleXY = squeeze ? new Vector2 ( 0.01f , 0.01f ) : new Vector2 ( 1.0f , 1.0f ) ;
lightData . lightAxisX = vx ;
lightData . lightAxisY = vy ;
lightData . lightAxisZ = vz ;
lightData . lightType = ( uint ) LightDefinitions . SPOT_LIGHT ;
lightData . lightPos = worldToView . MultiplyPoint ( lightPos ) ;
lightData . radiusSq = range * range ;
lightData . cotan = cota ;
lightShape Data . lightAxisX = vx ;
lightShape Data . lightAxisY = vy ;
lightShape Data . lightAxisZ = vz ;
lightShape Data . lightType = ( uint ) LightDefinitions . SPOT_LIGHT ;
lightShape Data . lightPos = worldToView . MultiplyPoint ( lightPos ) ;
lightShape Data . radiusSq = range * range ;
lightShape Data . cotan = cota ;
int i = LightDefinitions . DIRECT_LIGHT , j = LightDefinitions . SPOT_LIGHT ;
index = numEntries2nd [ i , j ] + offsets [ i , j ] ; + + numEntries2nd [ i , j ] ;
Vector3 vz = lightToView . GetColumn ( 2 ) ;
// fill up ldata
lightData . lightAxisX = vx ;
lightData . lightAxisY = vy ;
lightData . lightAxisZ = vz ;
lightData . lightType = ( uint ) LightDefinitions . SPHERE_LIGHT ;
lightData . lightPos = bound . center ;
lightData . radiusSq = range * range ;
lightShape Data . lightAxisX = vx ;
lightShape Data . lightAxisY = vy ;
lightShape Data . lightAxisZ = vz ;
lightShape Data . lightType = ( uint ) LightDefinitions . SPHERE_LIGHT ;
lightShape Data . lightPos = bound . center ;
lightShape Data . radiusSq = range * range ;
int i = LightDefinitions . DIRECT_LIGHT , j = LightDefinitions . SPHERE_LIGHT ;
index = numEntries2nd [ i , j ] + offsets [ i , j ] ; + + numEntries2nd [ i , j ] ;
m_lightData [ index ] = lightData ;
m_lightShapeData [ index ] = lightShapeData ;
}
for ( int envIndex = 0 ; envIndex < lightList . envLights . Count ; envIndex + + )
var bound = new SFiniteLightBound ( ) ;
var lightData = new SFiniteLightData ( ) ;
var bound = new SFiniteLightBound ( ) ;
var bnds = probe . bounds ;
var boxOffset = probe . center ; // reflection volume offset relative to cube map capture point
bound . scaleXY . Set ( 1.0f , 1.0f ) ;
bound . radius = combinedExtent . magnitude ;
lightData . lightPos = Cw ;
lightData . lightAxisX = vx ;
lightData . lightAxisY = vy ;
lightData . lightAxisZ = vz ;
var delta = combinedExtent - e ;
lightData . boxInnerDist = e ;
lightData . boxInvRange . Set ( 1.0f / delta . x , 1.0f / delta . y , 1.0f / delta . z ) ;
var lightShapeData = new LightShapeData ( ) ;
lightShapeData . lightType = ( uint ) LightDefinitions . BOX_LIGHT ;
lightShapeData . lightCategory = ( uint ) LightDefinitions . REFLECTION_LIGHT ;
lightShapeData . lightIndex = ( uint ) envIndex ;
lightData . lightType = ( uint ) LightDefinitions . BOX_LIGHT ;
lightData . lightModel = ( uint ) LightDefinitions . REFLECTION_LIGHT ;
lightShapeData . lightPos = Cw ;
lightShapeData . lightAxisX = vx ;
lightShapeData . lightAxisY = vy ;
lightShapeData . lightAxisZ = vz ;
var delta = combinedExtent - e ;
lightShapeData . boxInnerDist = e ;
lightShapeData . boxInvRange . Set ( 1.0f / delta . x , 1.0f / delta . y , 1.0f / delta . z ) ;
m_lightData [ index ] = lightData ;
m_lightShapeData [ index ] = lightShapeData ;
}
// Sanity check
m_lightCount = lightList . punctualLights . Count + lightList . envLights . Count ;
s_ConvexBoundsBuffer . SetData ( m_boundData ) ; // TODO: check with Vlad what is happening here, do we copy 1024 element always ? Could we setup the size we want to copy ?
s_LightDataBuffer . SetData ( m_lightData ) ;
s_LightShape DataBuffer . SetData ( m_lightShape Data ) ;
}
void VoxelLightListGeneration ( CommandBuffer cmd , Camera camera , Matrix4x4 projscr , Matrix4x4 invProjscr , RenderTargetIdentifier cameraDepthBufferRT )
{
cmd . SetComputeIntParams ( buildPerTileLightListShader , "g_viDimensions" , new int [ 2 ] { w , h } ) ;
cmd . SetComputeIntParam ( buildPerTileLightListShader , "g_iNrVisibLights" , m_lightCount ) ;
cmd . SetComputeIntParam ( buildPerTileLightListShader , "_PunctualLightCount" , lightList . punctualLights . Count ) ;
Utilities . SetMatrixCS ( cmd , buildPerTileLightListShader , "g_mScrProjection" , projscr ) ;
Utilities . SetMatrixCS ( cmd , buildPerTileLightListShader , "g_mInvScrProjection" , invProjscr ) ;
cmd . SetComputeTextureParam ( buildPerTileLightListShader , s_GenListPerTileKernel , "g_depth_tex" , cameraDepthBufferRT ) ;
cmd . SetComputeTextureParam ( deferredComputeShader , kernel , "_LightTextureB0" , m_LightAttentuationTexture ) ;
cmd . SetComputeBufferParam ( deferredComputeShader , kernel , "g_vLightListGlobal" , bUseClusteredForDeferred ? s_PerVoxelLightLists : s_LightList ) ;
cmd . SetComputeBufferParam ( deferredComputeShader , kernel , "g _v LightData" , s_LightDataBuffer ) ;
cmd . SetComputeBufferParam ( deferredComputeShader , kernel , "_LightShape Data" , s_LightShape DataBuffer ) ;
cmd . SetComputeBufferParam ( deferredComputeShader , kernel , "g_dirLightData" , s_DirLightList ) ;
var defdecode = ReflectionProbe . GetDefaultTextureHDRDecodeValues ( ) ;