Copy SceneDepth Information in FSceneViewExtension

I found the solution that you can create CopyShader by following

SCREEN_PASS_TEXTURE_VIEWPORT(ViewParams)
Texture2D CameraDepthTexture;
void MainPS(float4 SvPosition : SV_POSITION, out float depth : SV_Depth)
{
	const int2 pixelPos = int2(SvPosition.xy);
	depth = CameraDepthTexture.Load(int3(pixelPos, 0)).r;
}

then, you can do

FPixelShaderUtils::AddFullscreenPass(
		graphBuilder, globalShaderMap, FRDGEventName(TEXT("Copy Depth")), copyDepthShader, copyDepthParam, viewport);

	AddCopyTexturePass(graphBuilder, sceneDepth.Texture, SceneDepthCopyRenderTarget.Texture);
2 Likes