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

How should shaders be adjusted for use with tilemaps?

Discussion in '2D' started by jolechallinor3, May 9, 2022.

  1. jolechallinor3

    jolechallinor3

    Joined:
    Mar 6, 2019
    Posts:
    9
    I have a sprite shader that takes the maintex and a secondary texture emission map, and uses it to apply bloom to parts of a sprite. It works great, but when used with the tilemap, has unpredictable results. I only want to apply the bloom to certain small parts of a specific tile, so I duplicated the tileset and set these parts white with the rest of it black. Could it be that it's trying to apply it to each individual tile, but since the top left 16x16 pixels are black, it doesn't work?

    How could I make this work the way I'm imagining it?

    The tileset (please ignore how messy it is):

    The emission map:


    The shadergraph:
     
  2. jolechallinor3

    jolechallinor3

    Joined:
    Mar 6, 2019
    Posts:
    9
    Sorry for the bump, but I'm really confused by this.

    It's as if it only pays attention to the top left 16x16 pixels, and even then, it'll either apply it to every tile or only the dirt tile. I can't correctly explain what it's doing wrong because it seems to be so random each time I experiment. I'm wondering if I'm using shaders for tilemaps wrong, and that's why.

    In reality, I think what I'm asking for is this, and how I imagined it to work in the first place:
    The shader would go tile by tile. It would take the tile and the UV space on the tileset, then take the same space for the emission map, and combine them to get the emission/bloom effect. Clearly I got this wrong, though.
     
    Last edited: May 11, 2022
  3. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,323
    This should work so I'm guessing you have a small mistake somewhere. To find it, I would recommend breaking the problem down a bit. Break off the sprite with emission from their spritesheets. Have that single sprite and its emission texture. In the Sprite Editor, associate the sprite with its emission texture. Then try again.

    Btw there's a feature called Sprite Atlas which you might find is helpful and is generally superior to maintaining a spritesheet yourself. It can also support secondary textures.

    Also your Shader Graph pic is a bit blurry.
     
  4. jolechallinor3

    jolechallinor3

    Joined:
    Mar 6, 2019
    Posts:
    9
    Thanks for the reply.

    Right now I am making use of secondary textures but it seems to ignore them for the emission map (I am using references correctly as far as I'm aware, unless it's case sensitive. I'll have to check them), meaning I have to drag it in on the material parameter. I'm using Super Tiled 2 Unity, not sure if that could be messing with it. I wouldn't be surprised, but it's hard to want to give it up as it makes my levels so much easier to work with.

    Edit:
    Just installed ShaderGraphToPNG. Hopefully this is better for you. My group names may seem a little odd, but I'm new to shaders, so this was the best way for me to help me learn and remember as I slowly try to make more advanced shader graphs. It's fun, though.
     
  5. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,323
    Your Shader Graph looks fine to me. The UVs should work for the main texture and emission map so long as they're parallel to one another correctly. Having a spritesheet shouldn't alter that.

    Does this shader work for an individual sprite with a emission map?

    To check if Super Tiled 2 Unity is somehow messing with things, what happens if you create a Unity Tilemaps Tile with the glowing sprite and put it on a Unity tilemap?
    This does sound odd. Might help to see a pic of this.