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

TileMap System: RuleTile Definitions and Shaders

Discussion in '2D' started by Dennooo, May 18, 2021.

  1. Dennooo

    Dennooo

    Joined:
    May 12, 2015
    Posts:
    78
    Hi there,

    I'm currently trying out the TileMap system integrated in Unity and have a few questions that I hope you can help me with :D

    1. RuleTiles: I want to render different wall types (each has its own RuleTile) using the same TileMap renderer and would like to achieve two things here:

    a) The sprites should not be selected exclusively according to whether the neighbors use the same RuleTile, but whether their neighbours are not null. Please see the attachment for an example of what I want to achieve:
    Graph A shows the correct representation if a neighbor utilizes the same RuleTile. Graphic B shows the output when different RuleTiles is used. Instead of the result from B I want the one from graphic C. Is there an easy way to insert an "Empty" next to the "This" and "Not this" for the RuleTile definitions?

    b) How would you proceed if you wanted to display a Zig-Zag line between two tiles from different RuleTiles (like in figure D)?

    2. Fog of War: Currently I use the TileMapSystem to display a Fog of War as an overlay using square black tiles. This works fine, but it's not very pretty. What I would like to do is to use shaders to display the silhouette of all filled tiles (not single tiles) outside the tile area and animate them (an animated line, so to speak). I hope the attached example 2 clarifies what I am looking for:

    It is important that the outline would have to be generated even if the sprite does not contain transparency. Is this possible with the TileMapSystem or is there a better approach?

    Many thanks in advance.
     

    Attached Files:

  2. Dennooo

    Dennooo

    Joined:
    May 12, 2015
    Posts:
    78
    I just stumbled across the documentation for the API to easily add new ruleTile rules :oops:
    But how would you render a black zig-zag or border line between tiles from different ruleTiles?

    I see the following options:
    1. Draw all sprites with different borders and render them on the same tileMapRenderer as the walls. Each sprite with a border would receive 1/2 of the border size to create the illusion of 1 border. Problem: Small changes in the sprites or borders would potentially require to recreate all sprites.
    2. Define a border and draw it where required. For small projects I would simply find the positions where the borders should be and render them via SpriteRenderers. While this is straightforward, this is not suitable for my project due to performance overhead of such a solution. I was thinking of using a tileMapRenderer to exclusively render the borders. In this case I cannot think of a better solution than slightly offset that border tileMapRenderer (relative to the tilemapRenderer of the walls) to draw the lines between two sprites. While this would certainly work, it seems a little hackish.
    3. Use some shader wizardry (unfortunately I have no idea what kind of shader I could use for this).
     
  3. rarac

    rarac

    Joined:
    Feb 14, 2021
    Posts:
    570
    you have to create extra sprites with the zig zag border and place them according to your rules