Search Unity

Showcase Tillable Texture Atlas Using Shader Graph

Discussion in 'Shader Graph' started by GameBam, Feb 7, 2021.

  1. GameBam

    GameBam

    Joined:
    Feb 4, 2021
    Posts:
    11
    In a project I was working on, I wanted to implement Greedy Meshing to reduce the vertex count. The only issue is you would have to tile each face differently and I wanted to keep using the texture atlas to only need one or two materials total. It took a while to figure out, but with shader graph you can do exactly that!

    Below are the results, as you can see each texture which is a portion of a larger texture atlas can be tiled along a face.


    This will help reduce draw calls by reducing the material count and have textures for dozens of blocks in one 16x16 atlas (size can be changed).

    If you want to re-create this for yourself, below is a screen capture of the shader graph.


    The secret sauce to this shader is the fraction node and the fact it will tile the uv gradient when it goes above 1.0. This means to set the scale all you have to do is set the UV1 vectors for a quad to (0,0), (0, 2), (3, 2), (3, 0) to make the face tile 3x2.

    Now to select what tile on the atlas we want, all we do is set UV0 to constants of what tile (x,y) we want. As an example for a quad you would want to set all for UV0 vectors to (0, 15) if you want to have the texture on row 15 column 0.

    This may not be a great explanation so if you have any questions I will try my best to respond.
     
  2. garyalanridgway

    garyalanridgway

    Joined:
    Jul 5, 2017
    Posts:
    4
    Hey there! Finding this a year later lol. I am a little fuzzy on UV's, is that something you can set in the graph or somewhere else? Hope you are still able to answer questions after all this time! haha
     
  3. Settos

    Settos

    Joined:
    Aug 3, 2015
    Posts:
    16
    I've been looking for this. But now I am wodering, wouldn't I need to create a new material for every single tile on the texture atlas? And isn't that as bad as having multiple single textures?
     
  4. AldeRoberge

    AldeRoberge

    Joined:
    Jun 23, 2017
    Posts:
    60
    How's this project going?