Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Texture UV in custom mesh

Discussion in 'Editor & General Support' started by PatataFrita, Mar 17, 2021.

  1. PatataFrita

    PatataFrita

    Joined:
    Oct 17, 2014
    Posts:
    50
    Hi, I have a question about textures and UVs. I have a terrain similar to this, Minecraft style:



    Each face of the cubes has its own vertices, so a neighboring face does not share any vertex. In this way, a different texture can be added to each face by specifying its UVs.

    The problem I have is that I want to create each face of the mesh sharing its vertices between the faces, how would I have to do to add a different texture on two faces if they share their vertices?

    It is understood what I am asking?
     
  2. PatataFrita

    PatataFrita

    Joined:
    Oct 17, 2014
    Posts:
    50
  3. PatataFrita

    PatataFrita

    Joined:
    Oct 17, 2014
    Posts:
    50
  4. Reshima

    Reshima

    Joined:
    Dec 10, 2012
    Posts:
    51
    Deleted by author since info was unrelated to the question.
     
    Last edited: Mar 26, 2021
  5. PatataFrita

    PatataFrita

    Joined:
    Oct 17, 2014
    Posts:
    50
    Hello. I have not explained myself clearly enough, sorry. I know about the "mark seam" of blender, but I am generating the terrain in runtime, I create the mesh in runtime. So, I generate the terrain like this:
    upload_2021-3-26_15-8-28.png
    Each face of the cube is assigned its UVs because it has its own vertices. For example, vertices (1, 2, 3, 4) are assigned a UVs coordinate for grass, but (17, 18, 19, 20) a UVs coordinate for a dirt wall. Instead, if I create the terrain like this, sharing the vertices:
    upload_2021-3-26_15-8-34.png
    I can no longer assign the UVs to each face of the cube because they share the vertices. Or at least I don't know how to do it, that's what I'm asking, how can this be achieved.

    Thank you for helping me.
     
  6. Reshima

    Reshima

    Joined:
    Dec 10, 2012
    Posts:
    51
    Ok I'm sorry I misunderstood the question. I believe you can't do it without duplicating the vertex.

    As you know, each vertex gets assigned a Vector2 which is the coordinate in the texture which is a value from 0 to 1 for the U and V coordinates (0,0 for bottom left). Unless if you create a different UV coordinate (uv0, uv1) which is impractical for your use case, you can't assign different UV values for each vertex. The texture for a single face in this case would also need to share coordinates but this is impractical for you too because not every face share coordinates.
     
    PatataFrita likes this.
  7. PatataFrita

    PatataFrita

    Joined:
    Oct 17, 2014
    Posts:
    50
    But then how do other terrains (that share vertices) to be created in runtime and with different textures?
     
  8. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,762
    UV coordinates map directly to Vertices. That's just how it works in a Unity Mesh object.

    They don't on Unity. They might at a higher level with their own internal structures, but a translation has to be done to get it from whatever crazy structure they have down to the Unity Mesh structure.

    The only other way would be to live-manipulate your textures, fabricating hybrid chunks of continuous textures that couple different patterns side by side. I can't imagine this would be performant or easy to do in the general sense.
     
    PatataFrita likes this.
  9. PatataFrita

    PatataFrita

    Joined:
    Oct 17, 2014
    Posts:
    50
    And how could I do that? Wouldn't it thus be possible to generate a procedural terrain in runtime with different textures on each face but sharing the vertices?

    Thanks for answering.
     
  10. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,762
    As long as both of those textures can be placed on the same Material.
     
    PatataFrita likes this.
  11. PatataFrita

    PatataFrita

    Joined:
    Oct 17, 2014
    Posts:
    50
    You mean this?

    upload_2021-4-10_20-36-45.png

    That is, not that each face of the terrain has a texture, but rather that the terrain is an entire texture.