Search Unity

Resolved Referencing multiple textures on one mesh

Discussion in 'Scripting' started by puddleglum, Feb 16, 2024.

  1. puddleglum

    puddleglum

    Joined:
    May 11, 2020
    Posts:
    412
    im trying to generate a mesh with multiple cubes, like Minecraft, and I don't want to store every single texture in a single texture sheet for obvious reasons. so how do I programmatically reference different materials or textures when mapping UV coords
     
  2. Bunny83

    Bunny83

    Joined:
    Oct 18, 2010
    Posts:
    3,998
    Not sure what you mean by
    Minecraft always has used a texture atlas. In the beginning and for a long time we had a single 256x256 "terrain.png" which included all textures for all blocks. Since 2013 MC uses a dynamically generated texture atlas from the individual textures..
     
  3. puddleglum

    puddleglum

    Joined:
    May 11, 2020
    Posts:
    412
    ah my mistake, I did a quick lookup and found a couple results saying it used multiple atlases, probably should have checked the sources lol
     
  4. Bunny83

    Bunny83

    Joined:
    Oct 18, 2010
    Posts:
    3,998
    Well, afaik MC only uses a single atlas texture for the terrain. It has several atlases for other purposes (entities, items, particle effects and some other stuff). Most modern GPUs have a texture size limit of 16k². That means with the default block texture size of 16x16 you can fit one million textures into one atlas. Though when your textures are 128x128, you can only handle 16k textures. When you have 512x512 textures only 1024 would fit in that atlas.

    It seems that only modern Nvidia GPUs can handle larger textures likd 32k². Just a couple of years ago the low spec limit you should keep in mind was somewhere around 2k and 4k. It was a gradual change. If your game demands such a high texture resolution support, it would limit who and which devices will be able to run it.

    Binding textures during rendering is very expensive. That's why you want to avoid switching out textures / materials. That's why Unity actually has batching support so that objects which use the same material cam be rendered together.

    Technically it would be possible to have two or more texture atlases, however that would mean you would split a chunk into several meshes.
     
  5. puddleglum

    puddleglum

    Joined:
    May 11, 2020
    Posts:
    412
    ah I see ty