I am procedurally generating 3d solid meshes and would like to toggle a wireframe representation of the solids.
To be clear, I don’t want to see every triangle in the mesh, just the outlines…
Since I already know each face and vertex of the solids, I could pre-calculate the mesh data for the wireframe and just enable/disable it as a child gameObject.
Or, I could try to write an edge detection shader and have edges rendered in real-time (not looking to do that right now since I have very little experience with shaders).
Performance-wise, does anyone know what the difference would be?
It seems to me you are mixing terms, so just to be sure: In my book,
- A wireframe representation shows the vertices (the lines connecting the various points, the edges of each polygon. Advanced Versions can analyse the polygon, and remove/not draw some Vertices (e.g. the diagonal of a quad).
- Edge detection effects usually process an Image and look for a signal (crossing from hi to low or vice versa, perhaps with a pre-defined threshold). This can be done as a screen-space (image) shader; due to the fact that it needs to access the surrounding 8 Pixels (using Screen-space scale) it can be rather annoying to implement as a Unity shader.
- Outline shaders mark the threshold where the rendered shadpe starts occluding the background or is occluded by the foreground. Obviously, the outline changes with the angle you are looking at the object
From your description you are looking for the last, an outline shader, correct? Since shaders are pretty much the only way to draw efficiently in Unity, I’d go with an outline shader. There are many good outline shaders available at the asset store, and there is at least one included as a sample in Amplify Shader. I’m sure there are also some available on the net.
Advanced Wireframe is what I’m looking for. I want to connect the dots of each vertex on the edges.
I just want to confirm that the from a performance perspective, a run-time shader is the way to go compared to a mesh that generates a mesh of outlines that is toggled on/off (basically a bunch of LineRenderers drawn around the edges)
I’ve been there (love the stuff on the site). But the capsule mesh has too many lines (I don’t want any diagonals). I’ve attached some examples from CAD Programs (Tekla and AutoCAD). The idea of this wireframe is to see through something to work on something else, so there are a minimum amount of lines being shown. The yellow cylinder (Tekla) appears to be doing edge detection, since the vertical lines always appear on the edges. The white cylinder (AutoCAD) has fixed vertical lines drawn at each quadrant. This makes me think that wire-frame mesh is pre-calculated.