atlasInit . shadowClearShader = resources . shadowClearShader ;
atlasInit . shadowBlurMoments = resources . shadowBlurMoments ;
/ *
// Code kept here for reference if we want to add VSM/MSM later on
varianceInit . baseInit . shadowmapFormat = ShadowVariance . GetFormat ( false , false , true ) ;
varianceInit . baseInit . shadowmapFormat = ShadowVariance . GetFormat ( false , false , true ) ;
varianceInit2 . baseInit . shadowmapFormat = ShadowVariance . GetFormat ( true , true , false ) ;
varianceInit2 . baseInit . shadowmapFormat = ShadowVariance . GetFormat ( true , true , false ) ;
varianceInit3 . baseInit . shadowmapFormat = ShadowVariance . GetFormat ( true , false , true ) ;
varianceInit3 . baseInit . shadowmapFormat = ShadowVariance . GetFormat ( true , false , true ) ;
m_Shadowmaps = new ShadowmapBase [ ] { new ShadowAtlas ( ref atlasInit ) , new ShadowVariance ( ref varianceInit ) , new ShadowVariance ( ref varianceInit2 ) , new ShadowVariance ( ref varianceInit3 ) } ;
* /
m_Shadowmaps = new ShadowmapBase [ ] { new ShadowVariance ( ref varianceInit ) , new ShadowVariance ( ref varianceInit2 ) , new ShadowVariance ( ref varianceInit3 ) , new ShadowAtlas ( ref atlasInit ) } ;
m_Shadowmaps = new ShadowmapBase [ ] { new ShadowAtlas ( ref atlasInit ) } ;
ShadowContext . SyncDel syncer = ( ShadowContext sc ) = >
{
cb . SetGlobalBuffer ( HDShaderIDs . _ShadowDatasExp , s_ShadowDataBuffer ) ;
cb . SetGlobalBuffer ( HDShaderIDs . _ShadowPayloads , s_ShadowPayloadBuffer ) ;
// bind textures
cb . SetGlobalTexture ( HDShaderIDs . _ShadowmapExp_VSM_0 , tex [ 0 ] ) ;
cb . SetGlobalTexture ( HDShaderIDs . _ShadowmapExp_VSM_1 , tex [ 1 ] ) ;
cb . SetGlobalTexture ( HDShaderIDs . _ShadowmapExp_VSM_2 , tex [ 2 ] ) ;
cb . SetGlobalTexture ( HDShaderIDs . _ShadowmapExp_PCF , tex [ 3 ] ) ;
cb . SetGlobalTexture ( HDShaderIDs . _ShadowmapExp_PCF , tex [ 0 ] ) ;
// Code kept here for reference if we want to add VSM/MSM later on
//cb.SetGlobalTexture(HDShaderIDs._ShadowmapExp_VSM_0, tex[1]);
//cb.SetGlobalTexture(HDShaderIDs._ShadowmapExp_VSM_1, tex[2]);
//cb.SetGlobalTexture(HDShaderIDs._ShadowmapExp_VSM_2, tex[3])
// TODO: Currently samplers are hard coded in ShadowContext.hlsl, so we can't really set them here
} ;
{
if ( m_Shadowmaps ! = null )
{
( m_Shadowmaps [ 0 ] as ShadowAtlas ) . Dispose ( ) ;
( m_Shadowmaps [ 1 ] as ShadowAtlas ) . Dispose ( ) ;
( m_Shadowmaps [ 2 ] as ShadowAtlas ) . Dispose ( ) ;
( m_Shadowmaps [ 3 ] as ShadowAtlas ) . Dispose ( ) ;
foreach ( var shadowMap in m_Shadowmaps )
{
( shadowMap as ShadowAtlas ) . Dispose ( ) ;
}
m_Shadowmaps = null ;
}
m_ShadowMgr = null ;
public static readonly Vector3 k_BoxCullingExtentThreshold = Vector3 . one * 0.01f ;
// Static keyword is required here else we get a "DestroyBuffer can only be called from the main thread"
static ComputeBuffer s _DirectionalLightDatas = null ;
static ComputeBuffer s _LightDatas = null ;
static ComputeBuffer s _EnvLightDatas = null ;
static ComputeBuffer s _shadowDatas = null ;
static ComputeBuffer s _DecalDatas = null ;
ComputeBuffer m _DirectionalLightDatas = null ;
ComputeBuffer m _LightDatas = null ;
ComputeBuffer m _EnvLightDatas = null ;
ComputeBuffer m _shadowDatas = null ;
ComputeBuffer m _DecalDatas = null ;
static Texture2DArray s _DefaultTexture2DArray;
static Cubemap s _DefaultTextureCube;
Texture2DArray m _DefaultTexture2DArray;
Cubemap m _DefaultTextureCube;
PlanarReflectionProbeCache m_ReflectionPlanarProbeCache ;
ReflectionProbeCache m_ReflectionProbeCache ;
for ( int i = 0 , c = Mathf . Max ( 1 , hdAsset . renderPipelineSettings . lightLoopSettings . maxPlanarReflectionProbes ) ; i < c ; + + i )
m_Env2DCaptureVP . Add ( Matrix4x4 . identity ) ;
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 ) ) ) ;
s _shadowDatas = new ComputeBuffer ( k_MaxCascadeCount + k_MaxShadowOnScreen , System . Runtime . InteropServices . Marshal . SizeOf ( typeof ( ShadowData ) ) ) ;
s _DecalDatas = new ComputeBuffer ( k_MaxDecalsOnScreen , System . Runtime . InteropServices . Marshal . SizeOf ( typeof ( DecalData ) ) ) ;
m _DirectionalLightDatas = new ComputeBuffer ( k_MaxDirectionalLightsOnScreen , System . Runtime . InteropServices . Marshal . SizeOf ( typeof ( DirectionalLightData ) ) ) ;
m _LightDatas = new ComputeBuffer ( k_MaxPunctualLightsOnScreen + k_MaxAreaLightsOnScreen , System . Runtime . InteropServices . Marshal . SizeOf ( typeof ( LightData ) ) ) ;
m _EnvLightDatas = new ComputeBuffer ( k_MaxEnvLightsOnScreen , System . Runtime . InteropServices . Marshal . SizeOf ( typeof ( EnvLightData ) ) ) ;
m _shadowDatas = new ComputeBuffer ( k_MaxCascadeCount + k_MaxShadowOnScreen , System . Runtime . InteropServices . Marshal . SizeOf ( typeof ( ShadowData ) ) ) ;
m _DecalDatas = new ComputeBuffer ( k_MaxDecalsOnScreen , System . Runtime . InteropServices . Marshal . SizeOf ( typeof ( DecalData ) ) ) ;
m_CookieTexArray = new TextureCache2D ( ) ;
m_CookieTexArray = new TextureCache2D ( "Cookie" ) ;
m_CubeCookieTexArray = new TextureCacheCubemap ( ) ;
m_CubeCookieTexArray = new TextureCacheCubemap ( "Cookie" ) ;
m_CubeCookieTexArray . AllocTextureArray ( gLightLoopSettings . cubeCookieTexArraySize , gLightLoopSettings . pointCookieSize , TextureFormat . RGBA32 , true , m_CubeToPanoMaterial ) ;
TextureFormat probeCacheFormat = gLightLoopSettings . reflectionCacheCompressed ? TextureFormat . BC6H : TextureFormat . RGBAHalf ;
int index = GetDeferredLightingMaterialIndex ( outputSplitLighting , lightLoopTilePass , shadowMask , debugDisplay ) ;
m_deferredLightingMaterial [ index ] = CoreUtils . CreateEngineMaterial ( m_Resources . deferredShader ) ;
m_deferredLightingMaterial [ index ] . name = string . Format ( "{0}_{1}" , m_Resources . deferredShader . name , index ) ;
CoreUtils . SetKeyword ( m_deferredLightingMaterial [ index ] , "OUTPUT_SPLIT_LIGHTING" , outputSplitLighting = = 1 ) ;
CoreUtils . SelectKeyword ( m_deferredLightingMaterial [ index ] , "LIGHTLOOP_TILE_PASS" , "LIGHTLOOP_SINGLE_PASS" , lightLoopTilePass = = 1 ) ;
CoreUtils . SetKeyword ( m_deferredLightingMaterial [ index ] , "SHADOWS_SHADOWMASK" , shadowMask = = 1 ) ;
}
}
s_DefaultTexture2DArray = new Texture2DArray ( 1 , 1 , 1 , TextureFormat . ARGB32 , false ) ;
s_DefaultTexture2DArray . SetPixels32 ( new Color32 [ 1 ] { new Color32 ( 1 2 8 , 1 2 8 , 1 2 8 , 1 2 8 ) } , 0 ) ;
s_DefaultTexture2DArray . Apply ( ) ;
m_DefaultTexture2DArray = new Texture2DArray ( 1 , 1 , 1 , TextureFormat . ARGB32 , false ) ;
m_DefaultTexture2DArray . hideFlags = HideFlags . HideAndDontSave ;
m_DefaultTexture2DArray . name = CoreUtils . GetTextureAutoName ( 1 , 1 , TextureFormat . ARGB32 , depth : 1 , dim : TextureDimension . Tex2DArray , name : "LightLoopDefault" ) ;
m_DefaultTexture2DArray . SetPixels32 ( new Color32 [ 1 ] { new Color32 ( 1 2 8 , 1 2 8 , 1 2 8 , 1 2 8 ) } , 0 ) ;
m_DefaultTexture2DArray . Apply ( ) ;
s_DefaultTextureCube = new Cubemap ( 1 6 , TextureFormat . ARGB32 , false ) ;
s_DefaultTextureCube . Apply ( ) ;
m_DefaultTextureCube = new Cubemap ( 1 6 , TextureFormat . ARGB32 , false ) ;
m_DefaultTextureCube . Apply ( ) ;
InitShadowSystem ( hdAsset , shadowSettings ) ;
}
DeinitShadowSystem ( ) ;
CoreUtils . SafeRelease ( s_DirectionalLightDatas ) ;
CoreUtils . SafeRelease ( s_LightDatas ) ;
CoreUtils . SafeRelease ( s_EnvLightDatas ) ;
CoreUtils . SafeRelease ( s_shadowDatas ) ;
CoreUtils . SafeRelease ( s_DecalDatas ) ;
CoreUtils . Destroy ( m_DefaultTexture2DArray ) ;
CoreUtils . Destroy ( m_DefaultTextureCube ) ;
CoreUtils . SafeRelease ( m_DirectionalLightDatas ) ;
CoreUtils . SafeRelease ( m_LightDatas ) ;
CoreUtils . SafeRelease ( m_EnvLightDatas ) ;
CoreUtils . SafeRelease ( m_shadowDatas ) ;
CoreUtils . SafeRelease ( m_DecalDatas ) ;
if ( m_ReflectionProbeCache ! = null )
{
void UpdateDataBuffers ( )
{
s _DirectionalLightDatas. SetData ( m_lightList . directionalLights ) ;
s _LightDatas. SetData ( m_lightList . lights ) ;
s _EnvLightDatas. SetData ( m_lightList . envLights ) ;
s _shadowDatas. SetData ( m_lightList . shadows ) ;
s _DecalDatas. SetData ( DecalSystem . m_DecalDatas , 0 , 0 , Math . Min ( DecalSystem . m_DecalDatasCount , k_MaxDecalsOnScreen ) ) ; // don't add more than the size of the buffer
m _DirectionalLightDatas. SetData ( m_lightList . directionalLights ) ;
m _LightDatas. SetData ( m_lightList . lights ) ;
m _EnvLightDatas. SetData ( m_lightList . envLights ) ;
m _shadowDatas. SetData ( m_lightList . shadows ) ;
m _DecalDatas. SetData ( DecalSystem . m_DecalDatas , 0 , 0 , Math . Min ( DecalSystem . m_DecalDatasCount , k_MaxDecalsOnScreen ) ) ; // don't add more than the size of the buffer
// These two buffers have been set in Rebuild()
s_ConvexBoundsBuffer . SetData ( m_lightList . bounds ) ;
cmd . SetGlobalTexture ( HDShaderIDs . _Env2DTextures , m_ReflectionPlanarProbeCache . GetTexCache ( ) ) ;
cmd . SetGlobalMatrixArray ( HDShaderIDs . _Env2DCaptureVP , m_Env2DCaptureVP ) ;
cmd . SetGlobalBuffer ( HDShaderIDs . _DirectionalLightDatas , s _DirectionalLightDatas) ;
cmd . SetGlobalBuffer ( HDShaderIDs . _DirectionalLightDatas , m _DirectionalLightDatas) ;
cmd . SetGlobalBuffer ( HDShaderIDs . _LightDatas , s _LightDatas) ;
cmd . SetGlobalBuffer ( HDShaderIDs . _LightDatas , m _LightDatas) ;
cmd . SetGlobalBuffer ( HDShaderIDs . _EnvLightDatas , s _EnvLightDatas) ;
cmd . SetGlobalBuffer ( HDShaderIDs . _EnvLightDatas , m _EnvLightDatas) ;
cmd . SetGlobalBuffer ( HDShaderIDs . _DecalDatas , s _DecalDatas) ;
cmd . SetGlobalBuffer ( HDShaderIDs . _DecalDatas , m _DecalDatas) ;
cmd . SetGlobalBuffer ( HDShaderIDs . _ShadowDatas , s _shadowDatas) ;
cmd . SetGlobalBuffer ( HDShaderIDs . _ShadowDatas , m _shadowDatas) ;
cmd . SetGlobalInt ( HDShaderIDs . _NumTileFtplX , GetNumTileFtplX ( hdCamera ) ) ;
cmd . SetGlobalInt ( HDShaderIDs . _NumTileFtplY , GetNumTileFtplY ( hdCamera ) ) ;