Hi. I have a problem with outline shader. The task is to do borders between territories like in Civilization or in Europa Universalis. I'm using Unity 5.5.0p3 and in this version objects are in editor selecting by orange color. I found thread where explained how it works (https://forum.unity3d.com/threads/selection-outline.429292/#post-2776318) - i create these two shader files, put them in Assets folder, create a new material (without texture), apply this shader from thread, apply the material to the object, but nothing happened - no borders, nothing. Where's i'm wrong? Code of hexagons generating: Code (CSharp): public class FX_HexGen : MonoBehaviour { public Material material; public GameObject MakeHex (int offset, float scale) { Mesh mesh = new Mesh(); Vector3[] vertices = new Vector3[7]; //Center vertices[0] = Vector3.zero; vertices[1] = GetVertexPos(0 + offset) * scale; vertices[2] = GetVertexPos(60 + offset) * scale; vertices[3] = GetVertexPos(120 + offset) * scale; vertices[4] = GetVertexPos(180 + offset) * scale; vertices[5] = GetVertexPos(240 + offset) * scale; vertices[6] = GetVertexPos(300 + offset) * scale; int[] triangles = new int[18]; //Top triangles[0] = 0; triangles[1] = 2; triangles[2] = 1; //Bottom triangles[3] = 0; triangles[4] = 3; triangles[5] = 2; //Bottom Left triangles[6] = 0; triangles[7] = 4; triangles[8] = 3; //Bottom Right triangles[9] = 0; triangles[10] = 5; triangles[11] = 4; //Top Right triangles[12] = 0; triangles[13] = 6; triangles[14] = 5; //Top Left triangles[15] = 0; triangles[16] = 1; triangles[17] = 6; Vector2[] uv = new Vector2[7]; // Center uv[0] = new Vector2(.5f, .5f); uv[1] = new Vector2(1f, .5f); // Top Left uv[2] = new Vector2(.75f, .935f); // Top Right uv[3] = new Vector2(.25f, 0.935f); // Bottom Right uv[4] = new Vector2(0, 0.5f); // Bottom Left uv[5] = new Vector2(.25f, .065f); // Center Bottom Left uv[6] = new Vector2(.75f, .065f); // Bottom Left mesh.vertices = vertices; mesh.triangles = triangles; mesh.uv = uv; mesh.RecalculateNormals(); GameObject o = new GameObject("New Hex"); o.AddComponent<MeshRenderer>(); o.AddComponent<MeshFilter>(); o.GetComponent<MeshFilter>().mesh = mesh; mesh.RecalculateNormals(); mesh.RecalculateBounds(); o.AddComponent<MeshCollider>(); //o.GetComponent<Renderer>().material = material; return o; } }
The post you originally linked to has some basic instructions for how to use those two shaders, and it's far more than just slapping them on an object. There have been a few threads since that post with people putting up github repos with the effect working. However if what you're looking for is to have all of your regions individually outlined all of the time, that is not the way to do it. The effect is relatively expensive, so it's appropriate if you're looking to highlight one, or maybe a small handful of individual regions. If you want to give them all an outline that is something you'll want to do via C# to build out additional geometry and/or encoding data in the existing geometry that the shader being used to draw the regions normally can use to know where the edges are.