Lighing system for 2D android game Without unity light

Hello everybody !

I’m doing a 2D pixel game for android and i try to add a lighting system in my game but without the unity light system ( Too much cost in my case)

Here what i want to a have :
(I want this gradient pixel effect , and the possibility to erase the light when a other light come, exactly like its show on the picture)

I tried with sprite mask, but i fail , don’t know if i’m doing wrong or not enought knowledge about that …
Somone told me something about use shader , but i don’t know enought about that too :confused:

So if someone have a link , or advice for me and help me i’ll really appreciate !

Have good day !

You need to look for tutorials about Stencil Buffer, and write your own shader.
It’s scary but at the end, not so hard :wink:

You had a good intuition when you tryed to use mask sprite, stencil buffer allow you to achieve something similar directly in a shader.

1 Like

Seems like Youtube is your friend :smile:

2 Likes

Thanks for your help ! You give to me some good hours to learn about how write my own shader , didn’t realise the power of the shader , I didn’t really understand how these work !
Thanks for show me the way :smile: !!

A particular good day to you my friend, you already made mine lol ! !!

Edit : is it optimize for mobile game ? It’s for a 2.5d game on android ^^

It might be possible with SpriteMasks but I don’t think it’ll be very optimized.

Okay so , after a few days of research , some test , other stuff…
I found somethings wich work for me ( And i don’t understand how really because it’s basic lighting , so lot of cost in some case )

I found this Github file with a exemple of spotlight for 2D sprite (basic)
I imported the prefab “Directional light” in my scene.
change the cookie by one made by me with photoshop, change settings on alpha source fromgreyscale : Here the cookie :

After that i have changed directionnal by Spotlight (It’s still keep the cookie form for the light)

and here the result on my 2.5D android game:

I’v tested with 8 light baked in important on a 4.4.2 samsung j3(2016) and great result, it’s not 100% smooth , but fully playable !

Thanks again for all your link or tips and other !