In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
It is believed that many inexperienced people do not know what to do about how to carry out the Unity implementation of basic lighting control in graphics. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
General computer graphics in explaining the theory of lighting [1] is in the following order. Although they are outdated technologies, the PBR of your fashion is still based on these ancestors. When the magic changes, please note that these bones cannot be moved.
1.1 Shading coloring method
1.1.1 Flat shading planar shading
This is the easiest and most efficient way to render a material surface. Each face is represented by a single color. This kind of coloring is not implemented in Unity, you need to write a simple CG shader yourself. If you want the lowpoly effect, remember not to use the smooth group, press the triangle to give the vertex normal.
1.1.2 Gouraud shading Gorod coloring
Gerald coloring is introduced into graphics to improve the natural transition of colors on smooth objects. In this method, the light color of each model vertex is calculated, and then the light color is interpolated to the triangular face of the vertex.
This method is obviously more efficient than calculating light color pixel by pixel, but because most materials are not only diffuse reflection, but also specular reflection, and specular reflection mostly occurs on the interior of polygons rather than vertices, so this method is very bad at representing objects with detailed highlights.
Unity comes with the coloring method used by VertexLit shader, please right-click your shader file and view the frag function in the generated shader code in inspector.
1.1.3 Phong shading Ponzi coloring
As mentioned above, most material surfaces are not only diffuse, but also specular. In order to represent the material highlights, Ponzi shading is introduced into the rendering method. When you render a point in a polygon, the normal of that point is the interpolation of the normal of adjacent vertices. Light and color are calculated point by point.
This represents a sphere perfectly because the interpolation of normals is in line with the normal distribution of the sphere.
UNITY surface shader uses Phong shading by default. Right-click your mobile diffuse shader and view the frag function in the generated surf shader code in inspector.
1.2 Lambert Lighting Model
The property of a diffuse material is that incident light entering the surface is reflected from a random direction. You can think of this process as an atom absorbing one part of the photon and emitting another photon in the other direction. Because of the randomness of the light reflection direction, our observation angle becomes less important. The only thing we need to pay attention to is the direction in which the light enters the material surface.
If light enters the surface from a more vertical angle, it means that more intensive light energy reaches the surface of the material. If light enters the material from a squint angle, the same amount of light energy will cover a larger area and receive less light energy per unit surface. As shown in the figure, the light energy received by the material surface and the amount of light it can reflect are proportional to the angle between the material surface and the light direction.
This is why we need the normal vector of the material surface. The cosine of the angle between the normal and the direction of light determines the proportion of lighting we need.
We can find the implementation of Lambert Lighting in Unity as follows:
/ / Shader code from Lighting.cginfixed diff = max (0, dot (input.Normal, light.dir)); fixed4 output;output.rgb = s.Albedo * light.color * diff
1.3 Phong Lighting Model
As we mentioned earlier, the material surface is not only diffuse reflection, the real object surface will have part of the specular reflection, that is, part of the incident light will be emitted from the reflection direction. If the observer of the material happens to look at the material from the angle of reflection, you will find that one area of the material's surface is brighter than the others. Note that the position of the observer is constant. The observer can choose to observe different areas of the material's surface, but the specular reflection only appears in the area where the reflected light is directed to the viewer. In this way, part of the light is absorbed by the material surface and reflected in any direction, while the other part directly reflects off the surface. If the direct reflection part is 100%, then the surface is an ideal mirror.
We can still define this lighting model using the cosine of the viewing direction and the reflection direction of the light, but because the cosine function attenuates too slowly, it presents a large, loose highlight on the surface of the material. Phong proposes to use the n-th power of the cosine to quickly attenuate the cosine without affecting the range of function 0,1, which is called shininess in the program circle. Because the amount of calculation is larger than that of Blinn-Phong, the lighting model is not used in the default shader of Unity. Of course, you can change it yourself, and the position of the highlight will be slightly different, but don't lever it, okay?
1.4 Blinn-Phong Lighting Model
The lighting model closer to the real world is actually the Blinn-Phong model, which calculates highlights in a slightly different way. In the Blinn-Phong model, we use the sum of the incident vector and the observation direction of the light and the cosine value of the normal of the material surface to measure the lighting effect. It can be seen from the figure that when the reflection direction of the light coincides with the observation direction, the vector coincides with the normal direction, and the cosine value is 1, so there is nothing wrong with the theory.
Everything else remains the same, and the implementation in Unity is as follows
/ / Shader code from Lighting.cginchalf3 h = normalize (light.dir + viewDir); fixed diff = max (0, dot (s.Normal, light.dir)); float nh = max (0, dot (s.Normal, h)); float spec = pow (nh, s.Specular*128.0) * s.Glossscape fixed4 c. RGB = s.Albedo * light.color * diff + light.color * _ SpecColor.rgb * spec After reading the above, have you mastered how to implement the basic lighting control Unity in graphics? If you want to learn more skills or 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.