浏览代码

Merge pull request #967 from Unity-Technologies/improve-resources--management

Improve resources management
/main
GitHub 7 年前
当前提交
b878dd91
共有 31 个文件被更改,包括 136 次插入107 次删除
  1. 34
      ScriptableRenderPipeline/Core/CoreRP/Shadow/Shadow.cs
  2. 10
      ScriptableRenderPipeline/Core/CoreRP/Shadow/ShadowBase.cs
  3. 4
      ScriptableRenderPipeline/Core/CoreRP/TextureCache.cs
  4. 12
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/HDAssetFactory.cs
  5. 14
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/Reflection/HDReflectionProbeEditorUtility.cs
  6. 12
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipelineAsset.asset
  7. 30
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/LightLoop.cs
  8. 10
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Reflection/PlanarReflectionProbeCache.cs
  9. 17
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Reflection/ReflectionProbeCache.cs
  10. 6
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipelineResources/HDRenderPipelineResources.asset
  11. 9
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipelineResources/RenderPipelineResources.cs
  12. 9
      TestbedPipelines/Fptl/FptlLighting.cs
  13. 17
      TestbedPipelines/OnTileDeferredPipeline/OnTileDeferredRenderPipeline.cs
  14. 2
      Tests/GraphicsTests/RenderPipeline/HDRenderPipeline/CommonAssets/RP_Assets/HDRP_Test_Def.asset
  15. 4
      ScriptableRenderPipeline/Core/CoreRP/Shadow/ShadowBlurMoments.compute
  16. 8
      ScriptableRenderPipeline/Core/CoreRP/CoreResources.meta
  17. 8
      ScriptableRenderPipeline/Core/CoreRP/Editor/CoreResources.meta
  18. 10
      ScriptableRenderPipeline/Core/CoreRP/Editor/Resources.meta
  19. 9
      ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/Shadow/Resources.meta
  20. 9
      ScriptableRenderPipeline/Core/CoreRP/Shadow/Resources.meta
  21. 9
      ScriptableRenderPipeline/Core/CoreRP/Resources.meta
  22. 0
      /ScriptableRenderPipeline/Core/CoreRP/Editor/CoreResources
  23. 0
      /ScriptableRenderPipeline/Core/CoreRP/CoreResources
  24. 0
      /ScriptableRenderPipeline/Core/CoreRP/Shadow/ShadowBlurMoments.compute.meta
  25. 0
      /ScriptableRenderPipeline/Core/CoreRP/Shadow/ShadowBlurMoments.compute
  26. 0
      /ScriptableRenderPipeline/Core/CoreRP/Shadow/ShadowClear.shader
  27. 0
      /ScriptableRenderPipeline/Core/CoreRP/Shadow/ShadowClear.shader.meta
  28. 0
      /ScriptableRenderPipeline/Core/CoreRP/Shadow/DebugDisplayShadowMap.shader.meta
  29. 0
      /ScriptableRenderPipeline/Core/CoreRP/Shadow/DebugDisplayShadowMap.shader

34
ScriptableRenderPipeline/Core/CoreRP/Shadow/Shadow.cs


protected Vector4[] m_TmpSplits = new Vector4[k_MaxCascadesInShader];
protected float[] m_TmpBorders = new float[((k_MaxCascadesInShader+3)/4)*4];
protected ShadowAlgoVector m_SupportedAlgorithms = new ShadowAlgoVector( 0, false );
protected Material m_DebugMaterial = null;
private Material m_ClearMat;
private readonly VectorArray<CachedEntry>.Cleanup m_Cleanup;
private readonly VectorArray<CachedEntry>.Comparator<Key> m_Comparator;

public struct AtlasInit
{
public BaseInit baseInit; // the base class's initializer
public string shaderKeyword; // the global shader keyword to use when rendering the shadowmap
public BaseInit baseInit; // the base class's initializer
public string shaderKeyword; // the global shader keyword to use when rendering the shadowmap
public Shader shadowClearShader;
public ComputeShader shadowBlurMoments;
}
// UI stuff

public ShadowAtlas( ref AtlasInit init ) : base( ref init.baseInit )
{
m_ClearMat = new Material( Shader.Find( "Hidden/ScriptableRenderPipeline/ShadowClear" ) );
m_ClearMat = CoreUtils.CreateEngineMaterial(init.shadowClearShader);
m_Cleanup = (CachedEntry entry) => { Free( entry ); };
m_Comparator = (ref Key k, ref CachedEntry entry) => { return k.id == entry.key.id && k.faceIdx == entry.key.faceIdx; };

public void Initialize( AtlasInit init )
{
m_ShaderKeyword = init.shaderKeyword;
m_DebugMaterial = new Material(Shader.Find("Hidden/ScriptableRenderPipeline/DebugDisplayShadowMap")) { hideFlags = HideFlags.HideAndDontSave };
}
override public void ReserveSlots( ShadowContextStorage sc )

if( m_Shadowmap != null )
m_Shadowmap.Release();
Object.DestroyImmediate(m_DebugMaterial);
CoreUtils.Destroy(m_ClearMat);
}
override public bool Reserve( FrameId frameId, Camera camera, bool cameraRelativeRendering, ref ShadowData shadowData, ShadowRequest sr, uint width, uint height, ref VectorArray<ShadowData> entries, ref VectorArray<ShadowPayload> payload, List<VisibleLight> lights)

sd.edgeTolerance = asd.edgeTolerance;
sd.viewBias = new Vector4( asd.viewBiasMin, asd.viewBiasMax, asd.viewBiasScale, 2.0f / ce.current.proj.m00 / ce.current.viewport.width * 1.4142135623730950488016887242097f );
sd.normalBias = new Vector4( asd.normalBiasMin, asd.normalBiasMax, asd.normalBiasScale, ShadowUtils.Asfloat( flags ) );
// write :(
ce.current.shadowAlgo = (GPUShadowAlgorithm) shadowAlgo;
m_EntryCache[ceIdx] = ce;

cmd.SetViewport( m_EntryCache[i].current.viewport );
cbName = "Shadowmap.ClearRect";
cmd.BeginSample( cbName );
if( m_ClearMat == null )
m_ClearMat = new Material( Shader.Find( "Hidden/ScriptableRenderPipeline/ShadowClear" ) );
CoreUtils.DrawFullScreen( cmd, m_ClearMat, null, 0 );
cmd.EndSample( cbName );
cmd.SetViewProjectionMatrices( m_EntryCache[i].current.view, m_EntryCache[i].current.proj );

m_EntryPool.Add( ce );
}
override public void DisplayShadowMap(CommandBuffer debugCB, Vector4 scaleBias, uint slice, float screenX, float screenY, float screenSizeX, float screenSizeY, float minValue, float maxValue)
override public void DisplayShadowMap(CommandBuffer debugCB, Material debugMaterial, Vector4 scaleBias, uint slice, float screenX, float screenY, float screenSizeX, float screenSizeY, float minValue, float maxValue)
{
Vector4 validRange = new Vector4(minValue, 1.0f / (maxValue - minValue));

propertyBlock.SetFloat("_TextureSlice", (float)slice);
propertyBlock.SetVector("_ValidRange", validRange);
debugCB.SetViewport(new Rect(screenX, screenY, screenSizeX, screenSizeY));
debugCB.DrawProcedural(Matrix4x4.identity, m_DebugMaterial, m_DebugMaterial.FindPass("REGULARSHADOW"), MeshTopology.Triangles, 3, 1, propertyBlock);
debugCB.DrawProcedural(Matrix4x4.identity, debugMaterial, debugMaterial.FindPass("REGULARSHADOW"), MeshTopology.Triangles, 3, 1, propertyBlock);
}
}

m_Flags |= SystemInfo.usesReversedZBuffer ? Flags.reversed_z : 0;
m_SampleCount = sampleCount <= 0 ? 1 : (sampleCount > k_MaxSampleCount ? k_MaxSampleCount : sampleCount);
m_MomentBlurCS = Resources.Load<ComputeShader>( "ShadowBlurMoments" );
m_MomentBlurCS = init.shadowBlurMoments;
if( m_MomentBlurCS )
{

cb.EndSample("VSM conversion");
}
override public void DisplayShadowMap(CommandBuffer debugCB, Vector4 scaleBias, uint slice, float screenX, float screenY, float screenSizeX, float screenSizeY, float minValue, float maxValue)
override public void DisplayShadowMap(CommandBuffer debugCB, Material debugMaterial, Vector4 scaleBias, uint slice, float screenX, float screenY, float screenSizeX, float screenSizeY, float minValue, float maxValue)
{
Vector4 validRange = new Vector4(minValue, 1.0f / (maxValue - minValue));

propertyBlock.SetFloat("_TextureSlice", (float)slice);
propertyBlock.SetVector("_ValidRange", validRange);
debugCB.SetViewport(new Rect(screenX, screenY, screenSizeX, screenSizeY));
debugCB.DrawProcedural(Matrix4x4.identity, m_DebugMaterial, m_DebugMaterial.FindPass("VARIANCESHADOW"), MeshTopology.Triangles, 3, 1, propertyBlock);
debugCB.DrawProcedural(Matrix4x4.identity, debugMaterial, debugMaterial.FindPass("VARIANCESHADOW"), MeshTopology.Triangles, 3, 1, propertyBlock);
}
}
// -------------------------------------------------------------------------------------------------------------------------------------------------

}
}
public override void DisplayShadow(CommandBuffer cmd, int shadowRequestIndex, uint faceIndex, float screenX, float screenY, float screenSizeX, float screenSizeY, float minValue, float maxValue)
public override void DisplayShadow(CommandBuffer cmd, Material debugMaterial, int shadowRequestIndex, uint faceIndex, float screenX, float screenY, float screenSizeX, float screenSizeY, float minValue, float maxValue)
{
if (m_ShadowIndices.Count() == 0)
return;

ShadowData faceData = shadowDatas[(uint)(m_ShadowIndices[index] + offset + faceIndex)];
uint texID, samplerID;
faceData.UnpackShadowmapId(out texID, out samplerID);
m_Shadowmaps[texID].DisplayShadowMap(cmd, faceData.scaleOffset, (uint) faceData.slice, screenX, screenY, screenSizeX, screenSizeY, minValue, maxValue);
m_Shadowmaps[texID].DisplayShadowMap(cmd, debugMaterial, faceData.scaleOffset, (uint) faceData.slice, screenX, screenY, screenSizeX, screenSizeY, minValue, maxValue);
public override void DisplayShadowMap(CommandBuffer cmd, uint shadowMapIndex, uint sliceIndex, float screenX, float screenY, float screenSizeX, float screenSizeY, float minValue, float maxValue)
public override void DisplayShadowMap(CommandBuffer cmd, Material debugMaterial, uint shadowMapIndex, uint sliceIndex, float screenX, float screenY, float screenSizeX, float screenSizeY, float minValue, float maxValue)
m_Shadowmaps[index].DisplayShadowMap(cmd, new Vector4(1.0f, 1.0f, 0.0f, 0.0f), sliceIndex, screenX, screenY, screenSizeX, screenSizeY, minValue, maxValue);
m_Shadowmaps[index].DisplayShadowMap(cmd, debugMaterial, new Vector4(1.0f, 1.0f, 0.0f, 0.0f), sliceIndex, screenX, screenY, screenSizeX, screenSizeY, minValue, maxValue);
}
public override void SyncData()

10
ScriptableRenderPipeline/Core/CoreRP/Shadow/ShadowBase.cs


abstract public void Fill( ShadowContextStorage cs );
abstract public void CreateShadowmap();
abstract protected void Register( GPUShadowType type, ShadowRegistry registry );
abstract public void DisplayShadowMap(CommandBuffer cmd, Vector4 scaleBias, uint slice, float screenX, float screenY, float screenSizeX, float screenSizeY, float minValue, float maxValue);
abstract public void DisplayShadowMap(CommandBuffer cmd, Material debugMaterial, Vector4 scaleBias, uint slice, float screenX, float screenY, float screenSizeX, float screenSizeY, float minValue, float maxValue);
}
public interface IShadowManager

// Renders all shadows for lights the were deemed shadow casters after the last call to ProcessShadowRequests
void RenderShadows( FrameId frameId, ScriptableRenderContext renderContext, CommandBuffer cmd, CullResults cullResults, List<VisibleLight> lights);
// Debug function to display a shadow at the screen coordinate
void DisplayShadow(CommandBuffer cmd, int shadowIndex, uint faceIndex, float screenX, float screenY, float screenSizeX, float screenSizeY, float minValue, float maxValue);
void DisplayShadowMap(CommandBuffer cmd, uint shadowMapIndex, uint sliceIndex, float screenX, float screenY, float screenSizeX, float screenSizeY, float minValue, float maxValue);
void DisplayShadow(CommandBuffer cmd, Material debugMaterial, int shadowIndex, uint faceIndex, float screenX, float screenY, float screenSizeX, float screenSizeY, float minValue, float maxValue);
void DisplayShadowMap(CommandBuffer cmd, Material debugMaterial, uint shadowMapIndex, uint sliceIndex, float screenX, float screenY, float screenSizeX, float screenSizeY, float minValue, float maxValue);
// Synchronize data with GPU buffers
void SyncData();
// Binds resources to shader stages just before rendering the lighting pass

{
public abstract void ProcessShadowRequests( FrameId frameId, CullResults cullResults, Camera camera, bool cameraRelativeRendering, List<VisibleLight> lights, ref uint shadowRequestsCount, int[] shadowRequests, out int[] shadowDataIndices );
public abstract void RenderShadows( FrameId frameId, ScriptableRenderContext renderContext, CommandBuffer cmd, CullResults cullResults, List<VisibleLight> lights);
public abstract void DisplayShadow(CommandBuffer cmd, int shadowIndex, uint faceIndex, float screenX, float screenY, float screenSizeX, float screenSizeY, float minValue, float maxValue);
public abstract void DisplayShadowMap(CommandBuffer cmd, uint shadowMapIndex, uint sliceIndex, float screenX, float screenY, float screenSizeX, float screenSizeY, float minValue, float maxValue);
public abstract void DisplayShadow(CommandBuffer cmd, Material debugMaterial, int shadowIndex, uint faceIndex, float screenX, float screenY, float screenSizeX, float screenSizeY, float minValue, float maxValue);
public abstract void DisplayShadowMap(CommandBuffer cmd, Material debugMaterial, uint shadowMapIndex, uint sliceIndex, float screenX, float screenY, float screenSizeX, float screenSizeY, float minValue, float maxValue);
public abstract void SyncData();
public abstract void BindResources( CommandBuffer cmd, ComputeShader computeShader, int computeKernel);
public abstract void UpdateCullingParameters( ref ScriptableCullingParameters cullingParams );

4
ScriptableRenderPipeline/Core/CoreRP/TextureCache.cs


return !TextureCache.supportsCubemapArrayTextures ? (Texture)m_CacheNoCubeArray : m_Cache;
}
public bool AllocTextureArray(int numCubeMaps, int width, TextureFormat format, bool isMipMapped)
public bool AllocTextureArray(int numCubeMaps, int width, TextureFormat format, bool isMipMapped, Material cubeBlitMaterial)
{
var res = AllocTextureArray(numCubeMaps);
m_NumMipLevels = GetNumMips(width, width); // will calculate same way whether we have cube array or not

if (!m_CubeBlitMaterial) m_CubeBlitMaterial = new Material(Shader.Find("Hidden/CubeToPano")) { hideFlags = HideFlags.HideAndDontSave };
m_CubeBlitMaterial = cubeBlitMaterial;
int panoWidthTop = 4 * width;
int panoHeightTop = 2 * width;

12
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/HDAssetFactory.cs


newAsset.deferredShader = Load<Shader>(HDRenderPipelinePath + "Lighting/Deferred.Shader");
newAsset.gaussianPyramidCS = Load<ComputeShader>(HDRenderPipelinePath + "RenderPipelineResources/ColorPyramid.compute");
newAsset.depthPyramidCS = Load<ComputeShader>(HDRenderPipelinePath + "RenderPipelineResources/DepthPyramid.compute");
newAsset.copyChannelCS = Load<ComputeShader>(CorePath + "Resources/GPUCopy.compute");
newAsset.copyChannelCS = Load<ComputeShader>(CorePath + "CoreResources/GPUCopy.compute");
newAsset.applyDistortionCS = Load<ComputeShader>(HDRenderPipelinePath + "RenderPipelineResources/ApplyDistorsion.compute");
newAsset.clearDispatchIndirectShader = Load<ComputeShader>(HDRenderPipelinePath + "Lighting/LightLoop/cleardispatchindirect.compute");

newAsset.GGXConvolve = Load<Shader>(HDRenderPipelinePath + "Material/GGXConvolution/GGXConvolve.shader");
newAsset.opaqueAtmosphericScattering = Load<Shader>(HDRenderPipelinePath + "Sky/OpaqueAtmosphericScattering.shader");
newAsset.encodeBC6HCS = Load<ComputeShader>(CorePath + "Resources/EncodeBC6H.compute");
// Utilities / Core
newAsset.encodeBC6HCS = Load<ComputeShader>(CorePath + "CoreResources/EncodeBC6H.compute");
newAsset.cubeToPanoShader = Load<Shader>(CorePath + "CoreResources/CubeToPano.shader");
newAsset.blitCubeTextureFace = Load<Shader>(CorePath + "CoreResources/BlitCubeTextureFace.shader");
// Shadow
newAsset.shadowClearShader = Load<Shader>(CorePath + "Shadow/ShadowClear.shader");
newAsset.shadowBlurMoments = Load<ComputeShader>(CorePath + "Shadow/ShadowBlurMoments.compute");
newAsset.debugShadowMapShader = Load<Shader>(CorePath + "Shadow/DebugDisplayShadowMap.shader");
AssetDatabase.CreateAsset(newAsset, pathName);
ProjectWindowUtil.ShowCreatedAsset(newAsset);

14
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/Reflection/HDReflectionProbeEditorUtility.cs


[InitializeOnLoadMethod]
static void Initialize()
{
s_PreviewMaterial = new Material(Shader.Find("Debug/ReflectionProbePreview"))
{
hideFlags = HideFlags.HideAndDontSave
};
s_SphereMesh = Resources.GetBuiltinResource(typeof(Mesh), "New-Sphere.fbx") as Mesh;
}

var meshRenderer = p.GetComponent<MeshRenderer>() ?? p.gameObject.AddComponent<MeshRenderer>();
meshFilter.sharedMesh = s_SphereMesh;
// Lazy evaluation attempt to avoid shader compil error issue in Editor (The shader is not found the first time
// we load after deleting Library folder)
if (s_PreviewMaterial == null)
{
s_PreviewMaterial = new Material(Shader.Find("Debug/ReflectionProbePreview"))
{
hideFlags = HideFlags.HideAndDontSave
};
}
var material = meshRenderer.sharedMaterial;
if (material == null

12
ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipelineAsset.asset


--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1

supportSSR: 1
supportSSAO: 1
supportSubsurfaceScattering: 1
supportsForwardOnly: 0
supportForwardOnly: 0
supportMSAAAntiAliasing: 0
supportMSAA: 0
supportsMotionVectors: 1
supportsStereo: 0
supportMotionVectors: 1
supportStereo: 0
spotCookieSize: 128
cookieSize: 128
cookieTexArraySize: 16
pointCookieSize: 512
cubeCookieTexArraySize: 16

30
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/LightLoop.cs


return shadowType;
}
public ShadowSetup(ShadowInitParameters shadowInit, ShadowSettings shadowSettings, out IShadowManager shadowManager)
public ShadowSetup(RenderPipelineResources resources, ShadowInitParameters shadowInit, ShadowSettings shadowSettings, out IShadowManager shadowManager)
{
s_ShadowDataBuffer = new ComputeBuffer( k_MaxShadowDataSlots, System.Runtime.InteropServices.Marshal.SizeOf( typeof( ShadowData ) ) );
s_ShadowPayloadBuffer = new ComputeBuffer( k_MaxShadowDataSlots * k_MaxPayloadSlotsPerShadowData, System.Runtime.InteropServices.Marshal.SizeOf( typeof( ShadowPayload ) ) );

atlasInit.baseInit.maxPayloadCount = 0;
atlasInit.baseInit.shadowSupport = ShadowmapBase.ShadowSupport.Directional | ShadowmapBase.ShadowSupport.Point | ShadowmapBase.ShadowSupport.Spot;
atlasInit.shaderKeyword = null;
atlasInit.shadowClearShader = resources.shadowClearShader;
atlasInit.shadowBlurMoments = resources.shadowBlurMoments;
var varianceInit = atlasInit;
varianceInit.baseInit.shadowmapFormat = ShadowVariance.GetFormat( false, false, true );

// 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_deferredLightingMaterial;
Material m_DebugViewTilesMaterial;
Material m_DebugShadowMapMaterial;
Material m_CubeToPanoMaterial;
Light m_CurrentSunLight;
int m_CurrentSunLightShadowIndex = -1;

List<int> m_ShadowRequests = new List<int>();
Dictionary<int, int> m_ShadowIndices = new Dictionary<int, int>();
void InitShadowSystem(ShadowInitParameters initParam, ShadowSettings shadowSettings)
void InitShadowSystem(HDRenderPipelineAsset hdAsset, ShadowSettings shadowSettings)
m_ShadowSetup = new ShadowSetup(initParam, shadowSettings, out m_ShadowMgr);
m_ShadowSetup = new ShadowSetup(hdAsset.renderPipelineResources, hdAsset.GetRenderPipelineSettings().shadowInitParams, shadowSettings, out m_ShadowMgr);
}
void DeinitShadowSystem()

{
m_Resources = hdAsset.renderPipelineResources;
m_DebugViewTilesMaterial = CoreUtils.CreateEngineMaterial(m_Resources.debugViewTilesShader);
m_DebugShadowMapMaterial = CoreUtils.CreateEngineMaterial(m_Resources.debugShadowMapShader);
m_CubeToPanoMaterial = CoreUtils.CreateEngineMaterial(m_Resources.cubeToPanoShader);
m_lightList = new LightList();
m_lightList.Allocate();
m_Env2DCaptureVP.Clear();

m_CookieTexArray = new TextureCache2D();
m_CookieTexArray.AllocTextureArray(gLightLoopSettings.cookieTexArraySize, gLightLoopSettings.cookieSize, gLightLoopSettings.cookieSize, TextureFormat.RGBA32, true);
m_CubeCookieTexArray = new TextureCacheCubemap();
m_CubeCookieTexArray.AllocTextureArray(gLightLoopSettings.cubeCookieTexArraySize, gLightLoopSettings.pointCookieSize, TextureFormat.RGBA32, true);
m_CubeCookieTexArray.AllocTextureArray(gLightLoopSettings.cubeCookieTexArraySize, gLightLoopSettings.pointCookieSize, TextureFormat.RGBA32, true, m_CubeToPanoMaterial);
m_ReflectionProbeCache = new ReflectionProbeCache(iblFilterGGX, gLightLoopSettings.reflectionProbeCacheSize, gLightLoopSettings.reflectionCubemapSize, probeCacheFormat, true);
m_ReflectionProbeCache = new ReflectionProbeCache(hdAsset, iblFilterGGX, gLightLoopSettings.reflectionProbeCacheSize, gLightLoopSettings.reflectionCubemapSize, probeCacheFormat, true);
m_ReflectionPlanarProbeCache = new PlanarReflectionProbeCache(iblFilterGGX, gLightLoopSettings.planarReflectionProbeCacheSize, gLightLoopSettings.planarReflectionTextureSize, planarProbeCacheFormat, true);
m_ReflectionPlanarProbeCache = new PlanarReflectionProbeCache(hdAsset, iblFilterGGX, gLightLoopSettings.planarReflectionProbeCacheSize, gLightLoopSettings.planarReflectionTextureSize, planarProbeCacheFormat, true);
s_GenAABBKernel = buildScreenAABBShader.FindKernel("ScreenBoundsAABB");

}
}
m_DebugViewTilesMaterial = CoreUtils.CreateEngineMaterial(m_Resources.debugViewTilesShader);
s_DefaultTexture2DArray = new Texture2DArray(1, 1, 1, TextureFormat.ARGB32, false);
s_DefaultTexture2DArray.SetPixels32(new Color32[1] { new Color32(128, 128, 128, 128) }, 0);
s_DefaultTexture2DArray.Apply();

InitShadowSystem(hdAsset.GetRenderPipelineSettings().shadowInitParams, shadowSettings);
InitShadowSystem(hdAsset, shadowSettings);
}
public void Cleanup()

}
CoreUtils.Destroy(m_DebugViewTilesMaterial);
CoreUtils.Destroy(m_DebugShadowMapMaterial);
CoreUtils.Destroy(m_CubeToPanoMaterial);
}
public void NewFrame(FrameSettings frameSettings)

uint faceCount = m_ShadowMgr.GetShadowRequestFaceCount((uint)index);
for (uint i = 0; i < faceCount; ++i)
{
m_ShadowMgr.DisplayShadow(cmd, index, i, x, y, overlaySize, overlaySize, lightingDebug.shadowMinValue, lightingDebug.shadowMaxValue);
m_ShadowMgr.DisplayShadow(cmd, m_DebugShadowMapMaterial, index, i, x, y, overlaySize, overlaySize, lightingDebug.shadowMinValue, lightingDebug.shadowMaxValue);
HDUtils.NextOverlayCoord(ref x, ref y, overlaySize, overlaySize, hdCamera.actualWidth);
}
}

m_ShadowMgr.DisplayShadowMap(cmd, lightingDebug.shadowAtlasIndex, 0, x, y, overlaySize, overlaySize, lightingDebug.shadowMinValue, lightingDebug.shadowMaxValue);
m_ShadowMgr.DisplayShadowMap(cmd, m_DebugShadowMapMaterial, lightingDebug.shadowAtlasIndex, 0, x, y, overlaySize, overlaySize, lightingDebug.shadowMinValue, lightingDebug.shadowMaxValue);
HDUtils.NextOverlayCoord(ref x, ref y, overlaySize, overlaySize, hdCamera.actualWidth);
}
}

10
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Reflection/PlanarReflectionProbeCache.cs


MaterialPropertyBlock m_ConvertTextureMPB;
bool m_PerformBC6HCompression;
public PlanarReflectionProbeCache(IBLFilterGGX iblFilter, int cacheSize, int probeSize, TextureFormat probeFormat, bool isMipmaped)
public PlanarReflectionProbeCache(HDRenderPipelineAsset hdAsset, IBLFilterGGX iblFilter, int cacheSize, int probeSize, TextureFormat probeFormat, bool isMipmaped)
m_ConvertTextureMaterial = CoreUtils.CreateEngineMaterial(hdAsset.renderPipelineResources.blitCubeTextureFace);
m_ConvertTextureMPB = new MaterialPropertyBlock();
// BC6H requires CPP feature not yet available
probeFormat = TextureFormat.RGBAHalf;

m_ConvolutionTargetTexture.name = CoreUtils.GetRenderTargetAutoName(m_ProbeSize, m_ProbeSize, RenderTextureFormat.ARGBHalf, "PlanarReflectionConvolution", mips: true);
m_ConvolutionTargetTexture.Create();
m_ConvertTextureMaterial = CoreUtils.CreateEngineMaterial("Hidden/SRP/BlitCubeTextureFace");
m_ConvertTextureMPB = new MaterialPropertyBlock();
InitializeProbeBakingStates();
}
}

m_ConvolutionTargetTexture = null;
}
m_ProbeBakingState = null;
CoreUtils.Destroy(m_ConvertTextureMaterial);
}
public void NewFrame()

17
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Reflection/ReflectionProbeCache.cs


RenderTexture m_ConvolutionTargetTexture;
ProbeFilteringState[] m_ProbeBakingState;
Material m_ConvertTextureMaterial;
Material m_CubeToPano;
public ReflectionProbeCache(IBLFilterGGX iblFilter, int cacheSize, int probeSize, TextureFormat probeFormat, bool isMipmaped)
public ReflectionProbeCache(HDRenderPipelineAsset hdAsset, IBLFilterGGX iblFilter, int cacheSize, int probeSize, TextureFormat probeFormat, bool isMipmaped)
m_ConvertTextureMaterial = CoreUtils.CreateEngineMaterial(hdAsset.renderPipelineResources.blitCubeTextureFace);
m_ConvertTextureMPB = new MaterialPropertyBlock();
m_CubeToPano = CoreUtils.CreateEngineMaterial(hdAsset.renderPipelineResources.cubeToPanoShader);
// BC6H requires CPP feature not yet available
probeFormat = TextureFormat.RGBAHalf;

m_CacheSize = cacheSize;
m_TextureCache = new TextureCacheCubemap();
m_TextureCache.AllocTextureArray(cacheSize, probeSize, probeFormat, isMipmaped);
m_TextureCache.AllocTextureArray(cacheSize, probeSize, probeFormat, isMipmaped, m_CubeToPano);
m_IBLFilterGGX = iblFilter;
m_PerformBC6HCompression = probeFormat == TextureFormat.BC6H;

void Initialize()
{
if(m_TempRenderTexture == null)
if (m_TempRenderTexture == null)
{
// Temporary RT used for convolution and compression
m_TempRenderTexture = new RenderTexture(m_ProbeSize, m_ProbeSize, 1, RenderTextureFormat.ARGBHalf);

m_ConvolutionTargetTexture.autoGenerateMips = false;
m_ConvolutionTargetTexture.name = CoreUtils.GetRenderTargetAutoName(m_ProbeSize, m_ProbeSize, RenderTextureFormat.ARGBHalf, "PlanarReflection", mips : true);
m_ConvolutionTargetTexture.Create();
m_ConvertTextureMaterial = CoreUtils.CreateEngineMaterial("Hidden/SRP/BlitCubeTextureFace");
m_ConvertTextureMPB = new MaterialPropertyBlock();
InitializeProbeBakingStates();
}

m_ConvolutionTargetTexture = null;
}
m_ProbeBakingState = null;
CoreUtils.Destroy(m_ConvertTextureMaterial);
CoreUtils.Destroy(m_CubeToPano);
}
public void NewFrame()

6
ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipelineResources/HDRenderPipelineResources.asset


type: 3}
skyboxCubemap: {fileID: 103, guid: 0000000000000000f000000000000000, type: 0}
encodeBC6HCS: {fileID: 7200000, guid: aa922d239de60304f964e24488559eeb, type: 3}
cubeToPanoShader: {fileID: 4800000, guid: 595434cc3b6405246b6cd3086d0b6f7d, type: 3}
blitCubeTextureFace: {fileID: 4800000, guid: d850d0a2481878d4bbf17e5126b04163, type: 3}
shadowClearShader: {fileID: 4800000, guid: e3cab24f27741f44d8af1e94d006267c, type: 3}
shadowBlurMoments: {fileID: 7200000, guid: fb36979473602464fa32deacb9630c08, type: 3}
debugShadowMapShader: {fileID: 4800000, guid: ee25e539f5594f44085e0a9000c15d9b,
type: 3}

9
ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipelineResources/RenderPipelineResources.cs


public Shader skyboxCubemap;
// Utilities
// Utilities / Core
public Shader cubeToPanoShader;
public Shader blitCubeTextureFace;
// Shadow
public Shader shadowClearShader;
public ComputeShader shadowBlurMoments;
public Shader debugShadowMapShader;
}
}

9
TestbedPipelines/Fptl/FptlLighting.cs


atlasInit.baseInit.maxPayloadCount = 0;
atlasInit.baseInit.shadowSupport = ShadowmapBase.ShadowSupport.Directional | ShadowmapBase.ShadowSupport.Point | ShadowmapBase.ShadowSupport.Spot;
atlasInit.shaderKeyword = null;
atlasInit.shadowClearShader = Shader.Find("Hidden/ScriptableRenderPipeline/ShadowClear");
m_Shadowmaps = new ShadowmapBase[] { new ShadowAtlas(ref atlasInit) };

private Material m_BlitMaterial;
private Material m_DebugLightBoundsMaterial;
private Material m_CubeToPanoMaterial;
public void Cleanup()
{

if (m_DebugLightBoundsMaterial) DestroyImmediate(m_DebugLightBoundsMaterial);
if (m_CubeToPanoMaterial) DestroyImmediate(m_CubeToPanoMaterial);
m_CookieTexArray.Release();
m_CubeCookieTexArray.Release();

buildPerBigTileLightListShader.SetBuffer(s_GenListPerBigTileKernel, "g_data", s_ConvexBoundsBuffer);
}
m_CubeToPanoMaterial = new Material(Shader.Find("Hidden/CubeToPano")) { hideFlags = HideFlags.HideAndDontSave };
m_CubeCookieTexArray.AllocTextureArray(4, m_TextureSettings.pointCookieSize, TextureFormat.RGBA32, true);
m_CubeReflTexArray.AllocTextureArray(64, m_TextureSettings.reflectionCubemapSize, TextureCache.GetPreferredHDRCompressedTextureFormat, true);
m_CubeCookieTexArray.AllocTextureArray(4, m_TextureSettings.pointCookieSize, TextureFormat.RGBA32, true, m_CubeToPanoMaterial);
m_CubeReflTexArray.AllocTextureArray(64, m_TextureSettings.reflectionCubemapSize, TextureCache.GetPreferredHDRCompressedTextureFormat, true, m_CubeToPanoMaterial);
//m_DeferredMaterial.SetTexture("_spotCookieTextures", m_cookieTexArray.GetTexCache());
//m_DeferredMaterial.SetTexture("_pointCookieTextures", m_cubeCookieTexArray.GetTexCache());

17
TestbedPipelines/OnTileDeferredPipeline/OnTileDeferredRenderPipeline.cs


atlasInit.baseInit.maxPayloadCount = 0;
atlasInit.baseInit.shadowSupport = ShadowmapBase.ShadowSupport.Directional | ShadowmapBase.ShadowSupport.Point | ShadowmapBase.ShadowSupport.Spot;
atlasInit.shaderKeyword = null;
atlasInit.shadowClearShader = Shader.Find("Hidden/ScriptableRenderPipeline/ShadowClear");
m_Shadowmaps = new ShadowmapBase[] { new ShadowAtlas(ref atlasInit) };
m_Shadowmaps = new ShadowmapBase[] { new ShadowAtlas(ref atlasInit) };
ShadowContext.SyncDel syncer = (ShadowContext sc) =>
{

private Material m_ReflectionNearAndFarClipMaterial;
private Material m_BlitMaterial;
private Material m_CubeToPanoMaterial;
protected override void OnValidate()
protected override void OnValidate()
{
base.OnValidate();
Build();

{
if (m_BlitMaterial) DestroyImmediate(m_BlitMaterial);
if (m_CubeToPanoMaterial) DestroyImmediate(m_CubeToPanoMaterial);
if (m_BlitMaterial) DestroyImmediate(m_BlitMaterial);
if (m_DirectionalDeferredLightingMaterial) DestroyImmediate(m_DirectionalDeferredLightingMaterial);
if (m_FiniteDeferredLightingMaterial) DestroyImmediate(m_FiniteDeferredLightingMaterial);
if (m_FiniteNearDeferredLightingMaterial) DestroyImmediate(m_FiniteNearDeferredLightingMaterial);

m_ReflectionNearAndFarClipMaterial.SetInt("_CullMode", (int)CullMode.Off);
m_ReflectionNearAndFarClipMaterial.SetInt("_CompareFunc", (int)CompareFunction.Always);
m_CookieTexArray = new TextureCache2D();
m_CubeToPanoMaterial = new Material(Shader.Find("Hidden/CubeToPano")) { hideFlags = HideFlags.HideAndDontSave };
m_CookieTexArray = new TextureCache2D();
m_CubeCookieTexArray.AllocTextureArray(4, m_TextureSettings.pointCookieSize, TextureFormat.RGBA32, true);
m_CubeReflTexArray.AllocTextureArray(64, m_TextureSettings.reflectionCubemapSize, TextureCache.GetPreferredHDRCompressedTextureFormat, true);
m_CubeCookieTexArray.AllocTextureArray(4, m_TextureSettings.pointCookieSize, TextureFormat.RGBA32, true, m_CubeToPanoMaterial);
m_CubeReflTexArray.AllocTextureArray(64, m_TextureSettings.reflectionCubemapSize, TextureCache.GetPreferredHDRCompressedTextureFormat, true, m_CubeToPanoMaterial);
s_LightDataBuffer = new ComputeBuffer(k_MaxLights, System.Runtime.InteropServices.Marshal.SizeOf(typeof(SFiniteLightData)));

2
Tests/GraphicsTests/RenderPipeline/HDRenderPipeline/CommonAssets/RP_Assets/HDRP_Test_Def.asset


supportMotionVectors: 1
supportStereo: 0
lightLoopSettings:
spotCookieSize: 128
cookieSize: 128
cookieTexArraySize: 16
pointCookieSize: 512
cubeCookieTexArraySize: 16

4
ScriptableRenderPipeline/Core/CoreRP/Shadow/ShadowBlurMoments.compute


#pragma kernel main_MSAA_MSM_15 KERNEL_MAIN=main_MSAA_MSM_15 SHADOW_MOMENT_ALGORITHM=MSM MAX_MSAA=8 BLUR_SIZE=15
#pragma kernel main_MSAA_MSM_17 KERNEL_MAIN=main_MSAA_MSM_17 SHADOW_MOMENT_ALGORITHM=MSM MAX_MSAA=8 BLUR_SIZE=17
#include "../../common.hlsl"
#include "../ShadowMoments.hlsl"
#include "CoreRP/ShaderLibrary/Common.hlsl"
#include "CoreRP/ShaderLibrary/Shadow/ShadowMoments.hlsl"
#if MAX_MSAA > 1
Texture2DMS<float> depthTex;

8
ScriptableRenderPipeline/Core/CoreRP/CoreResources.meta


fileFormatVersion: 2
guid: 9b76b9e7a4790f14ca7a8b57cd46600d
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

8
ScriptableRenderPipeline/Core/CoreRP/Editor/CoreResources.meta


fileFormatVersion: 2
guid: a6209f4861b884a41ba167d4c8b50646
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

10
ScriptableRenderPipeline/Core/CoreRP/Editor/Resources.meta


fileFormatVersion: 2
guid: f00a25194233f5c4392fa05f23ecc076
folderAsset: yes
timeCreated: 1507130547
licenseType: Pro
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

9
ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/Shadow/Resources.meta


fileFormatVersion: 2
guid: f2f1273335a3dc54686dd5620bfc6790
folderAsset: yes
timeCreated: 1491321440
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

9
ScriptableRenderPipeline/Core/CoreRP/Shadow/Resources.meta


fileFormatVersion: 2
guid: 17c6560a19ee38a488a305b841122612
folderAsset: yes
timeCreated: 1496931301
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

9
ScriptableRenderPipeline/Core/CoreRP/Resources.meta


fileFormatVersion: 2
guid: 059214a704804ae4490357c01c763f42
folderAsset: yes
timeCreated: 1494862081
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

/ScriptableRenderPipeline/Core/CoreRP/Editor/Resources → /ScriptableRenderPipeline/Core/CoreRP/Editor/CoreResources

/ScriptableRenderPipeline/Core/CoreRP/Resources → /ScriptableRenderPipeline/Core/CoreRP/CoreResources

/ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/Shadow/Resources/ShadowBlurMoments.compute.meta → /ScriptableRenderPipeline/Core/CoreRP/Shadow/ShadowBlurMoments.compute.meta

/ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/Shadow/Resources/ShadowBlurMoments.compute → /ScriptableRenderPipeline/Core/CoreRP/Shadow/ShadowBlurMoments.compute

/ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/Shadow/Resources/ShadowClear.shader → /ScriptableRenderPipeline/Core/CoreRP/Shadow/ShadowClear.shader

/ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/Shadow/Resources/ShadowClear.shader.meta → /ScriptableRenderPipeline/Core/CoreRP/Shadow/ShadowClear.shader.meta

/ScriptableRenderPipeline/Core/CoreRP/Shadow/Resources/DebugDisplayShadowMap.shader.meta → /ScriptableRenderPipeline/Core/CoreRP/Shadow/DebugDisplayShadowMap.shader.meta

/ScriptableRenderPipeline/Core/CoreRP/Shadow/Resources/DebugDisplayShadowMap.shader → /ScriptableRenderPipeline/Core/CoreRP/Shadow/DebugDisplayShadowMap.shader

正在加载...
取消
保存