Wireframes without diagonals in Unity

I needed some simple wireframes rendered in my project. If you search around, you’ll find a few free and paid implementations, most of them shader-based. A critical feature for me was being able to render quads where possible, to achieve that retro grid-like effect.

Modern engines tend to use triangles rather than quads internally, making it challenging to achieve this effect using shaders. Ultimately, I went with a simple approach and wrote a script that traverses the vertices in the mesh and draws lines after the initial object rendering is done.

Cubes with the script applied, with different settings.

Here’s a few examples of what the script can do:

  • You can leave the diagonals in, effectively outlining every triangle in your mesh.
  • Use either GL.LINES for clean, single-pixel lines, or GL.QUADS to extrude the lines sideways into a custom width. The orientation of the quads is determined using the normals of the vertices.
  • Continue to render the mesh alongside the mesh renderer. A meterial is provided in the repository that will reduce z-fighting artifacts.
The Inspector.

The implementation isn’t perfect – feel free to suggest improvements here or directly on GitHub.

Leave a comment