Original link
Unity is becoming more and more popular among some of the best game developers. This should be attributed to Unity's direct support for multiple platforms, such as mobile phones, desktops, and host environments. In addition, it is free to use for low-income developers and studios.
Unity supports a variety of technologies and components, some of which are lighting and lighting technologies. In unity, you can illuminate a scene by simulating the light's complex behavior or by using a simple lighting model.
This tutorial will focus on how the lighting system works in Unity 5, lighting types and features, and how to use them to create rich lighting effects.
Preparatory work
First, make sure you're using the latest version of unity. In this tutorial, the Unity version number we used is 5.5.0f3. Make sure you are using the latest version of unity, or you may encounter problems in the following tutorials and in the use of physical connections.
Next, please download the Lightinginunity5-starter file. Unzip and open the project in unity. The example scenario should be open automatically, and if not, you can open it from the assets folder.
Direct and indirect light sources
In real-world scenarios, there are two types of lighting effects: direct and indirect light. Direct light source, as the name implies, is the light directly from a light source (light, sun or other). The indirect light source refers to the light coming from another object.
Now let's test and implement both of these effects.
In your scene, you can already see that the direct light is working. Perhaps you have noticed that there is already a directional light in this scene, which we call directional light (directional source).
Directional light sources are mostly used in outdoor scenes with sunlight or moonlight. They affect the surface of all objects in the scene. At the same time, they are the least expensive for graphics processors.
Select the directional light item and view its properties in the Inspector panel. You'll notice several interesting attributes (such as type, color, and intensity). You can try modifying the contents of the color and rotation properties to see the effects of the changes in real time. By modifying the values of those attributes, you can visually adjust the directional light.
At this point, your 3D scene does not have any indirect lighting. You can view it by moving the sphere sphere, keeping it close to the green wall or red wall. You will find that the color of the sphere will not change.
One of the areas of use of indirect light sources is to apply them to static game objects. Keep in mind that the use of static game objects can improve the performance of your game rendering, but it also degrades its performance, so you have to find the right balance for your game.
Add a box-like object and set the mesh parameter to box (gameobject> 3D object > Cube) and place it next to the sphere, named Cube.
Select the cube and check the static property in the Inspector panel.
When you tick the static property, unity automatically creates a light map for the object and uses the appropriate lighting model. Now you can move the camera towards the cube and see how the indirect light works. You will see that the green (middle) or red is constantly spreading to this cube.
If you change the direction of directional light, you will see unity also automatically updating the illumination map.
The indirect light source used on the cube does not work on sphere, because sphere is not static. You can achieve the same effect by setting the sphere to static (Inspector > Static).
Now you can add and configure direct and indirect light sources for static objects. However, the 3D scene is composed of many dynamic objects. So how do we use these effects on these dynamic objects? In the next section, you will solve this problem.
Light detectors
When your scene contains non-static objects, you need to use special lighting techniques to illuminate them correctly so that they don't appear to be out of the picture.
With the use of light detectors and their placement, you can sample some of the interesting points in the scene. Each light detector can sample the specific area in which it is located, and then calculate the illumination information for that particular area. This part of the operation is very fast, so it can be used during the game run. The use of light detectors avoids the disconnection between the light of a dynamic object in the scene and the static illumination map object.
Sphere is a dynamic object, so, contrary to what it might expect to see, it is not illuminated correctly. If you turn off directional light--you will notice that the only light that affects the sphere is ambient light. In order to properly illuminate the sphere, you need to use a light detector.
To implement a lighting probe in one area of your scene, do the following component > Rendering > Light Probe Group. This creates a group of light detectors in the scene.
The next step is to place the light detectors in the group in the correct position. You can now place them in a position close to each corner of the box.
The best way to do this is to switch the angle of view to the orthographic orthogonal view (click in the upper right corner of the scene below the cube). Then, select each light detector node and drag it to each box corner (similar to the one below).
Repeat the process until you have all the probe nodes in the correct position.
Some scenarios require additional detectors to illuminate the object correctly. To add more probes, you can select a probe and then, under the Inspector panel, click the Duplicate Selected (copy selected) button.
After copying, you need to place the new node in the correct location (the copied node will be generated at the same location as the probe node being selected).
If you look more closely at the interface in the Inspector panel, you'll notice that you can also add a standalone probe (add Probe), delete the probe (delete Selected), or select all the probes in the group (select All).
To observe the operation of the light detector, select sphere and add a rigidbody component (add Component > Rigidbody) above. Then, assign a material to its collision detector. You can use the rubber material.
Now place the sphere near the top of the box and press the play button. Now you can see the sphere the right light. To observe the difference, disable the light detector, and once again press the play button to observe.
Point Light
Point Light is a common light in the game, and they are often used as an explosive source and bulb. Because they emit light in all directions, they consume more evenly on the graphics processor. However, when using a point light source for shadow calculations, the cost of consumption is higher.
Select the Gameobject > Light > Spot lights to add a point lighting. Then, place the point light source in a position near the top of the box.
Select the point light source to observe the attribute parameters in its Inspector panel.
The first parameter is type. Here you can set the type of lighting you want to use. You can choose Spot (Spotlight), directional (directional light), point (spot light), or area (region light). Each of these types provides a specific lighting effect. You can select any of these options and observe the lighting effects in real time. However, only the point light option is used in this part of the tutorial. This creates a light bulb effect (the rays are uniformly irradiated in all directions).
The second parameter is baking (bake). You can set it to realtime, baked, or mixed (real-time, baked, or mixed). Leave this value as the default value. The range parameter specifies the maximum distance the light is emitted outward from the center of Point Light. The color parameter specifies the colour of the emitted light.
The intensity parameter specifies the luminance value of the light, Bounce intensity is the indirect light intensity multiplier. Shadow type determines the Shadow property and shadow type. You can set it to one of no Shadows (no shadows), Hard Shadows (stiff shadows), and soft Shadows (soft shadows). Keep in mind that the point light shadows are the most expensive for the engine, so think more when selecting this option.
If you choose hard Shadows or soft Shadows (soft shadows), you'll see a shadow effect created by the sphere and point lights. When you try to adjust the strength intensity value, the shadow also weakens or strengthens. The resolution resolution parameter sets the degree of granularity of the shadow. Finally, the-bias and normal bias parameters, which are used to set the offset of the pixel position of the light space against the shadow map value.
A cookie is an optional parameter that represents the alpha channel texture that is used as a mask to determine the different brightness of light in different locations. Since this is a point light, the texture map used must be a cube map.
The Drawhalo option is used only to render a halo effect around the light source. The flare option specifies a reference to the glow to be rendered at the light source location. The flare and draw Halo options are useful when you are debugging a 3D scene and the bottlenecks you might encounter.
The Rendermode rendering mode option defines how important the renderer is when rendering the scene. The heavier the degree, the more intense the rendering will be. The Render mode can be set to Auto (auto), Important (important), or non-important (not important) of the three. Finally, culling mask is used to select or reject groups of objects affected by the point light.
Now that you understand all the properties of the point light, let's discuss the direct and indirect illumination when using the point light. When you develop a game that is primarily characterized by lighting and lighting effects, complex lighting scenarios can lead to longer load times and fps frame rate bottlenecks, while also consuming more CPUs. Therefore, it is recommended that you use the shadows type and baking properties to balance your scene performance.
For example, if you set the baking (bake) property to Realtime (real-time), set the shadow type (shadow Type) property to Hard Shadows (a stiff shadow) or soft Shadows (soft shadow), Then there will be a very good and true shadow effect between sphere and box. However, if you have a lot of lights in your scene, this setting consumes too much CPU resources.
How to solve this problem? You can set the baking parameter to bake first. Once you do this, unity will automatically create a light map for this light source, which will give you a performance boost. However, this performance boost also has its own cost: Now you can't get a shadow effect that is projected into a dynamic object like sphere through a point light.
It is a best practice to analyze each light source separately and then process it accordingly. For example, in this scenario, choosing realtime Baking (real-time baking) and hard-Shadows (stiff shadows) will be more reasonable because only one light source is placed inside the box.
However, if your light source is a torch on the wall, setting the baking option to bake will make it a little better for unity to generate a light map.
To summarize, whichever approach you use depends on the developer's management of game quality and performance. So remember to keep a balance in mind, especially when you're developing on a mobile device.
Spotlight
Spotlight refers to the emission of light from a light source toward a specific area. They only illuminate the object in this particular area, which is limited to a three-dimensional cone area. Basically, they work similar to the headlights of a car. As you can imagine, they are ideal for flashlights, car headlights or light poles. For graphics processors, they are also the type of light source that consumes the most resources.
Now let's adjust the point-light parameter to spotlight. Select the point light that was created earlier, and adjust its type parameter to spot (Spotlight). Next, rotate the light source so it can illuminate the box's floor. and rename it to spot light.
As you may have noticed, the spot spotlight's parameters are very similar to the point light source parameters within the Inspector panel. However, here comes a new parameter, spot Angle.
The Spotangle parameter determines the spot angle of the light cone.
For direct and indirect lighting, the spotlight works much like a point light. They have the same limitations and advantages. Therefore, be careful when setting the balance of light in your game project.
Note that in order to strike a balance in performance and performance, you can always do this by adjusting the shadows and baking.
Area Light
An area is a light emitted in all directions on one side of a rectangular area plane. This rectangle is qualified by the width and height of the two attribute parameters. Area light can only be used for light map baking, which means that they do not affect objects during operation.
Select Spot Light, adjust its type parameter to area, and name area light. Then, place the light in the box, and in the Inspector panel, modify the width and height parameters to ensure that it covers the entire area inside the box box.
Looking at the area light related parameters, you'll notice that most of the parameters are similar to those of the previous lighting parameters, such as type, Draw Halo, Flare, Rendermode, and culling Mask.
In fact, the new parameter is width and height. Both of these parameters are used to set the rectangular size of the area light.
If you press the play button, you will see the area light projecting light into all objects within its range. The size of the area light rectangle is determined by the width and Height properties. The orientation of the projected light is the normal direction of the plane, which is consistent with the direction of the positive Z axis of the light. The light is emitted from the entire rectangular surface. Therefore, the shadow of the object affected by the area light is softer than the point or parallel light source.
Light calculation of area light consumes processor resources very much, so they cannot be used during operation and can only be used for light map baking.
Summarize
Summarize the above guidance on lighting systems in Unity 5. Several lighting effects and related configuration information are mainly studied. With this knowledge, you can now flexibly use multiple lighting effects in your gaming projects or applications.
Unity has an active ecosystem and there are many other products that can be used to help you build your project. At the same time, the platform's features help to improve your skills, which makes it a great choice. Either way, you can see everything we left behind in the Envato market.
If you have further questions or comments, feel free to leave a comment in the comments section as usual.
Unity 5: Lighting system