Unity3d Tutorial Shader: the 21st parallax map

Source: Internet
Author: User
Tags camera vector

reprinted from the Wind Yu Chong Unity3d Tutorial College Display of parallax mapsFigure one: Pay attention to the self-shadow in the tire printing, in fact, the road is just a flat Map II: The success of the Crysis, parallax mapping is not
Figure Three: Parallax mapping can also be used for people, equipment and propsThis lecture is divided into four parts
One: Advantage characteristicsII: FundamentalsThree: How to useFour: Parallax calculation the advantages and characteristics of parallax mapping in the first part The normal map was told on the previous one. Normal maps, either RGB normal maps or dxt5nm, have one drawback. The closer to the horizontal view of the face, the less realistic the picture is. Since the normal map is used, the raised part only looks convex, but the mesh model is not raised and still flat. Normally the raised part obscures the back part, but the normal map has no effect. So we have an improved version of the normal map-parallax mappingThe benefits of Parallax Mapping: (1) when the relative angle of view will change, there is a three-dimensional (2) in the angle of view close to the level, there is still good quality below the two-figure comparison can be seen, in the angle of view close to the level, parallax mapping is much clearer than the normal map. Note: Parallax mapping works almost the same as normal mapping when the angle of view is equal to or closer to vertical.

the second part of the Parallax mapping principleparallax mapping, invented by Tomomichi Kaneko in 2001, but limited to the performance of computers, the real business use began in 2007. Parallax maps are implemented with UV offsets. The offset value of the UVS is calculated from the height and the vectors that point to the camera. So parallax mapping still does not change the true model surface construction.Note: ifUsing Unity's own parallax class shader, the height must be in a channel (corresponding to COLOR.W), if the height map is a grayscale map, you need to convert to a channel, the following sections of the use of detailed methods. For a high level of knowledge, refer to the first half of the 17 lecture. Left: Rugged pebbles on the right: actually just a plane


the third part of the parallax map Use(1) Prepare the map, normal map, height map. (2) If the height chart height is stored in a transparent channel, skip this step. If it is a grayscale chart: Select the figure, tick the alpha from grayscale, and apply to

(3) Create plane and materials, shader select parallax Diffuse or parallax diffuse (4) Drag three graphs to the corresponding bar (5) to adjust height. If you are using parallax mapping for the first time, adjust the height to the highest and then rotate plane to view it, so you can quickly understand the benefits of parallax mapping. If it is really used, the height is slightly lower, otherwise it will be distorted. calculation of the parallax map in the fourth partOpen the Build-in Shader in the Normal-parallax.shader, namely Parallax diffuse. The following code is available:
    1. Half h = tex2d (_parallaxmap, In.uv_bumpmap). W;
    2. FLOAT2 offset = Parallaxoffset (h, _parallax, In.viewdir);
    3. In.uv_maintex + = offset;
    4. In.uv_bumpmap + = offset;
(1) The texture map obtains the height value H (2) is calculated by the height value H and the vector pointing to the camera offset offset (3) for the texture map and the normal map to the UV offset offsets where the second step is the focus. Open Unitycg.cginc and see the code below.
    1. Calculates UV offset for parallax bump mapping
    2. Inline Float2 parallaxoffset (half h, half height, half3 viewdir)
    3. {
    4. H = h * height-height/2.0;
    5. Float3 v = normalize (viewdir);
    6. The unit points to the camera vector. Z +0.42
    7. V.z + = 0.42;
    8. Offset. x = Height * (units pointing to the camera vector x/units pointing to the camera vector z)
    9. Offset. y = height * (units point to the camera vector's Y/unit to Z of the camera vector)
    10. Return h * (V.XY/V.Z);
    11. }
The calculation method comes out. The theoretical basis of the specific algorithm interested students can do their own research. Part of the content from: "Technology paste" the strongest map-parallax mapping technology

Unity3d Tutorial Shader: the 21st parallax map

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.