浏览代码

Converted ShadowPass to the new ScriptableRenderPass

/main
Felipe Lira 7 年前
当前提交
998892b5
共有 6 个文件被更改,包括 50 次插入34 次删除
  1. 18
      ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipeline.cs
  2. 7
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Passes/DepthOnlyPass.cs
  3. 9
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Passes/ScriptableRenderPass.cs
  4. 50
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Passes/ShadowPass.cs
  5. 0
      /ScriptableRenderPipeline/LightweightPipeline/LWRP/Passes/ShadowPass.cs.meta
  6. 0
      /ScriptableRenderPipeline/LightweightPipeline/LWRP/Passes/ShadowPass.cs

18
ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipeline.cs


private readonly LightweightPipelineAsset m_Asset;
DepthOnlyPass m_DepthOnlyPass;
private LightweightShadowPass m_ShadowPass;
private ShadowPass m_ShadowPass;
// Maximum amount of visible lights the shader can process. This controls the constant global light buffer size.
// It must match the MAX_VISIBLE_LIGHTS in LightweightInput.cginc

private bool m_UseComputeBuffer;
// Pipeline pass names
private static readonly ShaderPassName m_DepthPrepass = new ShaderPassName("DepthOnly");
private static readonly ShaderPassName m_LitPassName = new ShaderPassName("LightweightForward");
private static readonly ShaderPassName m_UnlitPassName = new ShaderPassName("SRPDefaultUnlit"); // Renders all shaders without a lightmode tag

m_LocalLightIndices = new List<int>(m_MaxLocalLightsShadedPerPass);
m_DepthOnlyPass = new DepthOnlyPass(null, RenderTextureFormat.Depth);
m_ShadowPass = new LightweightShadowPass(m_Asset, kMaxVisibleLocalLights);
RenderTextureFormat shadowmapFormat =
(SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.Shadowmap))
? RenderTextureFormat.Shadowmap
: RenderTextureFormat.Depth;
m_ShadowPass = new ShadowPass(m_Asset, kMaxVisibleLocalLights, null, shadowmapFormat);
// Let engine know we have MSAA on for cases where we support MSAA backbuffer
if (QualitySettings.antiAliasing != m_Asset.MSAASampleCount)

LightData lightData;
InitializeLightData(visibleLights, out lightData);
bool screenspaceShadows = m_ShadowPass.Execute(ref m_CullResults, ref lightData, ref context);
m_ShadowPass.Execute(ref context, ref m_CullResults, ref lightData, camera, false);
bool screenspaceShadows = m_ShadowPass.requireScreenSpaceResolve;
FrameRenderingConfiguration frameRenderingConfiguration;
SetupFrameRenderingConfiguration(out frameRenderingConfiguration, screenspaceShadows, stereoEnabled, sceneViewCamera);

context.SetupCameraProperties(m_CurrCamera, stereoEnabled);
if (CoreUtils.HasFlag(frameRenderingConfiguration, FrameRenderingConfiguration.DepthPrePass))
m_DepthOnlyPass.Execute(context, camera, ref m_CullResults, stereoEnabled);
m_DepthOnlyPass.Execute(ref context, ref m_CullResults, ref lightData, camera, stereoEnabled);
if (screenspaceShadows)
m_ShadowPass.CollectShadows(m_CurrCamera, frameRenderingConfiguration, ref context);

cmd.GetTemporaryRT(CameraRenderTargetID.depthCopy, depthRTDesc, FilterMode.Point);
}
m_ShadowPass.InitializeResources(cmd, baseDesc);
m_ShadowPass.BindSurface(cmd, baseDesc, 1);
}
var colorRTDesc = baseDesc;

7
ScriptableRenderPipeline/LightweightPipeline/LWRP/Passes/DepthOnlyPass.cs


bool m_Disposed;
FilterRenderersSettings m_FilterSettings;
public DepthOnlyPass(RenderTextureFormat[] inputColorAttachments, RenderTextureFormat inputDepthAttachment) :
base(inputColorAttachments, inputDepthAttachment)
public DepthOnlyPass(RenderTextureFormat[] colorAttachments, RenderTextureFormat depthAttachment) :
base(colorAttachments, depthAttachment)
{
RegisterShaderPassName("DepthOnly");
depthTextureID = Shader.PropertyToID("_CameraDepthTexture");

m_Disposed = false;
}
public override void Execute(ScriptableRenderContext context, Camera camera, ref CullResults cullResults, bool stereoRendering)
public override void Execute(ref ScriptableRenderContext context, ref CullResults cullResults, ref LightData lightData,
Camera camera, bool stereoRendering)
{
CommandBuffer cmd = CommandBufferPool.Get(kCommandBufferTag);
using (new ProfilingSample(cmd, kProfilerTag))

9
ScriptableRenderPipeline/LightweightPipeline/LWRP/Passes/ScriptableRenderPass.cs


{
public abstract class ScriptableRenderPass
{
public ScriptableRenderPass(RenderTextureFormat[] inputColorAttachments, RenderTextureFormat inputDepthAttachment)
public ScriptableRenderPass(RenderTextureFormat[] colorAttachments, RenderTextureFormat depthAttachment)
colorAttachments = inputColorAttachments;
depthAttachment = inputDepthAttachment;
this.colorAttachments = colorAttachments;
this.depthAttachment = depthAttachment;
public abstract void Execute(ScriptableRenderContext context, Camera camera, ref CullResults cullResults, bool stereoRendering);
public abstract void Execute(ref ScriptableRenderContext context, ref CullResults cullResults, ref LightData lightData,
Camera camera, bool stereoRendering);
public abstract void Dispose(CommandBuffer cmd);

50
ScriptableRenderPipeline/LightweightPipeline/LWRP/Passes/ShadowPass.cs


}
}
public class LightweightShadowPass
public class ShadowPass : ScriptableRenderPass
{
public bool IsDirectionalShadowsEnabled { get { return m_ShadowSettings.supportsDirectionalShadows; } }
public bool IsLocalShadowsEnabled { get { return m_ShadowSettings.supportsLocalShadows; } }

public bool IsSoftShadowsEnabled { get { return m_ShadowSettings.supportsSoftShadows; } }
// TODO: Remove this after we handle the passes dependencies
public bool requireScreenSpaceResolve { get; private set; }
public float RenderingDistance { get { return m_ShadowSettings.maxShadowDistance; } }

private ShadowSliceData[] m_LocalLightSlices;
private float[] m_LocalShadowStrength;
public LightweightShadowPass(LightweightPipelineAsset pipelineAsset, int maxLocalLightsCount)
public ShadowPass(LightweightPipelineAsset pipelineAsset, int maxLocalLightsCount,
RenderTextureFormat[] colorAttachments, RenderTextureFormat depthAttachment) :
base(colorAttachments, depthAttachment)
RegisterShaderPassName("ShadowCaster");
m_DirectionalShadowMatrices = new Matrix4x4[kMaxCascades + 1];
m_CascadeSlices = new ShadowSliceData[kMaxCascades];

Clear();
}
public void InitializeResources(CommandBuffer cmd, RenderTextureDescriptor renderTextureDesc)
public override void BindSurface(CommandBuffer cmd, RenderTextureDescriptor attachmentDescriptor, int samples)
renderTextureDesc.depthBufferBits = 0;
renderTextureDesc.colorFormat = m_ShadowSettings.screenspaceShadowmapTextureFormat;
cmd.GetTemporaryRT(m_ScreenSpaceShadowmapID, renderTextureDesc, FilterMode.Bilinear);
attachmentDescriptor.depthBufferBits = 0;
attachmentDescriptor.colorFormat = m_ShadowSettings.screenspaceShadowmapTextureFormat;
cmd.GetTemporaryRT(m_ScreenSpaceShadowmapID, attachmentDescriptor, FilterMode.Bilinear);
public override void Execute(ref ScriptableRenderContext context, ref CullResults cullResults, ref LightData lightData,
Camera camera, bool stereoRendering)
{
Clear();
public void Dispose(CommandBuffer cmd)
bool directionalShadowmapRendered = false;
if (IsDirectionalShadowsEnabled)
directionalShadowmapRendered = RenderDirectionalCascadeShadowmap(ref cullResults, ref lightData, ref context);
if (IsLocalShadowsEnabled)
RenderLocalShadowmapAtlas(ref cullResults, ref lightData, ref context);
requireScreenSpaceResolve = directionalShadowmapRendered && m_ShadowSettings.screenSpace;
}
public override void Dispose(CommandBuffer cmd)
{
cmd.ReleaseTemporaryRT(m_ScreenSpaceShadowmapID);

RenderTexture.ReleaseTemporary(m_LocalShadowmapTexture);
m_LocalShadowmapTexture = null;
}
}
public bool Execute(ref CullResults cullResults, ref LightData lightData, ref ScriptableRenderContext context)
{
Clear();
bool directionalShadowmapRendered = false;
if (IsDirectionalShadowsEnabled)
directionalShadowmapRendered = RenderDirectionalCascadeShadowmap(ref cullResults, ref lightData, ref context);
if (IsLocalShadowsEnabled)
RenderLocalShadowmapAtlas(ref cullResults, ref lightData, ref context);
return directionalShadowmapRendered && m_ShadowSettings.screenSpace;
}
public void CollectShadows(Camera camera, FrameRenderingConfiguration frameRenderingConfiguration, ref ScriptableRenderContext context)

for (int i = 0; i < m_LocalShadowStrength.Length; ++i)
m_LocalShadowStrength[i] = 0.0f;
requireScreenSpaceResolve = false;
}
private void SetShadowCollectPassKeywords(CommandBuffer cmd)

/ScriptableRenderPipeline/LightweightPipeline/LWRP/Passes/LightweightShadowPass.cs.meta → /ScriptableRenderPipeline/LightweightPipeline/LWRP/Passes/ShadowPass.cs.meta

/ScriptableRenderPipeline/LightweightPipeline/LWRP/Passes/LightweightShadowPass.cs → /ScriptableRenderPipeline/LightweightPipeline/LWRP/Passes/ShadowPass.cs

正在加载...
取消
保存