Depth texture using unreal shader

Hi, I have created a render texture which I can visualize using the view menu from UE editor. Currently, the texture is a single solid color. I want to populate the texture with pixel depths using unreal shader. I am aware that the depth buffer is already there, but this exercise is going to help me understand the entire shader pipeline in UE. Is there a way to get the depth values from the shader dumped onto a texture ? I have the following vertex shader.

struct FTriangleIDPassVSToPS
{
	float4 Position : SV_POSITION;
};

#define FTriangleIDPassVSOutput FTriangleIDPassVSToPS
void MainVS(FVertexFactoryInput Input,
	out FTriangleIDPassVSOutput Output
#if USE_GLOBAL_CLIP_PLANE
	, out float OutGlobalClipPlaneDistance : SV_ClipDistance
#endif
)
{
	ResolvedView = ResolveView();

	FVertexFactoryIntermediates VFIntermediates = GetVertexFactoryIntermediates(Input);
	float4 WorldPos = VertexFactoryGetWorldPosition(Input, VFIntermediates);

	float3x3 TangentToLocal = VertexFactoryGetTangentToLocal(Input, VFIntermediates);
	FMaterialVertexParameters VertexParameters = GetMaterialVertexParameters(Input, VFIntermediates, WorldPos.xyz, TangentToLocal);

	// Isolate instructions used for world position offset
	// As these cause the optimizer to generate different position calculating instructions in each pass, resulting in self-z-fighting.
	// This is only necessary for shaders used in passes that have depth testing enabled.
	ISOLATE
	{
		WorldPos.xyz += GetMaterialWorldPositionOffset(VertexParameters);
	}

	ISOLATE
	{
		float4 RasterizedWorldPosition = VertexFactoryGetRasterizedWorldPosition(Input, VFIntermediates, WorldPos);
	#if ODS_CAPTURE
		float3 ODS = OffsetODS(RasterizedWorldPosition.xyz, ResolvedView.TranslatedWorldCameraOrigin.xyz, ResolvedView.StereoIPD);
		Output.Position = INVARIANT(mul(float4(RasterizedWorldPosition.xyz + ODS, 1.0), ResolvedView.TranslatedWorldToClip));
	#else
		Output.Position = INVARIANT(mul(RasterizedWorldPosition, ResolvedView.TranslatedWorldToClip));
	#endif
	}
}

I understand the Output gives the clip space position of the vertex. In the pixel shader, should I do something like ?

void MainPS(FTriangleIDPassVSToPS Output, out uint OutColor : SV_Target0)
{
	OutColor = Output.Position.z / Output.Position.w;
}

This doesn’t give the expected result. Maybe I am missing something. Any kind of help is appreciated. Thanks.