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 Apply shader to tilemap as a whole

Discussion in '2D' started by SleepyDevil, Sep 3, 2020.

  1. SleepyDevil

    SleepyDevil

    Joined:
    Aug 5, 2013
    Posts:
    30
    Hey there,
    as I am testing around with the new shader graph I tried to apply some shaders to tilemaps.
    The problem is that the shader always gets applied to every single tile.

    upload_2020-9-3_2-5-17.png

    Is there a way to apply the shader to the tilemap as a whole?
    This way we could add stuff like organic color variations on grass tiles.
     
  2. ChuanXin

    ChuanXin

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    1,068
    Could you share your material and shader setup for your TilemapRenderers? The shader should be applied to all the Tiles in the Tilemap when set.
     
  3. SleepyDevil

    SleepyDevil

    Joined:
    Aug 5, 2013
    Posts:
    30
    Sure, its just some test material I quickly did with the shader graph.

    upload_2020-9-4_16-58-12.png upload_2020-9-4_17-14-9.png

    The weird thing is, if I try to apply the skybox material for instance it seems to work somehow.

    I also attached a demo file.
    https://filebin.net/8wv656a7ta6ldp8b
     
  4. SleepyDevil

    SleepyDevil

    Joined:
    Aug 5, 2013
    Posts:
    30
    Sorry to bump this. But I spent two whole days trying around without any success. Really hope someone can help.
     
  5. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,319
    Your OP looks like it's missing a "not" in one sentence, which might be the source of the confusion.
    I added a "not" - is that what you meant? You want per-tile properties?
     
  6. SleepyDevil

    SleepyDevil

    Joined:
    Aug 5, 2013
    Posts:
    30
    Thank you for your answer, but actually no, this is not what I meant.

    Maybe ChuanXin also understood me wrong, I think, maybe I did a poor job at at explaining my problem.
    I tried to come up with a fictitious example that illustrates my problem better.

    In the example it is a cutout-shader, but it could be any shader created with the shader graph.

     

    Attached Files:

    Last edited: Sep 7, 2020
  7. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,319
    I think you want to use the Position node with the World or Absolute World setting. Plug that into your UV for Simple Noise. Right now, it's implicitly getting UVs from the tile's sprite. If you make it relative to the world, then it should apply across tiles.
     
    GB2102, Jamisco, dasgandlaf and 5 others like this.
  8. SleepyDevil

    SleepyDevil

    Joined:
    Aug 5, 2013
    Posts:
    30
    Oh god, that is the solution! I'd throw my money at you if I had any, haha. Thank you, you saved me so much headaches.
     
  9. MrUncreative

    MrUncreative

    Joined:
    Jul 9, 2017
    Posts:
    1
    Oh shoot I was looking for the same answer and lo-renzo's answer works! Thank you so much lol
     
  10. A-Dree-N

    A-Dree-N

    Joined:
    Apr 5, 2021
    Posts:
    1
    I've got a quite similar problem but the solution does not seem to apply. I want to use a paper texture as an overlay for my tilemap.
    The node setup is as follows.

    upload_2021-6-30_14-56-12.png

    Instead of stretching the texture across all tiles I get this weird result:

    upload_2021-6-30_15-1-8.png


    Including a Tiling and Offset node steers it into the right direction, but it doesn't seem to be the right path to follow given the parameter values.

    upload_2021-6-30_15-3-4.png

    Result:

    upload_2021-6-30_15-3-35.png

    Does anybody have got an idea how to fix this properly?
    Thanks a lot in advance!
     
  11. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,319
    Hi, it's hard to understand your goal without seeing the inputs and the intended output.
    What does the paper texture look like?
    What does the tilemap look like with the normal sprite material?
    What do you mean by "overlay"?

    Try this first though: go to the texture in your project, change the Wrap Mode to Repeat.

    Next, if still broken: from your shader graph it doesn't look like you're using the alpha of your MainTex. I suspect this is may not be what you want. SampleTexture2D the _MainTex (add a new texture field to your Blackboard, give it "_MainTex" w/o quotes in the Reference field). Plug in its alpha to the output alpha. This will result in the shapes of your tiles remaining the same, but the paper's color overwrites the tiles' color.
     
    Last edited: Jul 1, 2021