Hello! I've been playing around with unity for the past week (it's amazing, I like this editor) and am very impressed. I've even created a custom map editor setting atlased tiles on a mesh. The simple fact that I can extend an EditorWindow as easily as I did is awesome. I've used a wizard to create a mesh and my map layers into a group of objects. The mesh itself looks okay, but the UV data gets lost somewhere between meshing and the surface shader. My first attempt to debug this was to simply output the UV's in the mesh shader: Code (csharp): Shader "Mapping/MapShader" { Properties { _Atlas ("Atlas Texture (RGB)", 2D) = "white" {} } SubShader { Tags { "RenderType"="Opaque" } CGPROGRAM #pragma surface surf NoLighting fixed4 LightingNoLighting(SurfaceOutput s, fixed3 lightDir, fixed atten) { fixed4 c; c.rgb = s.Albedo; c.a = s.Alpha; return c; } sampler2D _Atlas; struct Input { float2 uv_MainTex; }; void surf (Input input, inout SurfaceOutput o) { //float4 tex = tex2D (_Atlas, input.uv_MainTex); //o.Albedo = tex.rgb; o.Albedo = float3(input.uv_MainTex.r, input.uv_MainTex.g, 0.0f); } ENDCG } Fallback "Diffuse" } The mesh stays completely black. Then I tried setting every UV to 1.0f. I'm creating my mesh like this: Code (csharp): Mesh BuildMesh(MapLayer layer, Mesh mesh, float ht) { int vertexCount = MapData.Width * MapData.Height * 4; int indexCount = MapData.Width * MapData.Height * 6; // CREATE VERTICES Vector3[] vertices = new Vector3[vertexCount]; Vector2[] uvs = new Vector2[vertexCount]; Color[] colors = new Color[vertexCount]; int[] indices = new int[indexCount]; int vCount = 0; int iCount = 0; Vector3 start = Vector3.zero; Color color = new Color(255, 255, 255, 255); for (int k = 0; k < MapData.Height; k++) { for (int j = 0; j < MapData.Width; j++) { vertices[vCount + 0] = start + new Vector3(j + 0, k + 0); vertices[vCount + 1] = start + new Vector3(j + 1, k + 0); vertices[vCount + 2] = start + new Vector3(j + 1, k + 1); vertices[vCount + 3] = start + new Vector3(j + 0, k + 1); uvs[vCount + 0] = new Vector2(1.0f, 1.0f); uvs[vCount + 1] = new Vector2(1.0f, 1.0f); uvs[vCount + 2] = new Vector2(1.0f, 1.0f); uvs[vCount + 3] = new Vector2(1.0f, 1.0f); colors[vCount + 0] = color; colors[vCount + 1] = color; colors[vCount + 2] = color; colors[vCount + 3] = color; indices[iCount + 0] = (short)(vCount + 0); indices[iCount + 1] = (short)(vCount + 2); indices[iCount + 2] = (short)(vCount + 1); indices[iCount + 3] = (short)(vCount + 0); indices[iCount + 4] = (short)(vCount + 3); indices[iCount + 5] = (short)(vCount + 2); vCount += 4; iCount += 6; } } mesh.Clear(); mesh.vertices = vertices; mesh.triangles = indices; mesh.uv = uvs; mesh.Optimize(); mesh.RecalculateNormals(); Debug.Log(mesh.uv[0].ToString()); Debug.Log(mesh.uv[1].ToString()); Debug.Log(mesh.uv[2].ToString()); Debug.Log(mesh.uv[3].ToString()); return mesh; } Still black. Checking the debug log, my UVs are DEFINITELY being set to 1.0f. Any ideas?
Your texture is called _Atlas. You're trying to get the UV coordinates for a texture called _MainTex...