Global lighting Technology in Unity 5 (reproduced)

Source: Internet
Author: User
Tags comparison table emit ranges unity 5

Original link

This article is organized from the Unity Global Official website, Original: Unity 5-lighting and RENDERING

(The article is longer, please read patiently)
Brief introduction
Global illumination, referred to as GI, is an algorithm used to simulate the interaction and rebound of light, and to accurately simulate the global illumination is very challenging and costly, because of this, the modern game will be a certain degree of pre-processing these calculations, rather than real-time operation of the game execution.

In the same scene: no illumination (left), only direct light (medium), and global illumination (right) with indirect light sources, notice how the Color "bounces" the light on different surfaces to produce more realistic results.

In this article, we'll describe how global lighting works in unity, leading you through different lighting techniques to explain how to set up lighting in your project and think about how to help the scene through a variety of tools.

Select a lighting project

Broadly speaking, Unity's global illumination is "real-time" or "pre-calculated", and in some cases two methods can be used together to illuminate a more realistic scenario. In this section we will make a brief description of the difference and timing of the two technologies.

Real-time Illumination (REALTIME LIGHTING)

By default, Unity's light sources (direct lights, projection lights, point lights) are real-time, representing the lights that illuminate the scene and update at every frame, as the light source is an object that can be moved within the scene, the scene lights are updated in real time, and you can see the changes in the game window and Scene window.

Effects of real-time illumination: Notice that the shadow is completely black because there is no reflection light, only the surface of the object within the projection cone range has a light source effect.

Real-time lighting is the most basic way to illuminate objects in a scene, to illuminate characters and moving objects, but unfortunately, the light in unity real-time lighting does not reflect, so we import the global lighting system, enabling pre-computed technology, is to show a more realistic scene.

Bake global illumination (Bakedgi LIGHTING)

When baking a light map (lightmap), a static object in the scene calculates a map result based on the effect of the light and iterates over the scene object to establish the illumination effect:

Left: A simple light map scene result, right: a light map generated by unity (shadow and light source information are included in the calculation)

These "light maps" can contain direct light sources that are projected onto the surface of a scene, as well as "indirect light sources" that reflect between different objects, which can be used to describe surface information (Albedo) and Bump (Normals) information, such as color, through a shader (Shader) on an object's material.

The textures produced by baking light are not able to change operations at the time of the game's operation, so they are defined as static, although they can still continue to be computed on the layer map, but they are not interactive, and we usually use this illumination method to make the low-order cell phone run smoothly. Solve the problem of the performance of light in the game.

Precomputed Global Illumination (precomputed REALTIME GI LIGHTING)

Although traditional static illumination maps cannot change the scene lighting conditions while the game is executing, the pre-computed real-time global illumination system can help us to interact with complex scene light sources in real time, and in this way, we can build a dim environment with rich global illumination reflection and reflect the change of the light source in real time. Like a sundial, the position and color of the shadow will change as the light moves, which cannot be achieved in the original baking lighting system.

A case of a sundial presented in the GI

In order to achieve these effects at a reasonable frame rate, we need to do an "estimate" of a bunch of long-length digital data before real-time operations, and are expected to calculate the complex behavior of the light during the game, which can be computed at time-slot, which we call an "offline" operation.

How does it work?

The most common requirement is that we want indirect light sources to be included in the calculation of the scene illumination map, fortunately, the principle of these indirect light source is from the direct light source slowly changed from the color, only a small number of specific cases have a relatively large color change, such unity of global lighting estimates, the use of indirect light source diffuse ( Diffuse) attribute is advantageous to the operation. Usually good shadows are calculated from the instant light source instead of baking to the light map, assuming that we do not need to sample too complex details, which can greatly reduce the size of the data produced by global illumination.

It is important to simplify the entire process through precomputed calculations, effectively reducing the number of global lighting operations that would otherwise be calculated in real time in the game, if you want to change the light source color in the game, rotate the light source or adjust the intensity of the light, or even make changes to the scene surface. Unity samples The underlying map from the surface and defines the value of the color from a generalized definition to a large group, or "cluster", which produces a low-resolution, simulated static geometry that we can use to calculate light.

Left: When the scene display is set to "Albedo", you can clearly see the textures generated by Unity's pre-calculations; Right: Just like the game scene, instant lighting calculates the result and applies it to the scene.

Basically, when calculating global illumination, we do a "ray Trace" operation around a static scene, which is very inefficient and therefore cannot be demanding real-time operations, instead, unity uses trace tracking to calculate the cluster relationship of these surfaces-in the phase of the estimated "light transfer" and then string the world into a network structure , we no longer need a cost-effective ray tracing method in critical game processes.

We effectively create a simplified algorithm that can change the input structure during gameplay, which means that we can change the light source or surface color, and quickly see the effect of global illumination in the scene, and the resulting output light map is colored through the GPU and mixed with other lighting or surfaces, and then output to the screen.

Benefits and costs (benefits and COSTS)

While it is possible to use both baked GI and pre-computed GI, it is important to be aware that both systems are emulated at the same time, and the performance burden can be combined with two operations, not just because two sets of light maps are stored in the graphics card memory, and the shader has to pay two processing costs.

The final choice of which method depends on the nature of your project and the expected hardware considerations, such as the high performance and memory limitations on the mobile platform, baked GI method will be more suitable, if it is on a computer with a video card or game console execution, it may use the estimated real-time global illumination, or two simultaneous use is more feasible. Decide which method to use for your target platform, and remember that if the project meets several different hardware requirements at the same time, it is often considered with the most efficient platform.

Pre-computed processes (the precompute process)

In unity, is expected to be in the background, whether it is automatic process or manual activation, you can continue to edit your game object during the calculation, not affected, the estimated time will appear in the lower right corner of a progress bar, different algorithms will have different operational stages, the progress bar will also show the stage name and progress.

As can be seen from the above example, 11 work has progressed to the 5th, "cluster" and 108 pieces of work to be done before the 6th session, the Value status bar table is as follows:

Enable a precomputed (starting a precompute)

Only static objects are included in the GI estimate, so you must have at least one static object for the precomputed start, either by setting the object individually or by selecting multiple objects with SHIFT + from the hierarchy menu and modifying them one at a time.

From the Properties panel, select the static of the object, which will open all flags associated with the static object, including the navigation flag or the batch flag, which may not be what you want, as long as the "Lighting Static" flag is ticked for the expected calculation. More detailed control, just click on the property interface static to the right of the drop-down menu can be, in addition, from the window lighting interface can also specify the setting of static objects.

If your scene is set to Automatic (Lighting->scene->auto), Unity's estimate will start automatically, otherwise it will need to be performed manually using the following process.

Auto/manual precomputed (Auto/manualprecompute)

If the Lighting interface under Auto This option is checked (Lighting->scene->auto), then the estimate will automatically in the background to constantly change the static geometry of the scene output. But if this tick is not checked, you will need to click on the "Build" button next to Auto to start the estimate manually, which will be calculated in the same way, so that you can control the start time of the calculation. Manual start-up the estimate will re-evaluate and recalculate all the lighting and aspects of the scene, and if you wish to have selective calculations, you can choose from the drop-down menu next to "Build".

Using baked GI or precomputed gi (enablingbaked gi or precomputed REALTIME gi)

In the default case, both calculations are enabled in Unity (lighting->scene), because you can set which calculation method (inspector->light->baking) to use for individual light sources.

In a scene at the same time using two methods may be a burden on performance, the best way to use only one method at the same moment, to close any method can be removed from the GI interface (lighting->scene), do not use the method to cancel the tick can, only a tick algorithm will be calculated, Any related light settings will be overwritten.

Pre-lighting settings (pre-lightsettings)

The default baking mode for every light in unity is "Realtime", which means the lights still illuminate your scene, and Unity's precomputed GI system handles indirect light. However, if the default baking mode is "Baked", then these lights will process the direct and indirect light sources through Unity's baked GI system, and the resulting illumination map cannot be changed during execution once it is posted to the scene.

A point light that sets the baking mode to "Realtime"

If you choose the baking mode as "Mixed", the static objects in the scene will be calculated by baking gi, however, unlike the "Baked" mode, the mixed mode lights will continue to operate on the immediate light source to non-static objects, for you want to bake a static environment into a light map, But it is also helpful to hope that the same lamp can calculate shadows for the moving characters.

GI Pickup (GI cache)

Whether it's baking or precomputed, unity "caches" the lighting data from the scene to "GI Cache" and attempts to reuse the data to save time when it's calculated, and your changes to the scene will affect the amount of data re-use.

If you want to clear this cache from (Preference->gicache->clear Cache) to clear, after the purge means that all data must be re-calculated, because the time will take some time, in some cases you may need to reduce the size of the file space ( For example, to transfer the project to another computer) is helpful.

Scene settings (Scenesetup)

Select A Shaded path (choosing A RENDERING Path)

Unity supports a number of color techniques or "paths", and when you start a project, you have to set out a route, and the Unity preset is "Forward Rendering". In "Forwardrendering", each object is colored according to each affected object's light, through "Pass" to color, so it is possible that an object has been repeated several times, depending on the number of lights in the scope of the action.

The advantages of this approach are fast and low hardware requirements, in addition, this forward color provides a wide range of custom "shading models" that can quickly handle transparency, as well as hardware features such as multi-sample soft Edges (MSAA), and so on, some of which are not achievable on other paths, and have a significant impact on graphics quality.

However, his disadvantage is to pay for each lamp corresponding costs, that is, the more light the object is affected, the higher the cost of computing costs, some types of games will require a large number of light sources, it will be discouraged, and if you can manage the number of lights, then this path will be a very fast solution.

The "Deferred" path, which delays the masking and blending of light, until the position normals of the first received surface and the material data is colored to a "geometric buffer" (g-buffer) as a map of the screen space, and the result is synthesized, The advantage of this approach is that the color cost of lighting is proportional to the number of pixels, not the number of lights, so you don't have to control the number of scene lights, some game types will be a key advantage.

The "Deferred" path presents predictable performance characteristics, but usually requires a stronger hardware and a lower level of support for mobile platforms.

For more information on "Deferred", "Forward" or other paths, refer to here.

Select a color space (choosing a color spaces)

In addition to choosing a good color path, it is important to start with a "color space", which determines which algorithm is used to calculate the color mix when lighting or material is loaded, which can have a great impact on the realism of the game, but in most cases Color space settings that are too much exceeded may be constrained by the hardware of the target platform.

Recommended more close to the real color space is linear, you can find "color space" from playersetting inside to set (Edit->projectsetting->player)

The advantage of setting the linear is that the color provided to the shader in the scene will be brighter because of the light intensity increase, and if you change to "Gamma" color space, the brightness will be converted to white as a reference, which will not be conducive to the quality of the image.

Using the linear and gamma color space of the image comparison table, you can notice that when switching to gamma color quickly replaced by white as the light intensity of the benchmark.

Linear Another benefit is that the shader can sample the map without gamma compensation, which helps ensure that the color quality remains consistent through the color pipeline, improves color and calculation accuracy, and the output of the final screen is more realistic. Unfortunately, linear color space some mobile phone platforms and even some game consoles do not support, it should be said that the PC or some new mobile phone hardware and the next generation console will support the linear color space, in this case, you have to use a gamma method instead.

It is important to confirm what your target platform is before choosing the right color space, and to learn more about color space, see here.

High dynamic Range (HDR)

Like the color space, the dynamic range of the camera needs to be specified, essentially, it is used to define the brightest and darkest range of colors that the camera intercepts, and to enable HDR to tick the HDR items from the camera assembly, be aware that some phone hardware does not support HDR, When the color path is forwardrendering and the MSAA soft edge is enabled, the HDR,HDR and linear color spaces are not supported together and are best suited to maintain accuracy when dealing with very bright colors.

By default, Unity uses a low dynamic range (LDR), the color will be 8 bits per channel to store three primary colors (red, green and blue), 8 bits of the exact meaning is a combination of 8 0 or 1 number of values, there will be 256 combinations, three channels of x256 X 256 can be combined with 16 million color harvesting to express the gray scale from black to white in different layers.

In the real world, colors go well beyond the 16 million levels, and the colors and brightness are arranged far beyond what our human eyes can recognize, and unity is able to handle colors beyond these ranges and output colors higher than the LDR device support to provide high-quality results like computer graphics. Although there are still a lot of restrictions on the output, these numbers can still be used in many applications. When HDR is enabled, more accurate color data (denoted by floating-point arithmetic) is stored, which can handle more bright color ranges.

HDR allows us to maintain two large differences in brightness on the same screen, such as the shaded area of the scene and the light outside, we can also create a "halo" or glow effect in the environment scene, through these effects or visual lighting effects can increase the realism of the picture, but also carefully handle these effects to prevent them from overexposure.

Tone Mapping (tonemapping)

In the case of photography, if we use different exposures to shoot our scene, we can first observe which colors are lost due to overexposure, light tones in very bright areas may be covered by white, dark tones may be covered by black, which is like the "tonal image" of computer graph, when the color in the display device (such as a computer screen), the algorithm will correct the color to the device reasonable color and the screen, when the camera enabled HDR, it is recommended that the camera join tonemapping this program (assets->importpackage->effects) , this program can help you convert the color of the control out of range into a reasonable color.

More data on tonal images can be viewed here.

Ambient light (ambientlighting)

The scene of a lighting the overall environment is very important is "ambient light", can be said to affect the scene light is the most comprehensive element, ambient light is very useful, depending on the style you choose, such as the cartoon style of the shadow is unclear or the light is hand-painted style, Ambient light is also ideal when you don't want to adjust the light in the scene individually but want to increase the overall scene brightness. Ambient light does not calculate accurate physical occlusion when no Unity 5 global illumination is used, but if any kind of GI is turned on, ambient light from the skybox can be calculated as occlusion and the result will be more realistic.

Under the same scene, there is no light on the left side of the scene, the right is opened the ambient light, you can notice the intensity of the ambient light to adjust the brightness of the sky box has not changed.

By setting the object as a static object to enable the scene of global illumination, you can notice that the light is obscured on different surfaces.

The advantage of using ambient light is low efficiency, so as long as the number of lights on the mobile platform can be well controlled, you can find the Environmentlighting setting area (window->lighting) from the Lighting window ( Lighting->scene), change ambient source to change the source of ambient light.

The default value of Ambient source is "Skybox", which is a default Sky box created by the Unity 5 system, with a blue-toned ambient light, and some setting with a solid and gradient color on the half-sphere. It is important to note that changing the ambientsource inside the lighting will not change the color of the skybox, but will affect the ambient light exposure in the scene.

Reflection Source (Reflectionsource)

By default, objects in the scene are colored using the unity built-in standard shader (Standardshader), which is a physics-based shader (PBS), It simulates how light in the real world behaves as a material by imitating the physical properties of the real world, such as reflection or energy transfer.

When using a standard shader, each material has some degree of specular (specularity) and metal Reflection (metalness) properties, and in the absence of powerful hardware to handle the time-tracking reflection, we have to rely on pre-computed color reflections, We used a square-Cubemap that consisted of six pictures depicting the sky, or a reflection probe (Reflection Probe) from Unity 5 used to collect environmental information from a fixed point to produce the desired decal, It then mixes operations with other light and surface information to simulate the reflection that we see in the real world.

In the case of presets, higher specular and metalness will reflect the sky box more clearly, and the source of the reflection can be adjusted from the setting.

Objects in the scene reflect the contents of the Sky box by default, but you can find the Reflectionsource property from the lighting interface to change the source, specify a new square map, or specify a reflection probe to define.

Reflective Probe (Reflectionprobes)

The Sky box information may not contain all the scene objects, in many cases, objects can be obscured when collecting reflective information from the sky, such as indoor objects or objects in buildings like bridges or tunnels, in order to accurately reflect these objects, we must use reflective probes for these objects to sample, This probe samples the surroundings from their positions and writes the results to square thoughtfulness, allowing the surrounding objects to get a reflective image of the environment. You can add a reflection probe through the gameobject->light->reflection probe, and the position of the reflective probe will determine the content of the sample, and what the reflection looks like, generally speaking, the less reflective probe based on effectiveness, the better, keep in mind , the reflection probe is not used to get the exact result of physics, but rather to give the game world a better reflection, and in most cases a few well-arranged reflective probes are sufficient.

Left: The scene has only the preset reflection setting right: The scene adds the result after the reflection probe

In the properties panel of the reflective probe we can set the type to be real-time (Realtime), bake (Baked) or custom, it should be understood that the real-time reflection of the setting of the performance is extremely unfavorable, every one more real-time reflection probe will be more than six additional color operation, Therefore, the display of real-time reflective probe should have a clear demand, such as the reflection will be flashing neon, otherwise it is generally recommended to be baked enough, the performance will be much better.

It is important to note that only objects marked "Reflectionprobe static" will be sampled by the reflection probe, from the drop-down of the static object (static) on the attribute interface, and conversely, the real-time reflection probe will sample all visible objects unless you are masking (mask ) menu to exclude it.

Illuminate a scene (Lightinga scene)

We've covered some of the things you need to consider before you start working on scene lighting in unity, and hopefully you've got a direction for the target platform (the platform uses baked GI and gamma color space, the PC or game console uses real-time GI and linear color space), Let's take a look at some of the tools that help to develop light sources.

Directional light source (directionallights)

"Directional light" is ideal for simulating sunlight, its characteristics are like a sun, directional light energy from the infinite distance from the projection of light source to the scene, the light emitted from the directional lights are parallel to each other, and will not be like other types of light will diverge, the result is no matter how far away from the directional light source, the projected shadow looks the same This is actually good for lighting in outdoor scenes.

Directional light does not have a real light source coordinate, and placing it anywhere in the scene will not affect the effect of light, only the rotation will affect the result of directional light exposure. Other light types that have light coordinates, such as a projection light (spotlights), can change the character's shadow because it is close to or away from the light source, which may be a problem in illuminating the indoor environment, in general, by avoiding the role being too close to the invisible light source, we will create a bright spot to pretend the light source.

Use directional light regardless of distance, no matter how far it will affect the scene all the surface (unless removed), when using the delay (Deferred) color path will cause some performance loss, it is important to note that when using this color path, the efficiency of light and the number of pixels he affects is proportional to the However, although the consumption of efficiency, at least the result is more uniform, it is easier to adjust the balance.

In the default case, the new scene will be accompanied by a directional light, and in Unity 5 will also be associated with the Sky Box System (Lighting->scene->skybox), you can also delete the preset directional light and create a new light source, and then from the sun This property is re-specified ( Lighting->scene->sun)

The rotation of the preset directional light will cause the sky box is also updated, if the angle of light and the ground parallel can make the sunset effect, the light source to the sky resulting in black can make the night effect, from the top down will simulate the effect of the day. If the Sky box is designated as an ambient light source (Ambient source), then the color of the sky box will affect the objects inside the environment.

Point Light (dot LIGHTS)

The point light can be imagined as a point in a 3D space that emits light in all directions, and is ideal for making a light bulb, a weapon glowing, or an explosive effect emitted from an object, and the brightness of the light source is reduced from the center strongest until the range attribute (range) is set to 0, and the intensity of the light is inversely proportional to the distance , this is called the "Inverse square law", similar to the behavior of light in the real world.

The point light shines from its position to all directions, and the small spherical icon represents the "range" of the light, which is "attenuated" to 0 when the light reaches this range, but the projection continues if there is an indirect light or reflected light.

The point light to turn on the shadow operation is very inefficient, it must be used with caution, the shadow of the point light source in order to give six different world directions will be calculated six times, in the relatively poor hardware to turn on this function will cause a greater performance burden.

When adding point lights to the scene, it is important to note that they do not currently support shadow indirect reflection, which represents the light generated by the point light, as long as it is possible to reflect through the object to the other side in the distance, which may lead to a wall or floor "light leakage", so place the point lights to pay extra attention, but if the use of GI words, there will be no such problems arise.

Spotlight (Spotlights)

The spotlight casts a cone in front of his z-axis, and the width of the cone is controlled by the projection angle (Spot Angle) property, which slowly decays from the source to the set range to 0, while the closer to the cone edge will decay, increasing the value of the projection angle to make the cone wider, while also making the edge fade more aggressive. , this phenomenology is called "Penumbra".

Spotlights have many uses, they can be used to simulate street lights, wall lamps, or many creative uses, such as analog flashlight, because the projection area can be precisely controlled, so it is suitable for simulating the role of the light or simulated stage lighting effects and so on. As the light decreases as it gets farther from the source, it can be noted that the light will become weaker because it is closer to the edge of the cone, which we call the Penumbra area, which is more pronounced because the cone angle becomes larger. As with point lights, when using precomputed gi, the spotlight does not support indirect light shading, which means that the light passes through the geometry affecting the other side, so placing the projector light is a special concern.

Zone Light (area LIGHTS)

Area light can be used as a photographic soft light, in unity they are defined as a single-sided to the z-axis to emit light of the rectangle, currently only with the baking GI, the area light will be evenly illuminated the area, although the area of light does not have a range of properties can be adjusted, but the intensity of light will be as far away from the light source

Area light illuminates the surface and produces diffuse reflections and soft shadows in the interval

Area light is useful in establishing a soft lighting effect, where light travels through the surface of the light in any direction, causing refraction in different directions-resulting in diffuse reflection on the object, a common use as a ceiling wall lamp or a backlight, in order to achieve this function, we must emit a certain amount of light from each light map pixel, With the back of the area light to determine the visibility of the light, which means that the calculation of the area light is very expensive, and will prolong the baking time, but if used properly can increase the depth of the scene light, then the consumption is worth it, it is worth noting that area light can only be used in baking, so it does not affect game performance.

luminescent material (emissive materials)

Although the zone light does not support real-time gi,unity provides another soft light effect called a glowing material (emissive materials), like the area light, the luminous material can make the surface of the object glow, they can reflect in the scene like color or light intensity, etc. can be changed in the game light source, Self-illumination (emission) is a property within the standard shader, which allows a static object to become a luminous body, with a default of 0, which means that the material is specified without any spontaneous light reaction, and the HDR color selector can specify the glow color. The intensity can be adjusted in the range of 0-1 to establish the effect of similar area light.

The glowing material does not have a range attribute, but the light emitted from the material is decremented at two of the time, and the self-luminous material only acts on objects marked as "Static" or "lightmapstatic", and, similarly, If a glowing material is attached to a non-static object or a dynamic object like a character, it does not have any effect.

However, the material setting as long as the emission value is greater than 0, even if they do not receive the scene light will also have a light effect on the screen, this effect can also be emission under the properties of the "Global illumination" to "None", Self-luminous materials like this are ideal for simulating similar light sources such as neon lights.

Using the Unity standard shader and attaching an example of a self-luminous material, note that the spontaneous light from the Unity logo also calculates the shadow, which in this case gives the sphere a shadow.

Luminous materials only affect static objects in the scene, and if you want to influence dynamic objects like characters, you must use the light probes, which changes the value of the luminous material during the game cycle to update the light probe sample and see the changes directly in the results.

Optical probe (light probes)

Static objects are only calculated by the Unity Global illumination GI system, in order to enable dynamic objects to interact with the light and shadow information received by the static scene, we need to record the information of these lights and make a format that can be accessed quickly during execution. We place many sampling points in the scene to intercept information gathered in various directions, and color information is compiled into a set of values (or coefficients) that can be quickly taken out in the game, which we call "light probes".

Using the light probe scene, note the position of the light probe in the image where the light is prone to change, such as shadows or color transitions.

The light probe allows the moving object to accept a complex reflection light from the global illumination GI, which, when in the color grid, determines the position of the nearby light probe and blends the information of the light together, by searching for a tetrahedron generated by the light probe and then deciding which tetrahedron to fall into the axis of the object, This allows the dynamic object in the scene to receive the light information correctly, and if no light probe is placed, the dynamic object cannot accept the information of the global illumination, which causes the dynamic object to be darker than the scene.

In the case of a preset, the scene is without any light probe, and you must set up the light probe group yourself from Gameobjects->light->lightprobe group. If the global light in the Auto is tick (Lighting->scene->auto), when the light source or static object updates, the light probe information will be updated in real-time, not tick words must point build operation will be updated.

Global lighting Technology in Unity 5 (reproduced)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.