Achieving the Darwinia look in Unity?

Hi there,

I’m trying to start writing a little game that I’d like to look like Darwinia. Here’s a sample image:

What I’m interested in starting with is just highlighting the polygons with some sort of wireframe line, but also have them flat shaded. The terrain in the above image is an example of what I’m trying to start with. Both of these effects seem more difficult to achieve than I would have thought! Any recommendations on how to approach this?

I was thinking of writing a surface shader to get the flat-shaded look (I don’t want smooth lighting on the polys). Also, I was trying to find a good way to show some sort of glowing wireframe along the polygon edges. Again, I tried to write a shader based on what I found here:

http://unifycommunity.com/wiki/index.php?title=BarycentricWireframeUv1

but it doesn’t seem to work. Specifically, the shader compiles but the UVs are all messed up. I added a C# script to a Sphere to try to make the polys use barycentric coords, but it doesn’t really make sense because I figure there should be as many UV coordinates as vertices, but in the example shown there only 4 UV coordinates are generated instead of the 525 on my sphere!

Regardless, maybe I’m going about this the wrong way. I’ve also looked into Vectrosity for the line drawing, but it seems in all the examples it ONLY draws lines, but won’t necessarily draw them overtop of my flat shading. It seems a shader would be the most performant approach to me, but I’m really new to this stuff and I’m hoping there’s a fairly simple way to do it.

Thanks for any help you can provide me with!

Just split vertices on hard edges, no need for shaders.

It would if you use 3D lines, though you’d want to offset them slightly from the surface. I’m not really sure it’s the best way for drawing an entire terrain though. I’m pretty sure the lines are just a texture in Darwinia.

–Eric

Thanks for your reply Eric.

The vertex splitting is a good suggestion. I had read about that elsewhere in the forums. As an aside, I’m assuming it would only be possible to make this happen if the model you wanted to flat shade was imported from another program. Specifically, I’m assuming there’s no way to split the vertices of a Unity sphere within Unity – the process would have to involve exporting, splitting, then re-importing?

Using a texture for the terrain lines is a good suggestion. To be honest, it was also my working assumption about how the terrain was done. Unfortunately, it’s the programmer in me that expects that there should be a better, more flexible way. I figured if I could do it as a shader (or some other way programmatically), then I could just change a line in code rather than having to change a texture image. Also, there could potentially be infinite level of detail as you zoomed into/out of a mesh (like vector graphics) as opposed to blurring which I would expect to appear if the wireframe effect was achieved using textures.

Looks like I’m asking a bit much! Or that I require Unity Pro so I can start trying to do this using OpenGL directly…

Thanks again for your help, and let me know if anything else comes to mind!

Within Unity you can set it to auto-calculate normals to be faceted by setting the auto-calculate normals angle to 0.

Great suggestion Farfarer – thanks! I’ll try that out tonight and see what I get!

No, you can just split the vertices of any existing mesh in code.

function Start () {
	// Get mesh info from attached mesh
	var mesh = GetComponent(MeshFilter).mesh;
	var vertices = mesh.vertices;
	var uv = mesh.uv;
	var triangles = mesh.triangles;
	
	// Set up new arrays to use with rebuilt mesh
	var newVertices = new Vector3[triangles.Length];
	var newUV = new Vector2[triangles.Length];

	// Rebuild mesh so that every triangle has unique vertices
	for (var i = 0; i < triangles.Length; i++) {
		newVertices[i] = vertices[triangles[i]];
		newUV[i] = uv[triangles[i]];
		triangles[i] = i;
	}
	
	// Assign new mesh and rebuild normals
	mesh.vertices = newVertices;
	mesh.uv = newUV;
	mesh.triangles = triangles;
	mesh.RecalculateNormals();
}

–Eric

Even better – I’ll try that out also tonight and see how it works. Seems straightforward enough – that should give me the lighting effect I’m hoping for without writing a shader, so that’s good news!