浏览代码

add shadow resource to renderpipeline resource

- Move shadow .shader and .compute from ShaderLibrary to Shadow folder
- Init material and compute throught SahdowAtlasInit
/main
Sebastien Lagarde 7 年前
当前提交
4d0b3071
共有 16 个文件被更改,包括 38 次插入31 次删除
  1. 18
      ScriptableRenderPipeline/Core/CoreRP/Shadow/Shadow.cs
  2. 6
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/HDAssetFactory.cs
  3. 2
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipelineAsset.asset
  4. 10
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/LightLoop.cs
  5. 6
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipelineResources/HDRenderPipelineResources.asset
  6. 2
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipelineResources/HDRenderPipelineResources.asset.meta
  7. 6
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipelineResources/RenderPipelineResources.cs
  8. 3
      TestbedPipelines/Fptl/FptlLighting.cs
  9. 3
      TestbedPipelines/OnTileDeferredPipeline/OnTileDeferredRenderPipeline.cs
  10. 4
      ScriptableRenderPipeline/Core/CoreRP/Shadow/ShadowBlurMoments.compute
  11. 9
      ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/Shadow/Resources.meta
  12. 0
      /ScriptableRenderPipeline/Core/CoreRP/Shadow/ShadowBlurMoments.compute.meta
  13. 0
      /ScriptableRenderPipeline/Core/CoreRP/Shadow/ShadowBlurMoments.compute
  14. 0
      /ScriptableRenderPipeline/Core/CoreRP/Shadow/ShadowClear.shader
  15. 0
      /ScriptableRenderPipeline/Core/CoreRP/Shadow/ShadowClear.shader.meta

18
ScriptableRenderPipeline/Core/CoreRP/Shadow/Shadow.cs


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 Dispose()
{
if( m_Shadowmap != null )
m_Shadowmap.Release();
m_Shadowmap.Release();
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_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 )
{

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


newAsset.debugViewTilesShader = Load<Shader>(HDRenderPipelinePath + "Debug/DebugViewTiles.Shader");
newAsset.debugFullScreenShader = Load<Shader>(HDRenderPipelinePath + "Debug/DebugFullScreen.Shader");
newAsset.debugColorPickerShader = Load<Shader>(HDRenderPipelinePath + "Debug/DebugColorPicker.Shader");
newAsset.debugShadowMapShader = Load<Shader>(CorePath + "Shadow/DebugDisplayShadowMap.shader");
newAsset.deferredShader = Load<Shader>(HDRenderPipelinePath + "Lighting/Deferred.Shader");
newAsset.gaussianPyramidCS = Load<ComputeShader>(HDRenderPipelinePath + "RenderPipelineResources/ColorPyramid.compute");

// Skybox/Cubemap is a builtin shader, must use Sahder.Find to access it. It is fine because we are in the editor
newAsset.skyboxCubemap = Shader.Find("Skybox/Cubemap");
// 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);

2
ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipelineAsset.asset


m_Script: {fileID: 11500000, guid: 0cf1dab834d4ec34195b920ea7bbf9ec, type: 3}
m_Name: HDRenderPipelineAsset
m_EditorClassIdentifier:
m_RenderPipelineResources: {fileID: 11400000, guid: cc60adce76ce95e4d95136664d7b9813,
m_RenderPipelineResources: {fileID: 11400000, guid: 98a64afec53fa9244ba2b64306dc5461,
type: 2}
m_FrameSettings:
enableShadow: 1

10
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 );

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()

s_DefaultTextureCube = new Cubemap(16, TextureFormat.ARGB32, false);
s_DefaultTextureCube.Apply();
InitShadowSystem(hdAsset.GetRenderPipelineSettings().shadowInitParams, shadowSettings);
InitShadowSystem(hdAsset, shadowSettings);
}
public void Cleanup()

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


type: 3}
debugColorPickerShader: {fileID: 4800000, guid: 8137b807709e178498f22ed710864bb0,
type: 3}
debugShadowMapShader: {fileID: 4800000, guid: ee25e539f5594f44085e0a9000c15d9b,
type: 3}
deferredShader: {fileID: 4800000, guid: 00dd221e34a6ab349a1196b0f2fab693, type: 3}
gaussianPyramidCS: {fileID: 7200000, guid: 4e3267a1135742441a14298d8dcac04a, type: 3}
depthPyramidCS: {fileID: 7200000, guid: 64a553bb564274041906f78ffba955e4, type: 3}

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}

2
ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipelineResources/HDRenderPipelineResources.asset.meta


fileFormatVersion: 2
guid: cc60adce76ce95e4d95136664d7b9813
guid: 98a64afec53fa9244ba2b64306dc5461
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000

6
ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipelineResources/RenderPipelineResources.cs


public Shader debugViewTilesShader;
public Shader debugFullScreenShader;
public Shader debugColorPickerShader;
public Shader debugShadowMapShader;
// Lighting resources
public Shader deferredShader;

public ComputeShader encodeBC6HCS;
public Shader cubeToPanoShader;
public Shader blitCubeTextureFace;
// Shadow
public Shader shadowClearShader;
public ComputeShader shadowBlurMoments;
public Shader debugShadowMapShader;
}
}

3
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) };

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

3
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) =>
{

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;

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


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

/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

正在加载...
取消
保存