Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

ASE - Texture Blending issue

Discussion in 'Shaders' started by Deadphyre, May 30, 2018.

  1. Deadphyre


    Sep 26, 2013
    Hello ladies and gents, I've got a small issue that is probably really simple but I thought that maybe somebody could shoot an idea my way as to what the problem might be. I've got a shader I made using ASE that mostly, but smoothly blends textures together onto a procedural mesh. Basically I created a iso sphere, and chunked triangles up into data for generating spherical terrain. Both the sphere and the chunks use the same shader created with similar data through the exact same process. The sphere used to shade it's textures correctly but now, as you'll see in the screen shot it no longer blends them together and in some of the middle height layers, doesn't use the correct texture while the chunks, that literally use the same textures, same height data, same vertex data for that chunk/triangle from sphere and same shader works just fine.

    This is the idea where I got my blending from, just use textures instead of colors and I put in multiple textures.
    [Side note] If I disable the lerping of the textures on the sphere, it works but no longer blends, if I disable then the blending works only on the chunk.

    This screen shot is what it looks like from scene view and game view within the editor. As you'll see in the scene view, the middle height of the mesh is supposed to be rock, but instead it's either black or a neon color.

    The code for setting the mesh for the chunks:
    Code (CSharp):
    1. var data = gameObject.GetComponent<Planet_Data_Holder>().newBasePlanet.planetBaseChunks[i];
    3.                     GameObject aChunk = GetFirstDeactiveChunk(true);
    4.                     if (aChunk == null)
    5.                     {
    6.                         break;
    7.                     }
    8.                     List<Vector3> radVerts = new List<Vector3>();
    9.                     List<Vector3> radNorms = new List<Vector3>();
    10.                     blankUVs = new List<Vector2>();
    11.                     blankUVs = data.chunkUV;
    13.                     radVerts = GenerateChunkMap(data.chunkVert, true);
    14.                     radNorms = GenerateNormals(radVerts);
    16.                     Mesh mesh = aChunk.GetComponent<MeshFilter>().mesh;
    17.                     Destroy(aChunk.GetComponent<MeshCollider>());
    18.                     MeshCollider chunkCol = aChunk.AddComponent<MeshCollider>();
    19.                     aChunk.GetComponent<Renderer>().material.SetTexture("_HeightMap", planetHeightMap);
    20.                     aChunk.GetComponent<Renderer>().material.SetFloat("_PlanetRadius", planetRadius);
    21.                     mesh.Clear();
    22.                     mesh.vertices = radVerts.ToArray();
    23.                     mesh.normals = radNorms.ToArray();
    24.                     mesh.triangles = data.chunkTri.ToArray();
    25.                     mesh.uv = blankUVs.ToArray();
    26.                     chunkCol.sharedMesh = null;
    27.                     chunkCol.sharedMesh = mesh;
    28.                     mesh.RecalculateBounds();
    29.                     mesh.RecalculateNormals();
    30.                     aChunk.SetActive(true);
    The code for setting the mesh for the sphere (aka Planet):
    Code (CSharp):
    1. var mainPlanet = gameObject.GetComponent<Planet_Data_Holder>().newBasePlanet;
    2.         var mainGO = gameObject.GetComponent<MeshFilter>().mesh;
    3.         float newRadius = planetRadius - 8f;
    4.         List<Vector3> radVerts = new List<Vector3>();
    5.         List<Vector3> radNorms = new List<Vector3>();
    6.         blankUVs = new List<Vector2>();
    7.         blankUVs = mainPlanet.planetUV;
    9.         radVerts = GenerateChunkMap(mainPlanet.planetVert, false);
    10.         radNorms = GenerateNormals(radVerts);
    12.         Mesh mesh = gameObject.GetComponent<MeshFilter>().mesh;
    13.         Material mat = Resources.Load("Material/unexploredPlanet") as Material;
    14.         MeshFilter filter = gameObject.GetComponent<MeshFilter>();
    15.         Destroy(gameObject.GetComponent<MeshCollider>());
    16.         MeshCollider col = gameObject.AddComponent<MeshCollider>();
    17.         mesh = filter.mesh;
    18.         mesh.Clear();
    20.         gameObject.GetComponent<Renderer>().material.SetTexture("_HeightMap", planetHeightMap);
    21.         gameObject.GetComponent<Renderer>().material.SetFloat("_PlanetRadius", newRadius);
    23.         mesh.vertices = radVerts.ToArray();
    24.         mesh.normals = radNorms.ToArray();
    25.         mesh.triangles = mainPlanet.planetTri.ToArray();
    26.         mesh.uv = blankUVs.ToArray();
    27.         col.sharedMesh = null;
    28.         col.sharedMesh = mesh;
    29.         mesh.RecalculateBounds();
    30.         mesh.RecalculateNormals();
    Sorry about the above code, it has some long lines so it does the wrapping thing.

    After setting the mesh data for each respective object, it uses custom height data (from libnoise GetValue) and stores it in the uv.x for each object. Since this is a triplanar shader. I can screenshot it if it might help but it's relatively compact visually and might be difficult to make sense of.

    Thank you for any help or ideas and I'm fairly certain that whatever the issue is, is super simple than any sane person should have gotten right off the bat.
  2. Deadphyre


    Sep 26, 2013
    For those interested here is an image of the shader in ASE.