浏览代码

All renderpasses referencing attachments by handle

/main
Felipe Lira 7 年前
当前提交
98c82c99
共有 8 个文件被更改,包括 65 次插入115 次删除
  1. 24
      ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightForwardRenderer.cs
  2. 9
      ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipelineCore.cs
  3. 17
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Passes/DepthOnlyPass.cs
  4. 6
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Passes/DirectionalShadowsPass.cs
  5. 60
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Passes/ForwardLitPass.cs
  6. 7
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Passes/LocalShadowsPass.cs
  7. 18
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Passes/ScreenSpaceShadowOcclusionPass.cs
  8. 39
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Passes/ScriptableRenderPass.cs

24
ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightForwardRenderer.cs


bool supportsDepthCopy = copyShaderSupported || supportsTextureCopy;
bool requiresDepthPrepassToResolveMsaa = msaaEnabledForCamera && !supportsTexture2DMS;
bool renderDirectionalShadows = shadowsEnabledForCamera && lightData.shadowData.supportsDirectionalShadows;
bool requiresScreenSpaceOcclusion = renderDirectionalShadows && lightData.shadowData.requiresScreenSpaceOcclusion;
bool requiresDepthPrepass = requiresCameraDepth && (!supportsDepthCopy || requiresScreenSpaceOcclusion || requiresDepthPrepassToResolveMsaa);
bool requiresScreenSpaceShadows = renderDirectionalShadows && lightData.shadowData.requiresScreenSpaceOcclusion;
bool requiresDepthPrepass = requiresScreenSpaceShadows || (requiresCameraDepth && (!supportsDepthCopy || requiresDepthPrepassToResolveMsaa));
bool needsMsaaResolve = (msaaEnabledForCamera && !LightweightPipeline.PlatformSupportsMSAABackBuffer());
bool depthRenderBuffer = requiresCameraDepth && !requiresDepthPrepass;
bool intermediateRenderTexture = cameraData.isSceneViewCamera ||
!Mathf.Approximately(cameraData.renderScale, 1.0f) ||

needsMsaaResolve ||
depthOnlyPass.Setup(cmd, baseDescriptor, 1);
depthOnlyPass.Setup(cmd, baseDescriptor, null, RenderTargetHandles.Depth);
directionalShadowPass.Setup(cmd, baseDescriptor, 1);
directionalShadowPass.Setup(cmd, baseDescriptor);
if (requiresScreenSpaceOcclusion)
if (requiresScreenSpaceShadows)
screenSpaceShadowOcclusionPass.Setup(cmd, baseDescriptor, 1);
screenSpaceShadowOcclusionPass.Setup(cmd, baseDescriptor, new[] {RenderTargetHandles.ScreenSpaceOcclusion});
m_RenderPassList.Add(screenSpaceShadowOcclusionPass);
}
}

localShadowsPass.Setup(cmd, baseDescriptor, 1);
localShadowsPass.Setup(cmd, baseDescriptor);
int colorHandle = (intermediateRenderTexture) ? RenderTargetHandles.Color : -1;
int[] colorHandles = (intermediateRenderTexture) ? new[] {RenderTargetHandles.Color} : null;
forwardLitPass.colorHandles = new[] { colorHandle };
forwardLitPass.depthHandle = depthHandle;
forwardLitPass.Setup(cmd, baseDescriptor, cameraData.msaaSamples);
forwardLitPass.Setup(cmd, baseDescriptor, colorHandles, depthHandle, cameraData.msaaSamples);
m_RenderPassList.Add(forwardLitPass);
context.ExecuteCommandBuffer(cmd);

9
ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipelineCore.cs


{
return lightType == LightType.Directional || lightType == LightType.Spot;
}
public static bool PlatformSupportsMSAABackBuffer()
{
#if UNITY_ANDROID || UNITY_IPHONE || UNITY_TVOS || UNITY_SAMSUNGTV
return true;
#else
return false;
#endif
}
}
}

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


RegisterShaderPassName("DepthOnly");
}
public override void Setup(CommandBuffer cmd, RenderTextureDescriptor baseDescriptor, int samples)
public override void Setup(CommandBuffer cmd, RenderTextureDescriptor baseDescriptor, int[] colorAttachmentHandles, int depthAttachmentHandle = -1, int samples = 1)
base.Setup(cmd, baseDescriptor, colorAttachmentHandles, depthAttachmentHandle, samples);
baseDescriptor.colorFormat = RenderTextureFormat.Depth;
baseDescriptor.depthBufferBits = kDepthBufferBits;

baseDescriptor.msaaSamples = samples;
}
cmd.GetTemporaryRT(RenderTargetHandles.Depth, baseDescriptor, FilterMode.Point);
m_Disposed = false;
cmd.GetTemporaryRT(depthAttachmentHandle, baseDescriptor, FilterMode.Point);
}
public override void Execute(ref ScriptableRenderContext context, ref CullResults cullResults, ref CameraData cameraData, ref LightData lightData)

{
int depthSlice = LightweightPipeline.GetRenderTargetDepthSlice(cameraData.isStereoEnabled);
CoreUtils.SetRenderTarget(cmd, GetSurface(RenderTargetHandles.Depth), ClearFlag.Depth, 0, CubemapFace.Unknown, depthSlice);
CoreUtils.SetRenderTarget(cmd, GetSurface(depthAttachmentHandle), ClearFlag.Depth, 0, CubemapFace.Unknown, depthSlice);
context.ExecuteCommandBuffer(cmd);
cmd.Clear();

//cmd.SetGlobalTexture(depthTextureID, depthTexture);
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}
public override void Dispose(CommandBuffer cmd)
{
if (!m_Disposed)
{
cmd.ReleaseTemporaryRT(RenderTargetHandles.Depth);
m_Disposed = true;
}
}
}
}

6
ScriptableRenderPipeline/LightweightPipeline/LWRP/Passes/DirectionalShadowsPass.cs


Clear();
}
public override void Setup(CommandBuffer cmd, RenderTextureDescriptor baseDescriptor, int samples)
{
}
public override void Execute(ref ScriptableRenderContext context, ref CullResults cullResults, ref CameraData cameraData, ref LightData lightData)
{
Clear();

RenderTexture.ReleaseTemporary(m_DirectionalShadowmapTexture);
m_DirectionalShadowmapTexture = null;
}
m_Disposed = true;
}
void Clear()

m_DirectionalShadowmapTexture.filterMode = FilterMode.Bilinear;
m_DirectionalShadowmapTexture.wrapMode = TextureWrapMode.Clamp;
CoreUtils.SetRenderTarget(cmd, m_DirectionalShadowmapTexture, ClearFlag.Depth);
m_Disposed = false;
bool success = false;
for (int cascadeIndex = 0; cascadeIndex < m_ShadowCasterCascadesCount; ++cascadeIndex)

60
ScriptableRenderPipeline/LightweightPipeline/LWRP/Passes/ForwardLitPass.cs


m_SampleOffsetShaderHandle = Shader.PropertyToID("_SampleOffset");
}
public override void Setup(CommandBuffer cmd, RenderTextureDescriptor baseDescriptor, int samples)
public override void Setup(CommandBuffer cmd, RenderTextureDescriptor baseDescriptor, int[] colorAttachmentHandles, int depthAttachmentHandle = -1, int samples = 1)
if (colorHandles[0] != -1)
base.Setup(cmd, baseDescriptor, colorAttachmentHandles, depthAttachmentHandle, samples);
if (colorAttachmentHandle != -1)
{
var descriptor = baseDescriptor;
descriptor.colorFormat = m_ColorFormat;

descriptor.enableRandomWrite = false;
cmd.GetTemporaryRT(colorHandles[0], descriptor, FilterMode.Bilinear);
cmd.GetTemporaryRT(colorAttachmentHandle, descriptor, FilterMode.Bilinear);
if (depthHandle != -1)
if (depthAttachmentHandle != -1)
{
var descriptor = baseDescriptor;
descriptor.colorFormat = RenderTextureFormat.Depth;

cmd.GetTemporaryRT(depthHandle, descriptor, FilterMode.Point);
cmd.GetTemporaryRT(depthAttachmentHandle, descriptor, FilterMode.Point);
m_Disposed = false;
}
public override void Execute(ref ScriptableRenderContext context, ref CullResults cullResults, ref CameraData cameraData, ref LightData lightData)

cameraData.postProcessLayer.HasOpaqueOnlyEffects(renderer.postProcessRenderContext))
OpaquePostProcessSubPass(ref context, ref cameraData);
if (depthHandle != -1 && cameraData.requiresDepthTexture)
if (depthAttachmentHandle != -1 && cameraData.requiresDepthTexture)
CopyDepthSubPass(ref context, ref cameraData);
if (cameraData.requiresOpaqueTexture)

PostProcessPass(ref context, ref cameraData);
// No blit to backbuffer if camera is offscreen render.
if (!cameraData.isOffscreenRender && !cameraData.postProcessEnabled && colorHandles[0] != -1)
if (!cameraData.isOffscreenRender && !cameraData.postProcessEnabled && colorAttachmentHandle != -1)
FinalBlitPass(ref context, ref cameraData);
if (cameraData.isStereoEnabled)

}
}
public override void Dispose(CommandBuffer cmd)
{
if (!m_Disposed)
{
for (int i = 0; i < colorHandles.Length; ++i)
{
if (colorHandles[i] != -1)
cmd.ReleaseTemporaryRT(colorHandles[i]);
}
if (depthHandle != -1)
cmd.ReleaseTemporaryRT(depthHandle);
m_Disposed = true;
}
}
RendererConfiguration GetRendererConfiguration(int localLightsCount)
{
RendererConfiguration configuration = RendererConfiguration.PerObjectReflectionProbes | RendererConfiguration.PerObjectLightmaps | RendererConfiguration.PerObjectLightProbe;

void SetRenderTarget(CommandBuffer cmd, ClearFlag clearFlag)
{
if (colorHandles[0] != -1)
if (colorAttachmentHandle != -1)
if (depthHandle != -1)
CoreUtils.SetRenderTarget(cmd, GetSurface(colorHandles[0]), GetSurface(depthHandle), clearFlag);
if (depthAttachmentHandle != -1)
CoreUtils.SetRenderTarget(cmd, GetSurface(colorAttachmentHandle), GetSurface(depthAttachmentHandle), clearFlag);
CoreUtils.SetRenderTarget(cmd, GetSurface(colorHandles[0]), clearFlag);
CoreUtils.SetRenderTarget(cmd, GetSurface(colorAttachmentHandle), clearFlag);
}
else
{

// If rendering to an intermediate RT we resolve viewport on blit due to offset not being supported
// while rendering to a RT.
if (colorHandles[0] == -1 && cameraData.isDefaultViewport)
if (colorAttachmentHandle == -1 && cameraData.isDefaultViewport)
cmd.SetViewport(camera.pixelRect);
var drawSettings = CreateDrawRendererSettings(camera, SortFlags.CommonOpaque, rendererConfiguration);

{
var cmd = CommandBufferPool.Get("Final Blit Pass");
if (cameraData.isStereoEnabled && XRSettings.eyeTextureDesc.dimension == TextureDimension.Tex2DArray)
cmd.Blit(GetSurface(colorHandles[0]), BuiltinRenderTextureType.CameraTarget);
cmd.Blit(GetSurface(colorAttachmentHandle), BuiltinRenderTextureType.CameraTarget);
LightweightPipeline.Blit(cmd, ref cameraData, GetSurface(colorHandles[0]), BuiltinRenderTextureType.CameraTarget, cameraData.isStereoEnabled ? null : m_BlitMaterial);
LightweightPipeline.Blit(cmd, ref cameraData, GetSurface(colorAttachmentHandle), BuiltinRenderTextureType.CameraTarget, cameraData.isStereoEnabled ? null : m_BlitMaterial);
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);

void PostProcessPass(ref ScriptableRenderContext context, ref CameraData cameraData)
{
CommandBuffer cmd = CommandBufferPool.Get("Render PostProcess Effects");
LightweightPipeline.RenderPostProcess(cmd, renderer.postProcessRenderContext, ref cameraData, m_ColorFormat, GetSurface(colorHandles[0]), BuiltinRenderTextureType.CameraTarget, false);
LightweightPipeline.RenderPostProcess(cmd, renderer.postProcessRenderContext, ref cameraData, m_ColorFormat, GetSurface(colorAttachmentHandle), BuiltinRenderTextureType.CameraTarget, false);
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}

{
// TODO:
// cmd.GetTemporaryRT();
source = GetSurface(colorHandles[0]);
source = GetSurface(colorAttachmentHandle);
source = GetSurface(colorHandles[0]);
source = GetSurface(colorAttachmentHandle);
LightweightPipeline.RenderPostProcess(cmd, renderer.postProcessRenderContext, ref cameraData, m_ColorFormat, source, GetSurface(colorHandles[0]), true);
LightweightPipeline.RenderPostProcess(cmd, renderer.postProcessRenderContext, ref cameraData, m_ColorFormat, source, GetSurface(colorAttachmentHandle), true);
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}

CommandBuffer cmd = CommandBufferPool.Get("Depth Copy");
RenderTargetIdentifier depthSurface = GetSurface(RenderTargetHandles.Depth);
RenderTargetIdentifier depthSurface = GetSurface(depthAttachmentHandle);
RenderTargetIdentifier copyDepthSurface = GetSurface(RenderTargetHandles.DepthCopy);
RenderTextureDescriptor descriptor = renderer.CreateRTDesc(ref cameraData);

cmd.DisableShaderKeyword(k_MsaaDepthKeyword);
LightweightPipeline.CopyTexture(cmd, depthSurface, copyDepthSurface, m_DepthCopyMaterial);
}
cmd.SetGlobalTexture(RenderTargetHandles.Depth, copyDepthSurface);
//cmd.SetGlobalTexture(RenderTargetHandles.Depth, copyDepthSurface);
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}

float opaqueScaler = m_OpaqueScalerValues[(int)downsampling];
RenderTextureDescriptor opaqueDesc = renderer.CreateRTDesc(ref cameraData, opaqueScaler);
RenderTargetIdentifier colorRT = GetSurface(colorHandles[0]);
RenderTargetIdentifier colorRT = GetSurface(colorAttachmentHandle);
RenderTargetIdentifier opaqueColorRT = GetSurface(RenderTargetHandles.OpaqueColor);
cmd.GetTemporaryRT(RenderTargetHandles.OpaqueColor, opaqueDesc, cameraData.opaqueTextureDownsampling == Downsampling.None ? FilterMode.Point : FilterMode.Bilinear);

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


Clear();
}
public override void Setup(CommandBuffer cmd, RenderTextureDescriptor baseDescriptor, int samples)
{
}
public override void Execute(ref ScriptableRenderContext context, ref CullResults cullResults, ref CameraData cameraData, ref LightData lightData)
{
Clear();

RenderTexture.ReleaseTemporary(m_LocalShadowmapTexture);
m_LocalShadowmapTexture = null;
}
m_Disposed = true;
}
void Clear()

m_LocalShadowmapTexture = RenderTexture.GetTemporary(m_LocalShadowmapDescriptor);
m_LocalShadowmapTexture.filterMode = FilterMode.Bilinear;
m_LocalShadowmapTexture.wrapMode = TextureWrapMode.Clamp;
m_Disposed = false;
CoreUtils.SetRenderTarget(cmd, m_LocalShadowmapTexture, ClearFlag.Depth);

18
ScriptableRenderPipeline/LightweightPipeline/LWRP/Passes/ScreenSpaceShadowOcclusionPass.cs


m_ScreenSpaceShadowsMaterial = renderer.GetMaterial(MaterialHandles.ScrenSpaceShadow);
softShadows = false;
m_Disposed = true;
public override void Setup(CommandBuffer cmd, RenderTextureDescriptor baseDescriptor, int samples)
public override void Setup(CommandBuffer cmd, RenderTextureDescriptor baseDescriptor, int[] colorAttachmentHandles, int depthAttachmentHandle = -1, int samples = 1)
base.Setup(cmd, baseDescriptor, colorAttachmentHandles, depthAttachmentHandle, samples);
cmd.GetTemporaryRT(RenderTargetHandles.ScreenSpaceOcclusion, baseDescriptor, FilterMode.Bilinear);
m_Disposed = false;
cmd.GetTemporaryRT(colorAttachmentHandle, baseDescriptor, FilterMode.Bilinear);
}
public override void Execute(ref ScriptableRenderContext context, ref CullResults cullResults, ref CameraData cameraData, ref LightData lightData)

// stereo functionality, we use the screen-space shadow map as the source (until we have
// a better solution).
// An alternative would be DrawProcedural, but that would require further changes in the shader.
RenderTargetIdentifier screenSpaceOcclusionTexture = GetSurface(RenderTargetHandles.ScreenSpaceOcclusion);
RenderTargetIdentifier screenSpaceOcclusionTexture = GetSurface(colorAttachmentHandle);
cmd.SetRenderTarget(screenSpaceOcclusionTexture);
cmd.ClearRenderTarget(true, true, Color.white);
cmd.Blit(screenSpaceOcclusionTexture, screenSpaceOcclusionTexture, m_ScreenSpaceShadowsMaterial);

else
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}
public override void Dispose(CommandBuffer cmd)
{
if (!m_Disposed)
{
cmd.ReleaseTemporaryRT(RenderTargetHandles.ScreenSpaceOcclusion);
m_Disposed = true;
}
}
void SetShadowCollectPassKeywords(CommandBuffer cmd, int cascadeCount)

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


namespace UnityEngine.Experimental.Rendering.LightweightPipeline
{
public struct PassData
{
public LightData lightData;
public CameraData cameraData;
}
public int[] colorHandles { get; set; }
public int depthHandle;
public int[] colorAttachmentHandles { get; private set; }
protected bool m_Disposed;
public int colorAttachmentHandle { get; private set; }
public int depthAttachmentHandle { get; private set; }
m_Disposed = true;
}
public virtual void Setup(CommandBuffer cmd, RenderTextureDescriptor baseDescriptor, int[] colorAttachmentHandles = null, int depthAttachmentHandle = -1, int samples = 1)
{
this.colorAttachmentHandles = colorAttachmentHandles;
this.depthAttachmentHandle = depthAttachmentHandle;
colorAttachmentHandle = (colorAttachmentHandles != null && colorAttachmentHandles.Length > 0)
? colorAttachmentHandles[0]
: -1;
public abstract void Setup(CommandBuffer cmd, RenderTextureDescriptor baseDescriptor, int samples);
public virtual void Dispose(CommandBuffer cmd)
{
if (colorAttachmentHandles != null)
{
for (int i = 0; i < colorAttachmentHandles.Length; ++i)
if (colorAttachmentHandles[i] != -1)
cmd.ReleaseTemporaryRT(colorAttachmentHandles[i]);
}
if (depthAttachmentHandle != -1)
cmd.ReleaseTemporaryRT(depthAttachmentHandle);
}
public abstract void Dispose(CommandBuffer cmd);
public RenderTargetIdentifier GetSurface(int handle)
{

正在加载...
取消
保存