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"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

Drawing 2D Lines with 3D Occlusion

Hi there,

I'm trying to achieve the effect of visualizing a satellite orbit with a constant thickness no matter the viewing distance, so 3D lines with DrawDebugLine() aren't an option.

Here's the desired effect:

alt text

I’ve only come up with this:

  1. Extending the AHUD class and override the DrawHUD() function. Use AHUD:: Project() to convert 3D coordinates to 2D screen coordinates, then use AHUD:: DrawLine() to draw 2d lines on the HUD.

  2. Do line traces from camera to each point on the orbit to determine if it is blocked by some object, and use binary search to approximate the cut-off point:

alt text

However there are a few problems with this approach:

  1. Line trace is a synchronous operation which blocks the main game thread. I’ve tested 4,000 line traces within a single frame, and the fps drop is unacceptable (240 fps down to around 80 fps).

  2. If there is a blocking object in between two adjacent orbit points or the shape of the object is irregular, then this approach won’t work.

When the scene gets a bit more complex, there could be visual glitches every where, not to mention the performance. There is some optimization work can be done to minimize the problems, like skipping points based on viewing distance and dealing with every corner case, but I'm not sure if it's even worth the effort.

So I’m looking for a better approach to achieve the same effect. Any thoughts?

Product Version: Not Selected
Tags:
th.jpg (10.9 kB)
more ▼

asked Apr 03 '19 at 02:54 AM in C++ Programming

avatar image

icroiant
6 3 5

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

With the help of engine source FSplineComponentVisualizer::DrawVisualization and some forum posts, this is what I end up with:

alt text

Basically what I did was extending UPrimitiveComponent class and override these two functions:

 virtual FPrimitiveSceneProxy* CreateSceneProxy() override;
 virtual FBoxSphereBounds CalcBounds(const FTransform& LocalToWorld) const override;

Define your own component bounds to deal with frustum culling with CalcBounds.

Then create another class inheriting from FPrimitiveSceneProxy to get hold of a FPrimitiveDrawInterface pointer (refer to this forum post) and draw with

 PDI->DrawLine(LineStart, LineEnd, Color, SceneDepthPriorityGroup, Thickness);

If you want your line occluded by other objects, the SceneDepthPriorityGroup has to be SDPG_World.

With a thickness of 0.0f the line is constantly 1 pixel wide; however any value above 0.0f results in the line thickness becoming depth dependent. If you need a constant thickness and want to be able to control the thickness as well, check out FSceneView::WorldToScreen, which returns a FVector4, then use the W component of that vector to scale the line thickness.

annotation.png (440.8 kB)
more ▼

answered Apr 04 '19 at 09:58 AM

avatar image

icroiant
6 3 5

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

There is a DrawCircle function, built into the Primitive Drawing Utils that might be of use?

more ▼

answered Apr 03 '19 at 09:28 AM

avatar image

Jawdy
361 2 4 6

avatar image icroiant Apr 03 '19 at 09:54 AM

Thanks for the reminder. I'm currently looking into how spline visualizers are drawn, which utilizes the PrimitiveDrawInterface and it looks promising :D. I'll give it a try and post my findings. Cheers!

avatar image Jawdy Apr 03 '19 at 11:10 AM

Great stuff! And yeah, please do keep us posted with your findings... and once you have a solution, mark this as answered, so others can use it to find similar fixes :-D

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
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