I am trying to create a graphic of camera frustum projected on a minimap of an RTS game. I want it to be dynamic, so that it reacts to zoom and rotation of the camera, so the idea of pre-rendered projected frame mapped into UMG widget component fails.
I am doing 4 line traces for each corner of the camera view, and then gathering the world locations, and remapping XY coordinates of those 4 world locations from the world map size into 2D vectors in 0-1 range.
The question is how to use them, and how to do it efficiently.
There is a DrawLines function in UMG, which requires to be called from overriden OnPaint. It’s great because it takes exactly array of 2D vectors to connect into a continous closed shape. The problem is I absolutely can not figure out how to erase the buffer. I think it’s meant to do literally painting and painting only, not actual per frame drawing. What this means that I always get accumulation of the every frame, rather than fresh image every frame:
Since I can’t figure out how to clear the UMG Paint result every time, this approach has failed.
Then I tried using BeginDrawCanvasToRenderTarget, which creates canvas on which the primitive shapes can be drawn on too. The problem here is that by default, it accumulates too. Luckily, this can be mitigated by calling ClearRenderTarget2D. The problem I’ve ran into here is that one has to Being and End drawing each frame. If I do BeginDraw -> Draw Line -> End Draw, everything works, but I need to draw multiple lines, and unlike UMG, Draw to Canvas function set has only DrawLine function, not DrawLines. So I have to do 4 line draws. As soon as I execute a loop of 4 line draws, and call EndDrawCanvasToRenderTarget, for some reason the RenderTarget clearing stops working, and I run into the exact same issue as with #1.
I also tried to do some craziness with the material, where I tried to distor the UV space using the 4 corner 2D vector (Something like 4 pin warp in Photoshop):
So all 3 approaches have failed.
So I was wondering if someone knows about something else I can try. Ideally it should be as simple and performance friendly as possible.
Thank you in advance.