Unity_ Lighting System
Illumination system is also called lighting system;
In the literal sense, the function of the illumination system is to bring light to our scene and illuminate the scene. A colorful game scene must be more attractive than a dark piece of the game scene, want to make the game scene become more beautiful, lighting system is essential.
There are two main components of the lighting system in unity5.x:
Light components (4 light components, 2 special function components) and Lighting panels.
Two types of:
- Real-time lighting: PC, host side operation, lighting effect is good, but the consumption of large resources.
- Baked Light: Mobile operation, lighting effect is good, consumes less resources.
Real-time illumination of illumination system
Real-time illumination is all called precomputed Realtime GI (pre-computed real-time global illumination);
GI full name is global illumination (overall illumination);
The unity5.x lighting system uses the real-time lighting type by default.
Illumination Conclusion:
- All the lights are really involved in the operation, can dynamically change any light (position, color, intensity ...), and with the change, the impact of lighting on the scene environment is also real-time.
- All of the scene environment models are also real engagement operations, and these scene models are also real influenced by various light sources.
- Conclusion: The effect of light source is real and the environment is influenced by light source.
Lighting Panel Related settings:
- Ambient GI: Shows the mode of the current lighting system (real-time or baked).
- The role of Auto check box: By default, it means that a new model is added to the scene, which changes the position of the original model, and the scene light is automatically calculated. When the resource model in the scene is small, it can be checked, but if the scene is very complicated, it is necessary to cancel the Auto tick state, otherwise you adjust the model in the scene every time, it is very time-consuming to build again.
- The Build button functions: Scene real-time lighting, baked light-related lighting data "construction generation". The previous auto option is to control the related data, whether it is generated automatically or manually.
Baked Light In light system
Baked light is all called Baked GI (baked global illumination);
Baked light is characterized by baking the light source information in the scene into a "light map", using these maps to store the light, and then the engine will automatically match these "light maps" to the scene model, after baking the light map, in the game during the operation of the scene lights will not really participate in real-time operation. Baking lighting is less demanding than real-time lighting, which is more suitable for mobile devices such as mobile phones (real-time operation of light components, especially hardware performance). Now on the mobile side, specifically Android devices. Over 90% of the illumination above the MMORPG scene is used for baking light.
Baking steps:
- The Lighting panel selects the lighting system mode to use and cancels the Auto selection state.
- All light sources that participate in baking, the baking option in their own light assembly, are set to Baked. The default is Realtime, which is selected and set according to the mode of the lighting system to be used in the current scene.
- All of the scene model objects that are involved in baking are set to static, and when they are set, they become stationary objects that cannot be changed after the scene has been run.
- Once you have completed the previous operation, you can click the "Build" button below the Lighting panel to create a baking light map.
Light Map: Stores the light information in the scene, and when "Build" is complete, it appears as a resource in the Project Project catalog, in the same directory as the current scene, and generates a folder with the same name as the scene, storing the related lighting map.
Baking Light Step details
- Lighting panel selection mode for Baked GI;
- The relevant light is set to Baked;
- The related model is set to static;
Why are scene models static?
Because only the static model can participate in baking rendering, the baking rendering is to generate a light map. The resulting light map and scene model correspond to one by one. The map is fixed, if your model is non-static, it means that the model can be moved, the model moved, the light map is biased. To avoid this situation, the Unity engine allows only static models to participate in the lighting baking process.
Baking Lighting Key parameters
- Baked Resolution [key adjustment parameters]
Baking Resolution: Actually the resolution of the generated light map. The larger the value, the better the effect, the larger the volume, the longer the baking time, and vice versa. This parameter is the most affecting baking time.
Generally in the development phase, do not set too high, otherwise it will take a long time to render the light map.
Phase test, when the final release, set a higher point, rendering an optimal effect.
Baking pitch: Controls the amount of space between the baked light map and the mapping element information. No practical meaning, keep the default of 2.
Compression: Compresses the baked map, which is approximately multiple times the compression ratio. Significant, keeping the default tick status.
- Ambient occlusion [Choose whether to open according to the actual situation]
AO map effect: The effect is similar to the AO map inside the standard shader and is used to optimize the shadow and corner parts of the model.
Atlas Size: The maximum size of a single light map.
Lighting system Light probe Group baking light after the problem
When using Unity to develop mobile platform applications (games, Vr,ar), in order to protect the application's operating frame rate, we generally bake the "real-time" light that consumes the most resources in the scene as a "light map." The light map preserves the lighting effects of all static objects in the scene, but non-static objects in the scene, such as game characters, NPCs, and these dynamic characters, do not appear to have a light effect on them. So how to solve this problem??
In response to this, Unity has introduced a component that specifically addresses the issue: "Light Probe Group": Lighting probe set.
Light probe Set
Component function:
Using the light Probe group component, we can simulate the effects of real-time lighting in a baked scene.
Component Use steps:
- Light-to-light Probe Group add components;
- Click the Edit button on the component to add a new "probe" under orthographic view and adjust the position.
Component considerations
Put "probe" to make the probe a "volume", our character moves throughout the space, regardless of moving anywhere, is in a "volume", that is, triggering 4 probes.
Principle Analysis of components
Place N light probes in space into a volume state. The light maps are then baked, and the light probes are baked while the light map is baked, which records the light information at the current location. Then, when our non-static role model enters the range of the probe, the character model automatically acquires the illumination information recorded on the probe around it and, after interpolation, simulates the effect of the real light on the character model.
Auxiliary Baking Light Source
Area Light Components
Area light: regional lights [Component].
Area light is not valid in live light mode and is only useful in baked light mode.
Model Spontaneous Light:
The self-illumination option on the standard shader also allows the model to become an auxiliary baking light source.
Precautions:
- Spontaneous light objects in baking mode also need to be set to static.
- The larger the value after emission, the greater the self-luminous intensity.
Reflective probe for baking reflex probe in light system
Reflection Probe: Reflective probe assembly.
The reflection probe is used to simulate the reflection effect in the scene. Some of the high-reflective objects in the scene, such as very smooth, bright metals, glass, plastic, and so on, can reflect the surrounding environment, such as the test results in our previous course. These objects reflect what is shown, and are determined by the reflection probe; in Unity's new scene, there is a reflection probe by default.
Creation of reflective probes
Light-->Reflection Probe //创建一个新的反射探头
Component analysis:
- Reflective probe This component consists of a "cube space" and a "reflection probe";
- Reflective probe with Lighting panel, also in real-time mode and baking mode;
- The size of the cube can be adjusted, the position of the reflective probe can also be adjusted;
- If the type of the reflective probe is set to Baked, the reflection probe will only reflect the surrounding static object.
- All models in the cube space, as long as their degree of smoothness of the metal is relatively high, there will be a reflection effect, the reflection is actually taken from the reflection probe data;
- The reflection probe that exists by default in the environment is infinitely large, and the sky box is completely overlapping;
- The reflective probe can be baked separately.
Reflection Probe Parameters
- type[Type]: Sets whether the current reflection probe is a baking type or a live type.
- box projection[box Model projection]: a key parameter, but currently not easy to test, follow-up cases focused on the demonstration.
- Box size[Space Size]: Sets the dimensions of the cube space.
- Box offset[Space Offset]: Sets the overall offset of the cube space.
- resolution[resolution]: The baked reflection probe will actually output a map to our project, the resolution is to set the resolution of this map, the higher the resolution, the clearer the reflection effect, and vice versa.
- Clipping planes[Clipping surface (reflection range)]: The reflective probe reflects the object within that range.
The use of real-time reflective probes in light systems
- Uncheck the Baked GI in the Lighting panel;
- Create a Reflection Probe in the scene with the type set to Realtime;
- Create model objects and characters that participate in reflection;
- Adjusting the component properties of the real-time reflective probe;
Refresh mode[Refreshed mode]
The code implements location synchronization, synchronizing the position of the role to the real-time reflection probe.
This work is licensed by Star Meteor Chen using the Creative Commons Attribution-NonCommercial 4.0 International license Agreement.
Introduction to the Unity lighting system