[Wind yuchong] unity3d tutorial book shader: 19th lecture on concave and convex textures

Source: Internet
Author: User
If the original article needs to be reproduced, please note: Reprinted from Fengyu Chong unity3d tutorial Institute

       Lecture on shader 19thConcave and convex textures

This article consists of two parts: Principle 2: implementation
  
 
I. Principle (1) eyes and lightLet's look at a rough surface.

From a distance, the only evidence that this object is rough is that the brightness on its surface changes. Your brain is able to get these bright and dark pattern information and determine that they are concave and convex parts on the surface. A picture on the left shows this. You can see that it is a fully carved surface. Some moments and letters are printed on the surface, but they touch the glass of a hidden monitor. If the image is in a proper position, it does not need to do anything except change the brightness.
Then you may ask: How do I know which points should be bright and which ones should be dark? This is not difficult. The vast majority of people live in this environment-most of the light sources in this environment come from the top (for example, the main light in the day is from the sun, and the main light in the night is from the fluorescent light on the ceiling ). So the tilting area is brighter, and the tilting area is darker. Therefore, when your eyes see a bright and dark area on an object, you can determine its concave and convex. Relatively bright blocks are determined to be in the upward direction, while relatively dark blocks are determined to be in the downward direction. So I just need to color the lines on the object.
If you want more evidence, there is an almost identical image, unlike the previous one, which rotates 180 degrees. So it is the reverse image of the previous image. The areas that previously appeared to be concave and now seem convex.
At this time, your brain is not completely deceived. The visual impression in your mind makes you still have the ability to determine that this is the previous figure, but its light source has changed, your brain may be forced to figure it as the first image. In fact, as long as you keep staring at it and try to imagine that light shines in the lower right corner, you will understand it as concave, you can easily determine these images as protruding images, but with the impression of the previous comparison, you may notice that these blocks are actually concave, it's just that the judgment method does not conform to our daily habits, because at this time, most of the light is not from the top, but from the bottom up ).(2) normalAs mentioned above, normal light reflection is very important. In general, the normal of a point on a triangle is equal to the normal of the entire triangle vertical. However, we can use a grayscale image or a normal map to get a more realistic picture.

 
II. Implementation
(1) superposition with Grayscale ImagesThis method is also called fake bump mapping. Because it does not change the position or normal of the object's surface point. Just put bump
The map is superimposed on the rendered surface, causing a disturbance on the brightness, so that the eyes are concave and convex. Computing complexity is the basic addition and subtraction. The disadvantage is that the light and shade areas will not change with the change of the light direction.
(2)Generate normalBecause the method (1) has a hard injury that does not respond to light. So there is a more realistic method: using a high-density algorithm line. There are many ways to calculate the line of height. Here we mainly introduce a widely used method in CG. Method: when sampling a vertex on a grayscale image, the height of the vertex is not Hg, and take the HR point on the right of the point and the point ha above the point as two vectors using the three points: the first vector V1 is (, HR-Hg) the second V2 is the vector product of V1 and V2 after unitization (0, 1, ha-Hg.
If you store the result on a graph, a normal map is generated. Unity3d can do this for us and convert grayscale images to normal textures. Is the following (3)
(3)Line map in UnitySpecific steps: 1) Import heightmap2) change texture type to normal map3) Check create from grayscale4) After apply, you can see that the image in unity is directly converted into a blue normal map.

PS: The built-in Bump Map shader in unity3d, that is, the shader such as bumped diffuse is a normal texture. That is, the normal map of RGB is used, which is usually blue. The built-in shader of Unity does not directly use grayscale images, but provides the grayscale line map function. Part of the content from the http://freespace.virgin.net/hugo.elias/graphics/x_polybm.htm

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.