Lighting - SkaterXLModding/skater-xl-mapping-wiki GitHub Wiki

This is a temporary hold over until I can spend some real time doing a proper lighting guide.

Before getting started, lets very quickly discuss baked vs realtime lighting. Realtime lighting is exactly what it sounds like, lighting calculations are done in realtime in the game. So as you skate around, lighting is being calculated all around you. Realtime lights biggest drawback is performance. Due to the fact that the calculations are being run as you play, they impact performance very heavily, and even half a dozen realtime lights in a scene can hit, especially lower end machines, gameplay pretty hard. Baked lighting is where lighting is calculated before hand, in the Unity editor, and that data is stored in assets that are bundled with the scene. Baked lighting comes with the large advantage of calculating indirect light bounces. Indirect lighting is the light that bounces from a surface with reduced intensity. Think about a shadow beneath an umbrella at the beach. The shadow is not pitch black, there is still light bouncing in underneath the umbrella despite it blocking the direct rays of the sun. We use baked lighting to calculate such bounced lighting. If you notice your skater has very harsh wet looking shadows in game, its due to a lack of indirect lighting in the shadows. Baked lighting information is stored in lightmaps. These are 2D textures that represent the light levels on objects. The primary disadvantage is that it can not be used to bake lighting to dynamic objects. In our case, the skater is our issue here. You cant bake a 2d texture of the skaters lighting because they will be lit differently in various parts of the scene. So what we use is a combination of realtime lighting and lightprobes to effectively light the skater. Lightprobes are something we can scatter through the scene in places where the lighting changes. These probes are baked with lighting, store the information, and then pass that lighting to the dynamic object in real time. The downside of light probes is that they dont calculate every intricacy of lighting on our dynamic object. The dynamic object just gets one light probe value to the whole thing, so this can result in what is called ringing, or a visual of the object having a slight glowing halo in shadows. But if we use all these techniques in conjunction, we can get a very convincing and high fidelity lighting effect with minimal issues.

NOTE/WARNING: It is highly recommended to practice lighting in a scene like what I am using, which I created using ProBuilder in Unity. Simple scenes bake faster and allow for you to tweak settings and adjust things without waiting 2 hours between bakes. It is also highly recommended to backup your scene before doing lighting stuff on it, as it is very easy to make a mistake that can take hours to undo.

This is a scene with essentially default lighting. Your project most likely looks somewhat similar. Basically just a scene with a basic sky and fog volume and no light work done.

![image](https://user-images.githubusercontent.com/65366947/89695916-9bf8f900-d8ca-11ea-93b2-2bb7c946b938.png

The first step we must take is to make sure our objects have lightmaps. Baked Lightmaps bake to the UV2 slot of objects, and realtime Lightmaps go on the UV1 slot. Your normal 2D texture work is usually on the UV0 slot. Although you can create your own lightmaps in your modelling software, we are just going to let Unity handle it in this case.

Select the objects you will want to bake lighting to in the project panel. Keep in mind that for our purposes, we will want to bake lighting to basically everything. You can leave small props like trashcans as dynamic objects if you'd like, but the bulk model of your park should be a static object set. In the inspector, we will see the objects import settings. Check the Generate Lightmap UVs box.

image

This will automatically generate acceptable light maps for your 3D model. Next step is to set the meshes as static in the scene. As you can see in the example image below, I have all the meshes I will have marked as static organized into one parent empty. This is not required by any means, but helps with organization and ease of use. Once you have the desired objects selected, find the static drop down in the top right of the inspector, and check Everything

Note: You don't technically have to check anything other than Contribute GI as static for lightmapping, but might as well just do everything most of the time, for our purposes, except in specific corner cases

image

Lets next take a look at the lights in the scene. For this specific example I'm just lighting a basic outdoor scene, but we will talk a little bit about night and indoor lighting further on. Outdoor scenes are by far the most simple.

Firstly, we have a Directional Light set to Mixed. Mixed can mean a few different things depending on the lightmapping mode, but in simple terms it is a light that has both realtime and baked light properties. Keep in mind still, that mixed lights still have the performance hit of realtime lights.

image

These light settings are a decent baseline, but everybody's scene is different. Don't be afraid to tweak values and mess with stuff

Secondly is our scene settings volume. The important things to note here are: Some type of sky (Physically Based in this case, but any works), a Visual Environment, Exposure, and Indirect Lighting Controller.

Again, these are just baseline settings and values, experiment for yourself to achieve the look you want

image

Our next step, and final in this case, is to set up light probes. This step is tedious, but very important for lighting the skater effectively. In the hierarchy, right click and create Light > Light Probe Group

This will spawn something that looks like some yellow dots connected by pink lines in the scene. The yellow dots are individual probes, while the lines are indicating the connection of the probes and where dynamic objects will connect with the probes. These dots are what store the lighting info, then when a dynamic object crosses the pink line, the 3 nearest probes transfer the data to that dynamic object (yes this is a super simplified explanation, go fucking google them if you want to know more). Click the Edit Light Probes button, and now you can move the probes around with the 3d scene move tool.

Place probes around the map in places where the lighting changes, such as shadow transitions, locations with spotlights, and any other area where the skater will undergo a change in lighting. Use Ctrl + D with probes selected to duplicate and create more. I personally like to have a probe at ground level, and another just above the top of the skater. It can be useful to have a third probe just above the ground probe, to help light the skateboard.

image

Once set up, its time to bake lighting. Open your lighting settings tab by going Window > Rendering > Lighting Settings

Make sure to have the profile set to your active scene settings volume, and the Static Lighting Sky set to the sky type you are using. I have Realtime Global Illumination disabled in this case, due to the way ProBuilder does its lightmaps. You can keep it enabled, but if you get very bizarre light map artifacting in game (but things look fine in game), disable it. You can basically just leave things at default, or copy what I have here. Something important to note is the Lightmap Resolution setting, that is set to 5 in this example. It is suggested to use a low value (0.1-5 depending on the size of the bake) to quickly bake a preliminary pass, then up the values for passes closer to final, and then go up to 60-40 depending on the fidelity you are looking for for the absolute final pass. Now hit Generate Lighting, wait for it to finish, and check out your work in game!

image

I'll do more on this guide later, gotta play Genital Jousting sorry.