Foreword
In Unity's 5.x prior to version 5.6, Geomerics' Enlighten [1] was mainly used to provide real-time global illumination and baked global illumination. After 5.6, Unity introduced a new Lightmapper, Progressive, to provide baked global illumination and More mixed lighting modes are available, but Enlighten is still the main provider of global lighting in Unity.
So, this article comes to talk about Unity5.6 and Unity2017 and Enlighten, mixed lighting related topics.
Direct and indirect light
Everyone knows that in Unity, we can arrange light sources such as directional light, spot light, and spotlight in the scene. However, if there is only such light, the scene will only be affected by direct light, and the so-called direct light is a simple understanding of light emitted from the light source that directly affects the object. If only the influence of direct light is considered, many light and shadow details will be lacking, resulting in a "flat" visual effect. Indirect light describes how the photons bounce off the surface of the object and can be used to increase detail and realism.
For example, in the picture above, the area outside the direct light of the ceiling light lacks the lighting effect. There is no light and dark detail on the four walls, but on the contrary, the direct light range is uniform black, and the entire space is also very flat.
With the addition of indirect light, after rendering, you can see that the light is bounced off the surface of the object and the colored light is transferred from one surface to the other. The color of the red wall and the green wall (on the right and the red wall, not on the screen) is reflected on the other surfaces of the scene, and the walls are no longer uniform black.
Global illumination and rendering equations
As mentioned earlier, using direct light in Unity is not able to simulate the effect of photons bounce on the surface of the object, so Unity uses the global illumination (Global illuminaTIon) provided by Enlighten to provide indirect light effects.
The so-called Global Illumination (abbreviated GI) is a generic name for a set of algorithms used in 3D computer graphics designed to add more realistic lighting to 3D scenes. Such an algorithm not only considers light (direct light) directly from the light source, but also considers the case where subsequent light from the same source is reflected by other surfaces in the scene, ie, indirect light.
Global illumination can be described by a complex equation called rendering equation [2]:
The rendering equation defines how the light leaves a point on the surface. But as you can see, this integral equation is too complex to quickly calculate the results. Therefore, in the specific implementation, some approximate methods are often used.
The approximate method used by Enlighten used in Unity is the radiometric algorithm, which simplifies calculations assuming there is a finite set of static elements and only diffuse optical transmissions. The above rendering equation can be simplified as follows:
In this way, we can turn the integral calculation into the sum of the radiances of the other elements.
Which Bi refers to the final light at point i, Le is the light of point i itself, and how much proportion of light before two points will be rebound, there is a "form factor" to define, that is, Fij in the formula, Lj It is light of J point. The pi (input method problem, first written as p) is a parameter related to i's material properties.
In this way, the equation is better understood, and the calculation is much simpler than the previous rendering equation.
With the simplified equation, Enlighten groups the scenes into a system that facilitates parallel processing when calculating global illumination. Next, each system is cut into discrete clusters.
When calculating lighting, Enlighten treats the scene as a set of clusters. The cluster inside the scene is organized in a hierarchically-associated structure, and it will sample the mapped albedo of the static geometry, and then calculate the relationship between the clusters in the Light Transport phase to make the light pass between the clusters. .
It seems that the global lighting solution has perfectly solved the problem of indirect light, but the cost of pre-computing real-time GI is still very high. Therefore, for relatively low-end devices such as mobile platforms, there is a need for more optimized solutions. So baking the light information of a static object onto a lightmap while maintaining the use of real-time light on a dynamic object becomes a good solution. And that's what we're talking about in the next section.
Mixed lighting
What is the difference between using mixed lighting and using baked lightmap directly? In simple terms, selecting the "mix" baking mode will save light information from the hybrid light source that is marked as static by the GameObject as a Lightmap. However, unlike light labeled "baking," blending lights also provide real-time direct lighting for non-static (dynamic) GameObjects in the scene.
In the Unity 5.x version, the light source already has a choice of mixed modes. However, until Unity 5.6, the hybrid mode has changed to 4 seed mode. In Unity's 2017 version, it became a three-seeded mode - the shadowmask's two modes were placed under Shadow in Quality SetTIng. As shown in the figure below, Ligh TIng screenshots from the Unity 5.5, Unity 5.6, and Unity 2017.3 versions, respectively.
You can see the version after Unity 5.6, mixed lighting modes Baked Indirect, Distance Shadowmask, Shadowmask, SubtracTIve these sub-modes (after the 2017 version of the Distance Shadowmask settings into the Quality Setting).
First of all, we can first look at the Subtractive mode, because Subtractive mode is also the mixed lighting mode used by Unity before 5.6.
For example in Unity 5.5, if we set the light source to mixed to turn on mixed lighting, then selecting Subtractive mode after 5.6 to turn on mixed lighting is the same.
Is it safe to use mixed lighting now?
We can look at a common problem in this mode:
That is, when you turn on the mixed mode using point light, the dynamic object cube in the lower left corner does not generate the real-time shadow generated by the point light.
This doesn't sound like it was intended, because the mixed light mode obviously provides real-time lighting effects on the dynamic object, which is supposed to be the shadow caused by the point light as shown in the figure below.
Why is this? This is actually because the mixed lighting before 5.6 and the mixed lighting using subtractive mode after 5.6 can only work when there is only "Directional light".
Another problem with the subtractive mode is that there are no highlights in the baking result because this mode not only brews indirect light, it also bake direct light, and therefore it does not provide the highlight effect. So you can see in the above screenshot, there is no highlight effect.
Due to the lack of this mixed lighting model, Unity 5.6 introduced more mixed lighting models to meet everyone's needs.
However, as a hybrid mode with minimal overhead, the subtractive mode still has to be preserved. In some cases where the performance requirements are higher than the requirements of the effect, the subtractive mode is still a good choice.
Mixed Light New Mode - Shadowmask
An important feature of Unity's new hybrid lighting mechanism is support for Shadowmask [3]. In the case of mixed light with shadow mask mode enabled, Unity generates an additional set of shadow mask textures. Each of the 4 channels of each texel can be used to save 4 different light sources.
As shown in the figure, this shadow mask holds the information of 2 light sources, a main direction light and a spot light.
Shadowmask's main function is very easy to understand in nature, it solves the previously unsuccessful things in the subtractive mode. Shadowmask can not only deal with the direction of light, but also can correctly handle the performance of spotlight and spotlight under mixed lighting conditions.
You can see that the dynamic object cube in the lower left corner produces real-time shadows from the light in the mixed mode.
At the same time, because the direct light is not baked, it can provide the correct highlight effect at runtime.
Some friends who open the Mixed Mode sub-mode selection menu will see another shadow mask similar to the shadow mask in version 5.6.
What is the difference between Distance Shadowmask and Shadowmask?
This is related to the shadow distance and how shadows are generated in mixed lighting.
We can find the setting of Shadow Distance in Edit->Project Settings->Quality settings. In the real-time light mode, only the objects in the Shadow Distance range will be affected by the shadow.
In mixed-light-shadowmask mode, shadows between static objects and static objects are generated by shadow mask textures. For a shadow generated by a dynamic object received by a static object, the dynamic object generates a shadow map shadow in real time only within a shadow distance. Shadows between dynamic objects also need to be generated within the Shadow Distance. As for the dynamic object, if you want to receive the shadow of a static object, you need the help of the light probe.
As shown above, the shadow mask provides shadows between the static wall and the ground.
As for the three dynamic object cubes, the cube in the lower left corner cannot receive the shadow of the static wall without the light probe. There are real-time shadow map shadows between the two cubes on the right, and they also cast real-time shadow map shadows on static walls.
If you use the Distance Shadowmask mode, what type of shadow will you guess changes?
The answer is very simple, first of all, it is definitely related to the Shadow Distance, and the second is definitely related to the switching between the real-time shadow map and baked shadow mask. Well, the answer is ready to come out - in the distance shadow mask mode, static objects within the shadow distance will also produce shadow map shadows in real time. This is the same as dynamic objects, so whether it is between static objects or between static objects and dynamic objects There will be real-time shadow map shadows. Once the shadow distance is exceeded, the shadow of the static object is obtained from the shadow mask.
As shown in the above image, you can see that the shadow edge between the static wall and the ground is sharp. Unlike the previous shadow obtained from Shadowmask, it may be more blurred due to the resolution. At this time, it is already the Shadow Map shadow in real time. , so the edges are sharper and sharper. And the cube in the lower left corner can already receive the real-time shadow of the static wall.
However, as I mentioned earlier, the Distance Shadowmask and Shadow Distance and the two shadow generation methods are related, then there may be a kind of ç‘•ç–µ å³ å³ å³ å³ å³ å³ å³ å³ å³ å³ å³ å³ å³ å³ å³ å³ å³ å³ å³ å³ å³ å³ å³ å³ å³ å³ å³ å³ å³ å³ å³ å³ å³ å³ å³ å°±æœ‰ 就有 就有The shadows are often more blurred due to the resolution, such as the following:
You can see that the wall has two different shades. Therefore, you may also need to pay attention to this issue in the development process.
In addition, the difference in performance between Shadow Shadowmask and Shadowmask is obviously greater. It's not hard to imagine that there are still many static objects that have real-time shadows. Then we can simply compare the cost of the two in the Draw Call:
As you can see, the drawCall cost of the Distance Shadowmask on the right is much higher than the shadowmask. Therefore, the use of shadow masks on mobile devices rather than the more costly Distance Shadowmask is more applicable to the pursuit of performance. Of course, after Unity2017, the settings for Distance Shadowmask and Shadowmask have been moved to Quality Setting, which means that we can dynamically switch between these two modes at runtime.
Void OnTriggerEnter(Collider other) { if(QualitySettings.shadowmaskMode == ShadowmaskMode.Shadowmask) { QualitySettings.shadowmaskMode = ShadowmaskMode.DistanceShadowmask; }else { QualitySettings.shadowmaskMode = ShadowmaskMode.Shadowmask; } }
Of course, both the Distance Shadowmask and the Shadowmask can provide shadows from the Shadowmask outside of the Shadow Distance, although they are somewhat more ambiguous than real-time shadows. Therefore, Shadowmask mode is a good choice for projects that need to be shadowed in the distance.
Mixed Light New Mode -Baked Indirect
The last mixed lighting mode is Baked Indirect [4]. In fact, the name of this hybrid mode is already very straightforward - it only bake indirect light, and everything else is real-time. Shadowmask textures? nonexistent.
So we have real-time light, real-time shadows, and so on. So, within the Shadow Distance's range, just as with real-time lighting, shadows are real-time shadow maps, and there are no shadows outside the shadow distance—even those with low-resolution blurry shadows.
It can be seen that the shadow of the wall within Shadow Distance is very clear, but there is no shadow outside the range. At the same time, the cost of this hybrid mode is also great because it only brews indirect light, and everything else is real-time.
to sum up
Ok, let's make a small summary of these mixed modes, which can be simply summarized as the following table [5].
Cummins 0-20KW Diesel Generator
Cummins 0-20Kw Diesel Generator,Cummins Portable Power Generator,Cummins Open Type Power Generator,Cummins Container Power Generator
Shanghai Kosta Electric Co., Ltd. , https://www.generatorkosta.com