Download

Drawing 2D Lines with 3D Occlusion

Hi forum,

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:

http://help.agi.com/stk/Content/training/images/3DView_3CovOrbits.bmp

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:

https://forums.unrealengine.com/core/image/gif;base64

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?