Unity3d 5 Official Tutorial: Standard shader material parameters (iii)

Source: Internet
Author: User
Tags constant reflection contrast lighting
Normal map (bump map)


A normal map is one of the bump maps. They are a specific texture that allows for the addition of surface details such as bumps, grooves, and scratches to the model as if they were illuminated by the geometric representation of the solid.
For example, a user might want to show a surface with grooves and screws or rivets, such as an aircraft's shell. One way to achieve this is to model the details as geometry, as shown in the following illustration.

A planar metal with detail, modeled with a solid geometry.
Depending on the situation, it is often not a good idea to have such tiny details modeled with "real" geometry. As you can see on the right, the required polygons make up the details of a single screw head. For large models with a lot of subtle surface detail, this will require a very high number of polygons to be drawn. To avoid this, a normal map is used to represent fine surface detail, and a lower resolution polygon surface is used for larger shapes of the model.
If you swap with a bump map to show this detail, the surface geometry can be much simpler and the details can be expressed as a texture that adjusts how light is reflected on the surface. This is something that modern graphics hardware can do quite quickly. Because of the texture, the metal surface can now be a low-polygon plane, and the screws, rivets, grooves and scratches will reflect the light and appear to be deep.

Screws, grooves, and scratches are defined in a normal map, which modifies how light is reflected on the surface of the low polygon plane, giving a display of 3D detail. In addition to the rivet screws, the textures allow for a much more detail to include such as tiny bumps and scratches.
In modern game development art processes, artists will use their 3D modeling application to generate a normal map based on a very high resolution source model. These discovery stickers are then pasted to lower resolution, model versions for the game, so that the original high-resolution details are rendered using line maps. How to create and use a bump map

Bump mapping is relatively old graphics technology, but is still one of the core methods to be used when creating fine, realistic, real-time graphics. Bump maps are often also referred to as normal or height maps, but these nouns have slightly different meanings, which are explained below. what is surface normals.

In order to completely explain how normal maps work, here is a first description of what is "normal" and how it is used in real-time lighting. Perhaps the most basic example is that each surface polygon is only a model that is irradiated by the angle of the surface relative to the light. The angle of the surface can be represented by a line perpendicular to the surface in the direction, which is referred to as a "surface normal", or as a normal, relative to the surface of this direction (a vector).

In the above illustration, the left cylinder is a basic and monotonous contrast, and each polygon is shaded by the angle of the relative light source. On each polygon, the illumination across the entire polygon area is constant, because the surface is monotonous. There are two identical cylinders, and their wireframe is visible: the model on the right of the

has the same number of polygons as the left model, but the shading appears smooth-the appearance of the curved surface is formed by the illumination of the polygon. What is this for? The reason is that at each point the surface normals of the reflected light are graded in the direction of the width of the polygon, so that for any given point on the surface, the reflection of the light makes the surface look like an arc, not a polygon that is in fact monotonous and unchanging. The
is treated as a two-dimensional graphic that surrounds the three monotone projected surface polygons of the cylinder, which looks like this:

Monotone projection on three polygons, two-dimensional viewing
The normals of the surface are indicated by an orange arrow. Values are used to calculate how light is reflected on the surface, so you can see that the illumination produces the same reflection on the length of each polygon because the surface normals point in the same direction. This results in a "monotonous projection" and is the reason why the polygon on the left cylinder appears to have a stiff edge.
However, for a smooth projected cylinder, the surface normals change on a planar polygon, as shown in the following:

Smooth projection on three planes, two-dimensional view
The normal direction changes gradually on the plane polygon surface, so that the projection on the surface produces a smooth arc effect (as shown in the Green Line). This does not affect the actual polygon nature of the mesh, just how the light is calculated on the flat surface. The curved surface on this surface is not true, and a grazing angle will reveal that the surface is the essence of a flat polygon, but from most angles of view the cylinder appears to have a smooth curved surface.
using this basic smoothing, the data that determines the normal direction actually stores only each vector, so that the change in the value on the surface is interpolated between a vector and the next. In the above observation, the Red Arrows indicate the direction of the normals stored in each vector, and the orange arrows symbolize the example of interpolating normal directions in the area of the polygon. what is a normal map.

The

Normal map allows this modification of the surface normals to be further deepened by using a texture to store information about how to modify all the surface normals of the model. A normal map is a picture texture that maps to the surface of a model, similar to a color texture, whereas each pixel in a normal map texture (called a texel) is represented by a deviation from the surface normals in the surface normal direction relative to the "true" flatness (or smooth interpolation).

Here again is a two-dimensional representation of three polygons on a three-dimensional model surface, with each orange arrow corresponding to a pixel on the normal map texture. Below is a single-pixel tile map of a normal map texture. In the middle, you can see that the normals have been modified, causing some bump on the polygon surface. These bumps are only noticeable because the light shines on the surface, because the normals of these changes are used for lighting calculations.
The colours visible in a raw normal map file typically has a blueish hue, and don ' t contain any actual light or dark Shading-this is because the colours themselves was not intended to being displayed as they are. Instead, the RGB values of each texel represent the X, Y & Z values of a direction vector, and are applied as a modific ation to the basic interpolated smooth normals of the polygon surfaces.


This was a simple normal map, containing the bump information for some raised rectangles and text. This normal map can be imported to Unity and placed into normal map slots of the standard Shader. When combined in a material with a colour map (the Albedo map) and applied to the surface of the cylinder mesh above, t He result looks like this:

Again, this does not affect the actual polygonal nature of the mesh, only how the Lig Hting is calculated on the surfaces. This apparent raised lettering and shapes on the surface is not really present, and viewing the faces at glancing angles Would reveal the true nature of the flat surface, however from the very viewing angles the cylinder now appears to has Embosse D detail raised off the surface. How does I get or make normal maps?

Commonly, Normal Maps is produced by 3D or Texture artists in conjunction with the model or textures they is producin g, and they often mirror the layout and contents of the Albedo map. Sometimes they is produced by hand, and sometimes they is rendered out from a 3D application.

How to render normal maps from a 3D application are beyond the scope of this documentation, however the basic concept is That a 3D artist would produce the versions of a model-a very high resolution model containing all detail as polygons, And a lower-res the "game Ready" model. The high res model would was too detailed to run optimally in a game (too many triangles in the mesh), but it's used in th E 3D modelling application to generate the normal maps. The lower-res version of the model can then omit the very fine level of geometry detail that's now stored in the normal maps, So, it can be rendered using the normal mapping instead. A Typical use case for this would is to show the bumped detail of creases, buttons, buckles and seams on a characters clot Hing.

There is some software packages which can analyse the lighting in a regular photographic texture, and extract a Normalmap From it. This works by assuming the original texture was lit from a constant direction, and the light and dark areas were analysed an D assumed to correspond with angled surfaces. However, when the actually using a bump map, you need to make sure the your Albedo texture does not having lighting from any PA Rticular direction in the image-ideally it should represent the colours of the surface with no lighting at All-because The lighting information'll be calculated by Unity according to the light direction, surface angle and bump map Informa tion.

Here was a simple repeating stone wall texture with its corresponding normal map, and one was a charac examples Ter ' s texture atlas with its corresponding normal map:

. What ' s the difference between Bump maps, Normal maps and Height maps?

Normal maps and Height maps are both types of Bump Map. They both contain data for representing apparent detail on the surface of simpler polygonal meshes, but they each store th At the data in a different.

Above, on the left, you can see a height map used for bump mapping a stone wall. A height map is a simple black and white texture, where each pixel represents the amount so point on the surface should appear to be raised. The whiter the pixel colour, the higher the area appears to be raised.

A Normal map is an RGB texture, where each pixel represents the difference on direction the surface should appear to be FA Cing, relative to its un-modified surface normal. These textures tend to has a bluey-purple tinge, because of the the-the-the-vector is stored in the RGB values.

Modern realtime 3D graphics hardware rely on Normal Maps, because they contain the vectors required to modify how light Should appear to bounce of the surface. Unity can also accept Height Maps for bump mapping, but they must is converted to Normal Maps on import in order to use th Em. Why the bluey-purple colours?

Understanding this isn't vital for using normal maps! It ' s OK to skip this paragraph. However if you really want to know:the RGB colour values is used to store the x, Y, z direction of the vector, with Z bein G "Up" (contrary to Unity's usual convention of using Y as "up"). In addition, the values in the texture is treated as has been halved, with 0.5 added. This allows vectors of any directions to be stored. Therefore to convert an RGB colour to a vector direction, you must multiply by and then subtract 1. For example, an RGB value of (0.5, 0.5, 1) or #8080FF in hex results in a vector of (0,0,1) which are "up" for the purposes of Normal-mapping-and represents no change to the surface of the model. This is the colour-the flat areas of the "example" normal map earlier on this page.

A value of (0.43, 0.91, 0.80) gives a vector of (–0.14, 0.82, 0.6), which is quite a steep modification to the surface. Colours like this can is seen in the bright cyan areas of the stone wall normal map at the top of the some of the stone edges. The result is this these edges catch the light at a very different angle to the flatter faces of the stones.


Normal maps


How to import and use Normal maps and Height maps

A Normal map can be imported by placing the texture file in your Assets folder, as usual. However, you need-to-tell Unity-this-texture is a normal map. Changing the "Texture Type" setting to "Normal Map" in the Import Inspector settings.


To import a black and white heightmap as a normal map, the process was almost identical, except you need to check the "Crea Te from greyscale "option.

With ' Create from Greyscale ' selected, a bumpiness slider would appear in the inspector. Steep the angles in the Normalmap is, when being converted from the heights in your Heigh Tmap. A low bumpiness value would mean that even sharp contrast in the heightmap would be translated to gentle angles and bumps. A high value would create exaggerated bumps and very high contrast lighting responses to the bumps.

Once you has a normalmap in your assets, you can place it into the Normal Map slot of your Material in the inspector. The standard Shader have a normal map slot, and many of the older legacy shaders also support normal maps.

If you imported a normalmap or heightmap, and do not mark it as a normal map (by selecting Texture type:normal map as De scribed above), the Material inspector to fix it, as so:

Clicking "Fix Now" have the same effect as selecting Texture type:normal Map in the Texture Inspector settings. This would work if your texture really is a normal map. However if it is a greyscale heightmap, it won't automatically detect this-so for heightmaps your must always select t He "Create from greyscale" option in the texture ' s inspector window.secondary Normal Maps

You could also notice that there is a second Normal Map slot further the Material inspector for the standard Shader. This allows the additional normal map for creating extra detail. You can add a normal map to this slot in the same-the-regular normal map slot, but the intention here's Should use a different scale or frequency of tiling so, the other normal maps together produce a high level of detail a T different scales. For example, your regular normal map could define the details of panelling in a wall or vehicle, with Groves for the panel Edges. A Secondary Normal map could provide very fine bump detail for scratches and wear on the surface which is tiled at 5 t O times the scale of the base normal map. These details could is fine as to is visible when examined closely. To has this amount of detail on the base normal map would require the base normal map to being incredibly large, however by Combining-different scales, a high OVerall level of detail can is achieved with the relatively small normal map textures.

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.