How to enable depth test for Canvas Draw?

How to enable depth test for Canvas Draw?

FCanvas* NativeCanvas = Canvas->Canvas;

APlayerController* PC = GetOwningPlayerController();
ULocalPlayer* const LP = PC->GetLocalPlayer();
if (LP && LP->ViewportClient)
{
	// get the projection data
	FSceneViewProjectionData ProjectionData;
	FIntPoint ViewportSize = LP->ViewportClient->Viewport->GetSizeXY();
	if (LP->GetProjectionData(LP->ViewportClient->Viewport, eSSP_FULL, /*out*/ ProjectionData))
	{
		FMatrix const InViewProjectionMatrix = ProjectionData.ComputeViewProjectionMatrix();
		FMatrix OldBaseTransform = NativeCanvas->GetBottomTransform();
		NativeCanvas->SetBaseTransform(InViewProjectionMatrix);

		NativeCanvas->PushAbsoluteTransform(FMatrix::Identity);

		FHitProxyId HitProxyId = NativeCanvas->GetHitProxyId();
		FBatchedElements* LineBatcher = NativeCanvas->GetBatchedElements(FCanvas::ET_Line);
		FBatchedElements* TriangleBatcher = NativeCanvas->GetBatchedElements(FCanvas::ET_Triangle);
		LineBatcher->AddLine(FVector(0, 0, 0), GetActorLocation(), FLinearColor::Green, HitProxyId, 10);

		LineBatcher->AddLine(FVector(0, 0, 0), FVector(100, 0, 0), FLinearColor::Red, HitProxyId, 10);

		TriangleBatcher->AddVertex(FVector(0, 0, 0), FVector2D(0, 0), FLinearColor::Blue, HitProxyId);
		TriangleBatcher->AddVertex(FVector(0, 0, 40), FVector2D(0, 1), FLinearColor::Blue, HitProxyId);
		TriangleBatcher->AddVertex(FVector(0, 100, 0), FVector2D(1, 0), FLinearColor::Blue, HitProxyId);

		TriangleBatcher->AddTriangle(0, 1, 2, GWhiteTexture, SE_BLEND_Opaque);

		TriangleBatcher->AddVertex(FVector(0, 0, 0) - FVector(-100, 0, 0), FVector2D(0, 0), FLinearColor::Red, HitProxyId);
		TriangleBatcher->AddVertex(FVector(0, 0, 40) - FVector(-100, 0, 0), FVector2D(0, 1), FLinearColor::Green, HitProxyId);
		TriangleBatcher->AddVertex(FVector(0, 100, 0) - FVector(-100, 0, 0), FVector2D(1, 0), FLinearColor::Blue, HitProxyId);

		TriangleBatcher->AddTriangle(3, 4, 5, GWhiteTexture, SE_BLEND_Opaque);

		NativeCanvas->PopTransform();
		NativeCanvas->SetBaseTransform(OldBaseTransform);
	}
}

All drawing is ignore depth test, cause some weired effects.

90881-20160517163304.png

I don’t know how to enable depth when drawing with Canvas.
I need this feature to draw gizmo on top of all scene objects.

Thank you.

I’m in blueprints so not sure if this helps… it’s a part of another use after checking Disable Depth Test on the Widget3DPassThrumaterial in Engine Materials… after that in widgets: go down to Render Custom Depth pass, enable. And then set Translucency Sort Priority… (your call) 1000 close - 0 distant maybe something in this can lead ya to an answer…

I used an ugly solution.

I found Canvas just do simple Draw Primitives prcoesses.

I simply write a new class similar to FCanvas. Just create a depth rendertarget.
SetRendertarget with the depth rendertarget created. Don’t forget to clear the depth before rendering start.

It is just that simple.
Then I sucessfully render the 3d gizmo.

The source codes are part of our company software product.
So I can not post here.
Sorry.