Hi guys and gals, I’ve looked around but can’t seem to find any info on whether it’s possible to have the main camera render in wireframe mode? I did find some stuff on Unity Pro but that doesn’t help me
I’d quite like to do some cool retro stuff, a la Battlezone.
Hey guys, I prefer c# so I rewrote and uhm changed the script a bit
it renders every line two times so now you can choose, which line of the triangles to render, which gives some kind of random but faster mesh, quite interesting too.
using UnityEngine;
using System.Collections;
public class wireframe : MonoBehaviour {
public bool render_mesh_normaly = true;
public bool render_lines_1st = false;
public bool render_lines_2nd = false;
public bool render_lines_3rd = false;
public Color lineColor = new Color (0.0f, 1.0f, 1.0f);
public Color backgroundColor = new Color (0.0f, 0.5f, 0.5f);
public bool ZWrite = true;
public bool AWrite = true;
public bool blend = true;
public float lineWidth = 3;
public int size = 0;
private Vector3[] lines ;
private ArrayList lines_List ;
public Material lineMaterial ;
//private MeshRenderer meshRenderer;
/*
████████ ▄▀▀■ ▀▀█▀▀ ▄▀▀▄ █▀▀▄ ▀▀█▀▀
████████ ▀■■▄ █ █■■█ █▀▀▄ █
████████ ■▄▄▀ █ █ █ █ █ █
*/
void Start () {
//meshRenderer = gameObject.GetComponent<MeshRenderer>();
if (lineMaterial == null) {
lineMaterial = new Material ("Shader \"Lines/Colored Blended\" {" +
"SubShader { Pass {" +
" BindChannels { Bind \"Color\",color }" +
" Blend SrcAlpha OneMinusSrcAlpha" +
" ZWrite on Cull Off Fog { Mode Off }" +
"} } }");
/*lineMaterial = new Material ("Shader \"Lines/Colored Blended\" {" +
"SubShader { Pass {" +
" Blend SrcAlpha OneMinusSrcAlpha" +
" ZWrite Off Cull Front Fog { Mode Off }" +
"} } }");*/
}
lineMaterial.hideFlags = HideFlags.HideAndDontSave;
lineMaterial.shader.hideFlags = HideFlags.HideAndDontSave;
lines_List = new ArrayList();
MeshFilter filter = gameObject.GetComponent<MeshFilter>();
Mesh mesh = filter.mesh;
Vector3[] vertices = mesh.vertices;
int[] triangles = mesh.triangles;
for (int i = 0; i+2 < triangles.Length; i+=3)
{
lines_List.Add(vertices[triangles*]);*
lines_List.Add(vertices[triangles[i + 1]]);*
lines_List.Add(vertices[triangles[i+ 2]]);*
}*
//lines_List.CopyTo(lines);//arrays are faster than array lists*
If you don’t mind having a fixed black colour for the triangles, you can use the inbuilt VR/SpatialMapping/Wireframe shader, available from 2017 onwards.
On standard displays, this will draw a wireframe on top of black triangles. On AR displays like HoloLens, the triangles will be transparent, leaving the wireframe.
The advantage of this approach is that there are no external dependencies and it works in seconds with any MeshFilter. I often use it for debugging procedural mesh generation scripts.