In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you how Unity3D realizes the role shadow on the mobile platform. I hope you will gain something after reading this article. Let's discuss it together.
Since the mainstream use of Unity3.x does not support dynamic shadow generation on mobile platforms, the most popular and cost-effective shadow generation methods are as follows:
1. Simple mapping method
The so-called simple mapping method is to attach a shadow translucent map directly to the bottom of the character's corner and let it move with the character. Generally, the shadow Object is made into a child of the character model. The effect of this kind of shadow generation is as follows:
The Inspector view of shadows is as follows:
ShadowComponent is a script that controls shadows and has nothing to do with its generation, so it is not covered here. There are two main parts that affect the generation of the application, one is the Shadow mesh, and the other is the material "No Name" needed for rendering. It is important to note that the Shadow mesh is a flat surface, but it is not recommended to use the Plane generated by Unity itself, because Unity generates a large number of faces and can model itself through modeling tools such as 3DMax, as shown below:
For materials, the most important thing is the writing of Shader, which I list below for your convenience:
Shader "iPhone/SimpleShadow" {Properties {_ MainTex ("MainTex") 2D) = "" {}} SubShader {Tags {"Queue" = "Transparent"} Pass {Blend SrcAlpha OneMinusSrcAlpha Color [_ clrBase] Cull Off Lighting Off SetTexture [_ MainTex] {combine texture One-texture}}
Through the above settings can generate the simplest shadow effect, you can set your own script to control the movement and changes of shadows, and so on.
However, this shadow generation method has an obvious "hard wound", that is, the shadow can only be applied to the flat ground, and once the ground is uneven or covered, there will be a "piercing" effect, as shown in the following illustration. The shadow generated by this method has no effect on the cube under the foot, so in order to solve this problem, the projection generation method arises at the historic moment.
2. Projection generation method
This method is essentially a Decal technique, that is, a projector is set up, and then the shadow map is projected to the place where you want to show the shadow. The advantage of this method is that the projection effect does not depend on the geometric shape of the projected area, that is, the projected area can be arbitrarily convex and concave surface, but also can deal with all kinds of obstacles. The shadow effect generated by this method is as follows:
Let me introduce how to generate this shadow in detail:
(1) create an empty object through "GameObject- > Create Empty" and name it "Shadow Projector".
(2) add Projector components to the empty object by "Component- > Effects- > Projector", and achieve the following effects by translating, rotating and adjusting parameters:
(3) then drag the prepared material in the Material option to cast a shadow. The effect is as follows:
We can see that not only shadows are generated in the scene, but also the character's body "blackens". This is because the "Ignore Layers" of the projector is set to "Nothing". If we set the negligible layer as the character's layer "Player", the character can no longer be projected. The effect is as follows:
(4) the Inspector view of the final Shadow Projector is as follows:
The shader used for the material is:
Shader "Projector/Multiply" {Properties {_ ShadowTex ("Cookie", 2D) = "gray" {TexGen ObjectLinear} _ FalloffTex ("FallOff", 2D) = "white" {TexGen ObjectLinear}} Subshader {Tags {"RenderType" = "Transparent-1"} Pass {ZWrite Off Fog {Color (1,1) 1)} AlphaTest Greater 0 ColorMask RGB Blend DstColor Zero Offset-1,-1 SetTexture [_ ShadowTex] {combine texture, ONE-texture Matrix [_ Projector]} SetTexture [_ FalloffTex] {constantColor 1) combine previous lerp (texture) constant Matrix [_ ProjectorClip]}}
Through the above steps, we can realize the shadow generation method of projection type. As with the first method, you can set up specific scripts to control the movement of the shadow, changes, and so on. In addition, it is important to pay attention to the setting of the "Ignore Layers" option, which in principle is to remove those layers that do not need to be projected, so as to reduce the amount of unnecessary computation.
The above two methods are the mainstream shadow generation methods on the mobile platform at present, which have the advantages of simple generation, easy to use and small amount of calculation, but their disadvantages are also prominent, that is, the shadow is fake and is not cast by real objects, so the sense of reality is not strong. Below, I will introduce two real-time dynamic shadow generation methods that can be used on mobile platforms at present, but in this article we only introduce shadow effects, not specific implementation techniques and generation methods, which will be explained in future advanced tutorials.
3. Shadow Map method
Although Unity currently does not support dynamic shadow generation on mobile devices, you can also generate a simple Shadow Map through RenderTexture, as shown below:
We can see that the shadows generated are aliased, which is due to the insufficient resolution of Shadow Map. You can reduce the aliasing effect by increasing the resolution of RenderTexture, as shown in the following image, which will also lead to some rendering consumption.
4. Methods of environmental occlusion
This method is taken from the game "Shadow Gun". The dynamic shadow is generated in real time by analyzing the approximate environmental occlusion information of the object. The effect is as follows:
The generation method is roughly as follows:
First, a mesh showing shadows is generated on the soles of the character's feet.
Secondly, the ambient occlusion (Ambient Occlusion) information of the bottom surface is calculated by generating three balls at the character's step and legs respectively.
Finally, the mesh is subdivided dynamically according to the calculated AO information, so that the final AO shadow can be generated.
After reading this article, I believe you have a certain understanding of "how Unity3D realizes the role shadow on the mobile platform". If you want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.