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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Question How to alternate randomly between set of textures?

Discussion in 'Shader Graph' started by Fakkau, Mar 23, 2021.

  1. Fakkau

    Fakkau

    Joined:
    Mar 11, 2013
    Posts:
    22
    I have a wall with a tiling texture on it and would like to swap out the texture with different textures at random intervals. For example, texture A tiles 3 times, then texture B starts and tiles twice, then texture A again, then texture C a few times, etc, all on the same wall (face). The key thing to note here is that the texture seams need to line up; I don't want texture A to get cut off half way through the texture and then suddenly texture B begins (causing an ugly seam).

    I'm still learning shader graph, (or shaders in general really), and have made some progress, but I can't figure out how to achieve this one. Googling hasn't yielded anything. If anyone has an idea on how to do this, I'd appreciate the advice.
     
  2. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    1,553
    Hi @Fakkau,

    (I'm not 100% sure if I deciphered your use-case correctly, but this idea produces random tiling with seamless edges.)

    I think you could implement this by using a lookup texture for your "random" interval. This could be a typical texture or a procedurally generated value. Then use branching to select correct texture.

    Anyway, here's a quick example I cooked up. You probably can simplify a thing or two to reduce calculations.

    Please zoom into the image and also see the comments to understand why I did certain things:

    20210404_random_tiling.png

    You could also implement this so that you use only single texture page/atlas for the textures to be randomized, and then use the lookup texture to scale and offset UVs so that you can select specific tiles and then place them to your result. But that might be slightly complicated, especially when written in graph form. It might better to create a custom function node if you would use this kind of approach. But in any case there are a few ways you could do this.
     
    Last edited: Apr 4, 2021
    Fakkau likes this.
  3. Fakkau

    Fakkau

    Joined:
    Mar 11, 2013
    Posts:
    22
    Thanks! I managed to get a working graph a few days ago, but the final graph was so messy that when I look back at it now, I have no idea how it works anymore haha. Yours looks a lot more clean/efficient, so I'll try it out!