2D Mobile Optimized Lighting System


I'm working on a 2D lighting system for Unity. The quick story is I was going to add the Unity's Light2D into my mobile 2D game, but when I downloaded it, I soon realized there would be a problem as that lighting system didn't have shadow casting implemented. So I spent almost an entire week and a lot of hours implementing a collider-based wall detection which calculated shadows in a shader.. and after a pretty sweet result in my PC, I realized I had to test on my phone... 6 fps. After a bit of testing and profiling I realized the problem came from the mere Light2D that Unity implemented, so a bit mad at Unity I started creating my own really basic SpriteRenderer-based light, and implemented my previous shadow calculation system in it. Up to now, I have a single component light working with a SpriteRenderer on the same GameObject, with a couple settings for adapting the light to your needs. Also, this light (updating at every frame, which isn't necessary, runs at 40 - 50 fps in my phone!)

Comments

Log in with itch.io to leave a comment.

Nice :D

Do you have any scripts, or is it still a WIP? Been wanting to see how this is done for ages. Does it support all collider types too? Thanks

Hey! Sorry for the late reply, I've been busy with another project lateley, so I haven't had time to work on it so much, but I will certainly finish it and make it as perfect as I possibly can. About the colliders, at the moment it only works with polygon colliders but I'm planning on making it compatible for all types of colliders. Boxes and circles are easy but I found some colliders as TilemapCollider2D or well, CompositeCollider2D are kind of weird in the way you would get it's vertices, which is the main thing this needs to work. But I have to investigate more on the topic.