Hey guys I was trying to get lightmaps for my sprites when I find out that Unity does not bake lights for SpriteRenderer so I made a very simple editor script that trick Unity into bake the lightmaps for all sprites in the scene (if they are static).
Here is the git hub page:
I’m using the 5.4.1f1 so it tiny bit old, so let me know if there is a newer version that can do bake sprites lighting.
Tell me what your thoughts. What your guys think?
Edit:
[ALREADY FIXED] Looks like the script only works in editor in release builds the lights is disconsidered.
Edit:
The unity was not saving the lightmap data for the SpriteRenderer compoment so I added a new component to do save and the setup.
The unity shader has been changed for latest Unity builds (such as Unity 2017.1) and if you use default sprites/diffuse, there’ll be no lightmap support.
Please add lightmap support in your shader. I’ve wrote one for you.
Hey @lassade Thank you very much! We’re using a lot of lights in our game to make each level look different and give a unique feeling but I’m not sure how much that affects performance yet. It could be the shaders we’re using with Spine. Once we finish up the last chapter of the game we’ll start investigating ( xbox one is running 20 fps ) but your solution for 2D lightmaps is the only one I’ve found so far. I’ll let you know when we do!
Hey @lassade ! We’re also developing a 2D platformer and would really like to use your solution, but there is a problem. I noticed that Baking lightmaps on packed sprites give a rather weird result. All the light is moved by an offset from the origin point.
You can observe the same effect occurring in your demoscene as well if you pack background and foreground sprites.
No idea what’s happening, same issue here. My guess is the lightmap scale and offset is relative to the sprites UV when they change, the lights gets mess up.
I think its possible to fix, but no sure if you can allow rotation on atlas. I will give a closer look at it.
Hey @DrDrimixar I pushed a new version of the script that supports SpriteAtlas but is not an ideal solution, give a look at the README to see the limitations.
I think we rushed a bit and I think we’re getting the same issue with @DrDrimixar basically some squares are showing up weirdly, ours is more divided into smaller boxes, did you guys solve it somehow?
A while ago I submited an experimental feature to handle altases in github page check the section Sprite Atlas Support (Beta) in the README.md see if it works.
Yeah I saw that but we didn’t have time to implement it unfortunately as it would change quite a lot at this point.
Also testing this in a few situations I think pre-merging all the meshes could end up with a better result, unity’s default merging isn’t helping I guess because this isn’t taking place in runtime?
So it’s generating a lot of lightmaps and if you have a 3x3 tiling system for a building say it creates a few issues.
But yes, your implementation is definitely in our game which will soon be out: