I’m looking into remaking an old game I made a few years back in Shockwave 3D. In shockwave in Director it was and simple a choosing a render mode to set mdoels to appear in wireframe a la ‘BattleZone’, how can this be done in Unity? I assume it’d be a shader thing? Not really sure. Any tips or thoughts on this much appreciated.
If this is a working wireframe shader (haven’t tested it yet) could you please post this in the Wiki? I know other folks have asked for this in the past and it would make a great addition!
The only problem I see with Yoggy’s script is that it’s very slow (I think) - assuming that it actually is using immediate mode. Then again, UT might do some magic underneath to use VBOs or something of the sort.
Another possibility would to have UT expose glPolygonMode() and DirectX equivalent. That would probably be pretty easy for them to implement.
Yoggy’s code is pseudo code AFAIK. Here’s my attempt at GL wireframe rendering so far (attach to Main Camera). I’d love to see someone really nail this though…
var P0 : Vector3;
var P1 : Vector3;
var P2 : Vector3;
var wires = new Array();
var lineColor : Color;
var myMesh : GameObject;
static var lineMaterial : Material;
function Start ()
{
CreateLineMaterial();
var filter : MeshFilter = myMesh.GetComponent(MeshFilter);
var mesh = filter.mesh;
var vertices = mesh.vertices;
var triangles = mesh.triangles;
for (k = 0; k < triangles.length / 3; k++)
{
wires.Add (vertices[triangles[k * 3]]);
wires.Add (vertices[triangles[k * 3 + 1]]);
wires.Add (vertices[triangles[k * 3 + 2]]);
}
wires.Add (vertices[triangles[triangles.length - 2]]);
wires.Add (vertices[triangles[triangles.length - 1]]);
}
function OnPostRender()
{
lineMaterial.SetPass(0);
GL.Begin(GL.LINES);
GL.Color(lineColor);
for (i = 0; i < wires.length / 3; i++)
{
P0 = myMesh.transform.TransformPoint (wires[i * 3]);
P1 = myMesh.transform.TransformPoint (wires[i * 3 + 1]);
P2 = myMesh.transform.TransformPoint (wires[i * 3 + 2]);
GL.Vertex3(P0.x, P0.y, P0.z);
GL.Vertex3(P1.x, P1.y, P1.z);
GL.Vertex3(P2.x, P2.y, P2.z);
GL.Vertex3(P0.x, P0.y, P0.z);
}
GL.End();
}
static function CreateLineMaterial()
{
if( !lineMaterial ) {
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;
}
}
Yeah, mine works, but it’s pretty far from useable in any practical application (the framerate is fine, but the method is extremely convoluted). I wish you were more intrigued by this because if you were you’d probably bang out a killer GL wireframe renderer in an afternoon.
As an incentive picture telephone/power cables dangling here and there for a certain game
thanks so much for the responses Forest, Ethan, this is exactly the kind of thing i’ve been thinking of. I’ll post some of my game up as soon as i find time to make it!
He needs to BindChannels in the shader, I think. Unity is usually good about getting bindings figured out for us, but in cases like this, it sometimes needs help mapping sources to targets.
You will want to add something like this to the subshader pass (escaping as necessary)
BindChannels { Bind "Color",color }
Note though that I didn’t actually run this with or without that fix, and I’m completely speculating that this is causing the black lines in Windows problem.