Apply different shaders to tiles in a tileset

Godot Version



I am making a game that is done in 4 color monochrome, but I want to have a color mode. I am using shaders to recolor the sprites when this mode is enabled. For example, on a character, I will do a check to see if we are in the original monochrome mode, or in full color mode. If we are in the full color mode, I will use the shader to replace the colors in the sprite with other colors I have selected. It would still only be 4 colors, but each sprite could have any 4 colors I choose which would overall make the game more colorful.

I am wondering how to do this with my tiles. For example, imagine I have 4 tiles I am using in my tileset. The first tile is a tree top, the second tile is the tree trunk, the third tile is a patch of grass, and the fourth tile is a rock. When I recolor these, they would all need separate shaders, because the tree top would be shades of green, the tree trunk would be shades of brown, the grass might be other shades of green or it might use the same shader as the tree top, and the rock would be shades of gray.

I need to be able to change these in code, but I am not sure how to approach it. For example, can I separate them by layer and then change the shader on all tiles on that layer? Meaning everything that would use shader 1, goes on a certain layer in the tilemap and everything that would use shader 2 goes on another layer. I don’t think that works, but it is some idea of what I am looking to do.

How would you approach solving this?

You can set a Material to each tile. You can use different materials one for green, one for brown, one for gray,… and using the correct material in each tile. Then when you modify those materials shader parameters all tiles that have assigned that specific material will be affected by the changes.

1 Like

I didn’t know I could do that! That’s really cool! Thank you

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.