Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

New Tilemap with Shadow Support?

Discussion in '2D' started by radonthetyrant, Aug 21, 2017.

  1. radonthetyrant

    radonthetyrant

    Joined:
    Feb 14, 2014
    Posts:
    6
    I checked out the new Tilemap system and would like to use it as floor surface in a kinda top-down-shooter game.

    I want to use walls that block off light and can receive shadows. I noticed that it is hard to get a tilemap to use shadows at all.

    I wrote a script, that takes the TilemapRenderer and does this:

    TilemapRenderer.receiveShadows = true;
    TilemapRenderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.On;

    But it only works with the Default-Shader. Check this out:



    The Default-Shader does it right, but ideally I'd like to have the Normal Mapped Tile Shader work as well. Is there any way to get the same shadow results with normalmap feature?

    The Normal Mapped Shader is from here: https://github.com/Unity-Technologi...Assets/Tilemap/Normal Mapping/Material/Shader
     
  2. Deleted User

    Deleted User

    Guest

    Seems that shadow receiving is not supported with the tilemaps. Even changing the sprite rendered to a mesh renderer does not work and just makes the whole tilemap disappear. Too bad as I would love for this feature to work out of the box. Maybe you can make an "bug" issue? :D
     
  3. radonthetyrant

    radonthetyrant

    Joined:
    Feb 14, 2014
    Posts:
    6
    I'm going with the default shader for now as it supports shadows until there is a proper tilemap shader that supports shadows.

    But feel free to open a request. That would be nice to have for sure
     
  4. Fido789

    Fido789

    Joined:
    Feb 26, 2013
    Posts:
    343
    How did you manage to get the shadows working? I thought it will be as simple as putting
    Code (CSharp):
    1.  
    2. public class ShadowActivator : MonoBehaviour
    3. {
    4.     private void Awake()
    5.     {
    6.         GetComponent<TilemapRenderer>().receiveShadows = true;
    7.         GetComponent<TilemapRenderer>().shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.On;
    8.     }
    9. }
    10.  
    on tilemap game object, but it isn't.

    Am I missing something?

    EDIT: I just noticed you are using Default-shader and not Sprites-default (confusing naming), I am going to try it out.

    EDIT 2: Not working even with Default-shader

    EDIT 3: Ok, my fault, it is working. Thanks!
     
    Last edited: Feb 2, 2018
  5. Aske_Johansen

    Aske_Johansen

    Joined:
    Mar 30, 2018
    Posts:
    1
    I have the same problem, but i am unable to find the default-shader. Has it been renamed in a newer version?

    Edit: Ok, so i also found a way to make it work:
    1. Make sure that whatever light used has either a hard or soft shadow type
    2. Select the tilemap that needs to receive shadows, and under the tilemap Renderer component in the inspector, select Material > Assets-tab > Default-material.
    3. Tell the tilemap to receive shadows by giving it a scrip just like the one Fido789 made.

    That should be it :)
     
    Last edited: Jul 13, 2018
  6. ZerkyWerky

    ZerkyWerky

    Joined:
    Apr 2, 2009
    Posts:
    129
    I found an easier way to do this.

    1. Create a new standard material and put it in the tilemaps TilemapRenderer material.
    2. In the very top right hand corner of the inspector, click the little icon that has 3 horizontal lines. It's right of the lock icon.
    3. Select Debug. You should see extended fields in your components now.
    4. In the TilemapRenderer, click Receive Shadows.
    5. Change back to Normal.
    6. Marvel at what you have done.
    7. Get back to work.
     
  7. sovredcat

    sovredcat

    Joined:
    Sep 8, 2013
    Posts:
    14
    This works, however how would you cast a shadow from objects? I've added a 3D cube but it doesn't cast the shadow on the tilemap.
     
  8. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,503
    Also curious, esp for how to get it to work right w/ isometric