As my teacher advised me I started of experimenting with lightbaking in a small scene. I tried to bake two spotlights and one point light onto the Databuffer (intercom asset) and the floor. I had the floor provided with clean UV maps, since the mesh is a simple plane. This resulted in a smooth lightmap for the floor. The databuffer on the other hand did not have UV's. In the gif on the bottom right is the successful lightmap on the databuffer and floor shown. Though when zooming in closely on the mesh, you can spot some ugly UV seems. To perfectionize this I actually need to make clean UV's for all of the assets.
Databuffer without UV's
Databuffer with UV's
Next mesh I tried to bake: the rocks. This turned into a disaster and would have taken 50 minutes to bake one directional light. That was not worth it in my opinion. My teacher told me to retopologize the rocks and floor, because their high polycount could likely be the reason for the slow baking process. I guess I underestimated the impact of the polycount.
The rocks in an endless baking process
The polycount disaster of the rocks and ground, around 400.000 tris
Rocks & Floor before = 400.000 tris
Rocks & Floor after = 120.000 tris
Rocks before = 94.000 tris
Rocks after = 72.000 tris
Floor before = 300.000 tris
Floor after = 48.000 tris
Starting of with discovering the new Retopologize tool in maya. I had to be careful since decreasing it with this method is not that clean and can rips off a lot of details very easily. For the medium and small rocks I tried to keep the counts between 200 and 500 polygons. For the larger ones they ended up shifting between 600 and 1000. This would not be the end result, since I still think I wanna replace them all by more solid ones in stead of cartoony round forms, but it is allright for optimization.
After this polycount descreasing process I moved on into merging some of the rocks that are crammed together. That would help me get rid of polygons which are never visible, because they are sticking through each other.
In the previous version of the rocks were all of the meshes combined. If I want to add Oclussion Culling, I need to seperate the rocks. They can be exported together in a group, as long as they are not all combined. After this was completed my teacher told me combine little groups of rocks. See the right gif below. This would make the amount of draw calls way less.
The floor was one of the biggest felons with over 300.000 tris. The decimation tool in Zbrush helped me decreasing this amount down to 48.000. In the left gif below you can see the before and after mesh shown,
Of course for lightmaps to work I need UV maps for all of the static meshes. I made some quick and dirty UV sets for the assets which are really not for showcase, but to get a better result in the end than letting Unity generate UV's automaticly. Below I show some of the results. Do not judge me on this. I just made it to test.
Now that I have the UV's was ready to make some baked lightmaps in a small scene like I did before. All objects in the scene are static except for the screen terminal one with the yellow screen. From left to right:
Realtime lighting: I can turn the Databuffer which results in changing shadows, because the light is dynamic and realtime. My previous SOMA scene was completely build with realtime lights.
Baked lighting: I can turn the Databuffer which results in no change of shadows, because the light is baked as a texture into the meshes. This does on the other end result in a darker scene and the only dynamic object (yellow screen) is now black, because it has no light source anymore. I was told that the solution for the dark scene would have something to do with the Indirect Multiplier settings from the Directional Light. I played around with this tool but with no results. The solution for the darken yellow screen is supposed to be solved by changing the Baked Lighting into Mixed Lighting.
Mixed lighting: when I turn the Databuffer, which is a static mesh, it still behaves as a dynamic mesh. The shadows change and are therefore not baked. In the project folder did pop up some lightmap textures of my scene, which makes me confused. My teacher told me that the Baked maps will start to render when the player moves further away from the mesh.
I noticed there is no chance for me to bake the directional lights in my scene, since they are volumentric. It would result in a dark dead scene (picture below right).
Default scene
Baked volumentric directional lights -> bad result
I have two directional lights that cast volumentrics around the environment. I have precisely created those in the previous phases and they both need to be present. Two directional volumentric sky lights: dark blue (base) and light blue (accent). Without one of them the scene loses depth.
Default scene
Without the light blue sky light
Without the dark blue sky light
The two pictures below demonstrate a tryout of non volumentric sky light. They are hardly visible, but you can notice some lighter highlights on the rocks. When I would push the intensity higher the environment becomes to revealing, which is the opposite of what I want. The lighting is fine as it is.
Default scene with a suttle green non volumentric directional light. You can see some small highlights on the rocks in the distance and the left side of the building.
Default scene with a suttle green non volumentric directional light. The rocks are a little bit lighter.
I could keep the non volumentric light and bake it, but I think my scene already contains the atmosphere that is needed. It's adding a new light too, which is the opposite of what I am trying to accomplish at the moment: optimizing.
For a moment I was afraid I would not be able to bake anything in my scene, since I thought every light was volumentric. This is not true. The pictures below show the non volumentric ones.
I changed all the non volumentric lights to static and baked. The baking process took an hour to complete, but the time I put into making UV maps were definitely worth the effort. The result were pleasing. The first baking try turned out to dark and the second too bright. For the second try I had just increased the Lumen Intensity of each static light in stead of playing with the Indirect Multiplier, since I think that does not do much.
Default scene
Baked Lighting (result too dark)
Baked Lighting (result too bright)
When you use Occlusion Culling, Unity divides the scene into cells and generates the data that is within view of the player. Since I gallantly took good care of the rocks in maya, to be ready for Occlussion Mapping, the rest of this process was easy. I only had to bake all the static meshes into the occlusion culling renderer. At runtime, Unity loads this baked data into the memory. This solution could have a great positive effect on the FPS, but it eats memory. Therefore it could be possible to lose performance by enabling Occlusion Culling, in stead of gaining.
Sadly my whole experiment with lightbaking and occlusion culling gave no positive result in the stats and profiler view. The FPS stays the same and I have way more draw calls. This last part probably has to do with the seperation of the rocks. The weirdest part of all is the identical result of the vertices, which should have dropped a lot since I have been retopologizing the rocks and floor. My teachers tell me its most likely due to a Unity bug.
FPS before balancing around 70
FPS after balancing around 70
Draw Calls before 50
Draw Calls after 150
Verts before 12.9 K
Verts after 12.9 K
Apart from the the unchanged result I managed to bake lights into lightmaps for the first time. Also Occlusion Culling worked out well. But concluding that all of this did not help with getting a better performance, what else was left from the analysis? I think my amount of shaders actually could also be a huge bottleneck for the performance as well and I still have too many unnecessary copies materials. There is no reason to keep three copies of shaders with just a little tweak to creat variety. I have learned all of this now to take in account for the future.
Light Realtime, Mixed and Baked: https://docs.unity3d.com/Manual/LightMode-Mixed.html
Lightbaking tutorial from my teacher: https://www.youtube.com/watch?v=-ucP-Rt1E1o&feature=emb_logo
Occulsion Culling Unity manual: https://docs.unity3d.com/Manual/OcclusionCulling.html