I have been working on rendering roads across a huge landscape (real world like). This was initially during the development of my f18 game and its worldbuilder tools. While doing this, I found myself needing a fast way to draw lines. I first made quite a slow way, using sprites and go’s.
I can happily say that Ive found quite a reasonable way to now draw the lines:
The best part about this, is this is around 10x more lines than I need. The above example is drawing 150,000 lines (3x 50,000 per mesh).
The example can be found here. Its all MIT. There is the main branch (which is the old “slow” way) and the new line-shader branch which shows the above.
The code can probably improved quite a bit. Feel free to use it as you’d like
Another quick update for those that might be trying to use this.
Fixed:
multi mesh (oops was sharing mesh!). now makes a resource for each mesh thats drawing lines.
fixed bugs with the direction vector on the lines. Soz.
some cleanup with the line creation. Should be clearer how this works now - using a position and rotation it makes a rotated set of quad points with the position as the center start of one end of the line.
To give an idea of perf. I just did a test with 1.5 million lines spread across 3 meshes (500K each), and it is still only consuming 0.2ms (ish - hard to measure at this speed).
Remember this is effectively static lines. But, you can update them. The main cost will be the time to modify the stream buffer, and then the time to resubmit. If you used smaller buffers across many mesh objects, and only modified a small buffer, this could be done in realtime.
The good news is its looking good in the worldbuilder now too:
This is fantastic! I was looking for a more solid way to draw shapes for my walk mesh in the in-game editor than the debug lines.
Will give it a try in the weekend.
Its 3D too, but the example essentially uses the XY plane to render to. If you need any help with it (it was a fairly rushed example so I could then trial it) let me know.
I might update the repo too, so the main branch is the latest, and I put the old sprite method into its own branch.