Lightmaps (Bakery Asset)
Bakery is an asset on the Unity store that offers improved, and potentially faster, lightmap baking results in comparison to the Unity Lightmapper.
Bakery is usually about US$60.50, but can be found for half price on Unity Store sales. Bakery does things a little different from the Unity Lightmapper, and has some quirks of it’s own, but can be well worth the results.
Note that there are some considerations with the Bakery asset. The Mintable file does not include the Bakery asset due to licensing issues, and therefore there are some console errors with the build when opening the Mintable file in Unity. The owner will need to purchase Bakery as well if they want to use your lighting or update the scene, or they will need to redo the lightmapping with the Unity Lightmapper if they want to make any changes.
Bakery will also add significant filesize to the Artifacts and Portals scenes, even if there are little to no assets in them. So this negates the benefits of filesize with the better packing for the second UVs.
Due to the aforementioned issues Bakery is not recommended to use unless you understand the potential issues.
Overview
Install Bakery Lightmapper
Make sure the imported models have Generate Lightmap UVs (if you want Bakery to take care of that)
Set any object you want to bake into the lightmap to Static
Either add the Bakery light scripts to the lights you have in the scene or add bakery lights from the Bakery / Create menu.
Set up the Lightmap settings in the Bakery window
Render the lightmap
After rendering the Lightmap, generate the Reflection Probes (if you have them)
Installing Bakery
1. Open the Package manager from the Window Menu.
2. Add it to your layout.
3. (Sign in if you need to) and select Bakery - GPU Lightmapper.
4. Select Download in the bottom right of the Package manager (I will use a different asset as I already have the latest Bakery downloaded).
5. Once downloaded, select Import. A popup will appear asking what assets you want to import. Select Import at the bottom right.
Setting up the Scene
Generating Lightmap UVs
For lightmaps to bake the information your objects need a second layer of UVs to bake onto. You can do this yourself in an external application like Blender etc. But if you are putting the scene together in Unity it is somewhat easier and faster to let Bakery do this for you. Bakery has a much better packing algorithm than Unity does, with differing results depending on which method you use (more on that in the Bakery Settings section)
1. If you want Bakery to unwrap your objects for lightmapping, select your model file in the Project window and then go to Inspector / model tab > Generate Lightmap UVs. Then select Apply. A window may popup asking if you want to apply the change to the children objects as well.
NB : If you bake and your lightmaps look terrible (overlapped UVs, large dark blocks for no reason, etc.) then not having correct second UVs is probably the reason.
Static Objects
1. Select objects to be lightmapped in the scene or Hierarchy and set it to Static in the top right of the objects Inspector. If this is not set, the lightmapping will not see it.
Using Bakery
It is not possible to use Bakery Shaders in your Mona space. This is due to them referencing custom scripts, which are not supported in Mona. So using Bakery for lightmapping works fine, but using the Bakery shaders on objects do not.
We recommend using Standard or WebGL compatible shaders only.
Adding Bakery Lights
There are two methods to set up lights using Bakery, Adding Bakery scripts to pre-existing lights or creating them from the Bakery menu. Pre-existing lights offer a more visual guide to the result, whereas using the second method does not. Therefore using the second method won’t get visual results until after you bake the lightmaps. You could purchase the Bakery Previewer asset (that is still in a preview state as of Dec 2021) for real time previews of the Bakery results.
Method 1 -
1. Select a pre-existing light in your scene
2. Make sure that it is set to baked. This will make sure that the light does not count as a real time light. Note that this light is purely for visual reference in the scene and is not used in the final bake. The Bakery scribe is what is included in the baked scene.
3. Click on Add Component at the bottom of the Inspector.
4. Type ‘B’ in the search box to filter to the list of Bakery scripts
5. Select the script that best suits the light you are applying it to. Options are :
Bakery Direct Light
Bakery Point Light
Bakery Sky Light There are other Bakery scripts but they are outside this tutorial. Feel free to look at the Bakery docs here for more information.
You may note there is no spotlight script. An example Spotlight can be found using Method 2 to create a modified Point Light to create one.
Once you have applied the script, you can easily transfer your light settings over to the Bakery script using the Use real time to lightmap Button. Or vice versa with the Use lightmap to Realtime button.
Real-time = the Unity Light
Lightmapped = the Bakery Script
Note that changing the unity light and not updating the Bakery script is a common error, so keep that in mind when the lightmap doesn't work as you expect. Get used to transferring settings between the two elements of your lights as you will end up doing it quite a lot.
Method 2 -
1. Go to the Bakery / Create menu and select the light you would like.
2. Move your new light to your desired location, and angle. As noted, this method does not give any visual cues as to what this might look like.
3. Adjust the parameters on the Light settings as you see fit.
Bakery Lights in detail
This section will cover some of the elements of Bakery lights in detail. Coming soon.
Example Scene
As an example moving forward, this scene has one real time directional light (the one that comes with the template), a Bakery area light (which is basically a plane with a script that sets an emissive material to it), a Bakery spotlight (which is a modified point light that has no visuals in scene), and a Bakery point light (which is a Unity light with the Bakery Point Light script on it). All unity lights (apart from the realtime light) will be set to Baked (although this will not be used with Bakery). One object with emissive materials (see the materials tutorial for details) will also be added.
Lightmapping settings
1. In order to see the results of the lightmap baking, open the Lighting Tab and place in your layout.
2. Open the Bakery Tab using Bakery / Render Lightmaps. Drag and drop it according to your preferred layout location.
3. If you hit the Render button in the Bakery Settings window. Select yes to bakery automatically selecting Optimal settings. It is recommended to set the recommendations as default, and play with them afterwards if need be. Select yes if you have an RTX graphics card, or no if you have a card older than that. You do not need an RTX card for Bakery to function, but it will speed up the process if you do.
4. So far the best results I have found in the settings are the following ;
Some of these depend on the results of your Optimal Settings (such as RTX mode and Optix version).
Setting the Texels per unity will be the main factor on quality as this will give more space to the polygon in the lightmap texture. This of course means more textures will be needed. Adjust this as needed for optimal resolution to size.
If you select Xatlas under the Unwrapper it will come up with a popup about settings, I will usually apply the recommendations.
Directional Mode / Baked Normal Maps gives good results for speed. Other options may give better results for slower render times (or vice versa). Check the documentation for more information
Hole Filling will only be available if you use the XAtlas mode under Atlas Packer. I find this better for packing the second UV more efficiently.
Adding Ambient Occlusion will slow down the render but give better results to your environment. Use as you see fit.
Baking the Lightmaps
1. Once the objects are set to static, the Bakery light scripts have been added, and the settings are set to the above (or similar), you can render the lightmap by pressing Render at the bottom of the Bakery Settings tab.
2. Once baked, you can check the resulting Lightmap textures in the Baked Lightmaps section in the Lighting Tab. You can use this to visually see the result of the unwrapping process, and can sometimes guide you with trouble shooting (overlapping second UVs or sections of your space that don’t require baking (polygons that are never seen such as the other side of a ceiling or floor).
Refining Results
Improving your space
1. Modify Bakery Tab > Texels per Unit to adjust how much space the polygons take up on the lightmap. Increasing this will (potentially) increase the amount of Lightmaps you have (and therefore resulting file size) when the previous lightmap is ‘full’, but it increases the amount of space the polygons take up on the lightmap texture (eg. better quality). Finding the sweet spot between quality and number of lightmaps is half the fun.
NB : These renders are done on a Ryzen 5950X, 64Gb RAM, 2070RTX.
If you compare the results to the unity lightmapper, the number of lightmaps to quality is exceptional. I could go higher in quality and still keep the lightmaps small (note how the two maps are only 512 by 512 pixels) but to be honest this is more than reasonable, and would be more so if all the objects weren’t plain colour objects
2. Other options are available to tweak, but generally aren’t needed with results this good.
3. Isolate the results of your baked lights, by turning down/off your real time light/s and the environment/ambient lighting under Lighting / Environment / Environment Lighting > Source and/or Intensity multiplier. Your scene will look different when you turn these back on, but it’s a good way to understand the effect of each light…so bounce between the two (or three) states. Note that this only works with Unity lights as reference, and Bakery lights (on their own) will not be displayed in the space.
Optimising results
1. Make sure that the Lightmap resolution is set to the level that fills up the last lightmap. Check what your lightmaps look like in the Lighting Tab / Baked Lightmaps section. If there is any blank space on the final map, then turn up the Bakery Tab / Texels per Unity resolution (even by a decimal level) until there isn’t. Make sure that it doesn’t spill over into a new lightmap, and have most of it blank. Lightmaps will take up considerable file size, so keep this in mind when you are choosing how many you create. 2-3 at 2048 should be plenty. However this could be more or less depending on the complexity of your space.
2. It is possible to make an object take more texture space in the lightmap. Select the static object and increase/decrease the Mesh Renderer / Lightmapping > Scale under Lightmapping. Putting that higher will mean it takes more space in the lightmap, less and it will be smaller.
Miscellaneous
Mona related
1. Artifacts should not have Static applied as they will affect, and be affected by, the environment and they might not be there forever (as artifacts can be modified or turned off). So a safe bet is just to turn all Artifacts’ Static to off. Portals are fine however as they cannot be edited in the space.
Troubleshooting
All/some of my objects look dark/messup up
As noted, if many/all of your objects look like the lightmapping is messed up, there is a reasonable chance those objects have not been set to Generate Lightmap UVs correctly and the lightmaps are overlapping. Check out Generating Lightmap UVs at the beginning of this tutorial for more information.
My emissive object isn't affecting the objects around it
If your object that is meant to be emitting light does not seem to be affecting the space around it then your object might not be 'big' enough to do so. There are two ways to get around this :
Go back to the original model in your 3D application and make sure to reset transforms, Apply transforms or the equivalent. This will make sure that the asset is exported at the right scale
Go to the Model tab on the imported object in the Project window of unity. At the top there is Scale Factor. If you increase this the 'size' of the object is bigger, you will need to readjust the size in the scene once you apply this.
You could possibly use this to your advantage if you want an object to emit more light, without affecting the emissive material itself.
Last updated