Whats the best way to draw a wireframe?

Avatar
  • updated
  • Answered

Hello,

I am currently working on a strategy game and I want to draw a wireframe of the points the player can use to place objects. What I am doing right now is getting a list of points in world coordinates at runtime and drawing lines. I currently have 8489 lines after applying an operation to the points to convert them to lines. I've tried drawing this in immediate mode and also instantiating Shapes.Line game objects, but the performance hit is pretty big. I can see a pretty dramatic drop in framerate. What would be the best way to approach this with the Shapes package?


Some approaches I tried:

* Creating a Polygon that has all the points (this one threw an error "Invalid polygon triangulation - no convex edges found. Your polygon is likely self-intersecting").

* Creating a Rectangle and changing it to wireframe mode (was not able to achieve this).

* Occluding lines outside the camera (this one is a bit more complicated because I'd have to do a lot of adjustments to the game design so it can work with this)

I think the 2 easiest approaches would be to either draw a rectangle and switch it to (wireframe mode) or be able to draw a single shape that contains all the points like a polygon.

Ideally what I would like is to be able to draw a grid of any size and be able to toggle it on/off without noticing a performance hit. Any ideas are appreciated!

Thanks

Reporting a bug? please specify Unity version:
Reporting a bug? please specify Shapes version:
Reporting a bug? please specify Render Pipeline:
Pinned replies
Avatar
Freya Holmér creator
  • Answer
  • Answered

generally a grid would be better made using a single mesh that can render the whole thing with one draw call

it also depends on what your requirements are, if each line can be flat, or if it has to be 3D etc

but generally a grid with 8000+ lines is going to be too heavy/wasteful in Shapes most likely, a large quad mesh with a custom grid shader would render it much faster and would get you a similar effect

Avatar
Freya Holmér creator
  • Answer
  • Answered

generally a grid would be better made using a single mesh that can render the whole thing with one draw call

it also depends on what your requirements are, if each line can be flat, or if it has to be 3D etc

but generally a grid with 8000+ lines is going to be too heavy/wasteful in Shapes most likely, a large quad mesh with a custom grid shader would render it much faster and would get you a similar effect

Avatar
Javier Falcon
Quote from Freya Holmér

generally a grid would be better made using a single mesh that can render the whole thing with one draw call

it also depends on what your requirements are, if each line can be flat, or if it has to be 3D etc

but generally a grid with 8000+ lines is going to be too heavy/wasteful in Shapes most likely, a large quad mesh with a custom grid shader would render it much faster and would get you a similar effect

Can I add a feature request for Shapes to do what you just said?

Thanks for the quick answer!

Avatar
Freya Holmér creator

I've considered adding support for pattern overlays for the polygon shape, which would allow you to sort of do this as long as a grid pattern is included! feel free to open up a separate feature request on that :)