I'm trying to setup a 2D game with lighting, but can't get lights to only illuminate specific objects. I've created a simple sample project with my expectation of how this should be working, and am hoping someone can see and explain what concept I'm missing here...
Full project as a .7z : https://file.io/rfpp6xGcRXTc (attribution: uses assets from the Pixel Crawler pack: https://anokolisa.itch.io/dungeon-crawler-pixel-art-asset-pack )
Scene setup:
- Node2D (root node)
- TileMap (Visibility.LightMask=1)
- Sprite2D (Visibility.LightMask=1)
- Sprite2D (Visibility.LightMask=2)
- Sprite2D (Visibility.LightMask=3)
- Sprite2D (Visibility.LightMask=4)
- CanvasModulate (Color=DarkGrey(0.21,0.21,0.21,1.0); Visibility.LightMask=1)
- DirectionalLight2D (Visibility.LightMask=2; Shadow.Enabled=True; Shadow.ItemCullMask=2)
- Button (onPressed toggles .Enabled of the DirectionalLight2D above, on LightMask 2)
- DirectionalLight2D (Visibility.LightMask=3; Shadow.Enabled=False)
- Button (onPressed toggles .Enabled of the DirectionalLight2D above, on LightMask 3)
The idea is:
- TileMap providing a ground background (Light Mask 1)
- 4 Sprites on 4 different Light Mask layers
- CanvasModulate to darken one/all Light Mask layer(s) (same behavior if this is set to a single Light Mask or all 4?)
- 2 DirectionalLight2D s , each with a button to toggle it (
light.enabled = !light.enabled
), one on Light Mask 2, one on Light Mask 3
Expectation:
- Can press buttons to toggle lights, which will each only illuminate one of the 4 sprites
Reality:
- Either light fully illuminates all 4 sprites and the tileMap