x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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. alt text

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.

Product Version: UE 4.11
Tags:
20160517163304.png (54.4 kB)
more ▼

asked May 17 '16 at 08:44 AM in Rendering

avatar image

Henry Read
98 12 13 24

avatar image Henry Read May 18 '16 at 02:22 AM

..........................................

avatar image WilliamHooper May 18 '16 at 04:59 AM

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...

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

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.

more ▼

answered May 21 '16 at 04:29 AM

avatar image

Henry Read
98 12 13 24

avatar image Henry Read May 21 '16 at 04:32 AM

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

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question