目录
深度图
深度图,是记录离物体离摄像机最近的图。
如何写入深度图
深度图,在urp中,如果相机开启了需要深度图的话,会自动在写color之后,写一个深度图。此外urp还提供一个depth only pass的,他和免费提供的写深度互斥使用。

申请深度图
RenderingUtils.ReAllocateIfNeeded(ref m_CameraDepthAttachment, depthDescriptor, FilterMode.Point, TextureWrapMode.Clamp, name: "_CameraDepthAttachment");
cmd.SetGlobalTexture(m_CameraDepthAttachment.name, m_CameraDepthAttachment.nameID);
长什么样子

copy depth pass
为啥urp有个copydepth,还有个depthonly。
depthonly存在的原因,我的猜测是为了先得到深度图,earlyz的剔除功能,但是会增加drawcall。
copydepth存在的原因,我不知道:原始的_CameraDepthAttachment能用读取呀,为啥不直接用呢???
C#代码中申请_CameraDepthTexture的地方,然后将_CameraDepthAttachment拷贝到_CameraDepthTexture。
// Allocate m_DepthTexture if used
if ((this.renderingModeActual == RenderingMode.Deferred && !this.useRenderPassEnabled) || requiresDepthPrepass || requiresDepthCopyPass)
{
var depthDescriptor = cameraTargetDescriptor;
if (requiresDepthPrepass && this.renderingModeActual != RenderingMode.Deferred)
{
depthDescriptor.graphicsFormat = GraphicsFormat.None;
depthDescriptor.depthStencilFormat = k_DepthStencilFormat;
depthDescriptor.depthBufferBits = k_DepthBufferBits;
}
else
{
depthDescriptor.graphicsFormat = GraphicsFormat.R32_SFloat;
depthDescriptor.depthStencilFormat = GraphicsFormat.None;
depthDescriptor.depthBufferBits = 0;
}
depthDescriptor.msaaSamples = 1;// Depth-Only pass don't use MSAA
RenderingUtils.ReAllocateIfNeeded(ref m_DepthTexture, depthDescriptor, FilterMode.Point, wrapMode: TextureWrapMode.Clamp, name: "_CameraDepthTexture");
cmd.SetGlobalTexture(m_DepthTexture.name, m_DepthText

最低0.47元/天 解锁文章
846

被折叠的 条评论
为什么被折叠?



