Hi everyone I've been working on a new mobile game for a week or so now. I've been using URP's 2D lighting system to give my game nice lighting and shadows, but unfortunately I've noticed that this has caused a major framerate drop in my game (from 60FPS to 15FPS). I rather have a smooth game than a pretty one, so I took out the lights. I wanted to ask - are there any other ways to incorporate lighting into my 2D game, that isn't as CPU-intensive? It could be a trick or a workaround as well. Anything to make my game look prettier without making it unplayable. Thanks in advance!
Depending on your project, this workaround may work for you. You could use white sprites like this with a transparent background and use the alpha for intensity. For shadows a simple elipse shape might be a good enough approximation. Edit: Grammar.
Some things to try Replace lights with semi-transparent sprites. Avoid shadows or fake them with semi-transparent dark sprites Fake lights with emission. Use an emissive shader with bloom. Remove bloom if emission itself sufficient. Bake "emission" into MainTex's color to avoid special shader altogether. Fake bloom by baking that in as well. Use only global light, or a few real lights, the others as fakes. No normals. Limit size of both real and fake lights you have.
This seems like the simplest solution to implement, however the shadow part is a bit lacking as far as I understand... Assuming I want to make a point light in my scene and I want the objects it hits to cast shadows, is there any way to replicate this effect with white sprites like this?
That's cool! I studied up a bit on shaders and looked for a bunch, I don't see any modern example which uses shaders for lighting. Is there an example you could point me to perhaps? Thanks in advance!
no problem, here are 2 shaders you can use for lighting, these work like blend modes in photoshop add and multiply. if you use these shaders on an image like @justLC posted, if you use the ADD shader it will look like a flash of light(all the white in the image counts as light source and all the black as transparent), if you use the Multiply shader it will simulate darkness( the blacks in the image will get rendered and the whites will be transparent.) if you apply the multiply shader on this image and you overlay it on top of your scene it will look similar to the image you posted. Of course now you would need a way to dynamically generate this black and white image, but if you can figure out a way to optimize that it will be much cheaper than normal lights and look the same.
Thank you very much for the shaders! They're pretty cool Unfortunately, my problem is precisely with the part you described in the end - I am not sure how to generate such a black/white image dynamically in a way that won't kill the CPU. In my head, just the raycasts needed to calculate where the light goes and doesn't go alone would be too much for a mobile build if my predictions are correct Thanks anyway though!
ye if your light moves around and changes the shape of the shadows you are better off using the lights
Hi, there are some assets in assetstore. https://assetstore.unity.com/packages/tools/particles-effects/2d-lights-and-shadows-119920 https://assetstore.unity.com/packag.../2ddl-pro-2d-dynamic-lights-and-shadows-25933 https://assetstore.unity.com/packages/tools/particles-effects/hard-light-2d-152208 (FREE)
Just wanted to say that I ended up using the Hard Light 2D asset @juanmabonet mentioned. It did the job perfectly, and is customizable enough to make it performant even on mobile. Highly recommend!