Unity3d Development Diary (5)-Suitable for mobile platforms with the wind swinging vegetation

Source: Internet
Author: User
Tags sin

I've been thinking about how to make the scene more vibrant, and I think the wind-swinging of the vegetation is essential. The vegetation of the CE3 engine is very bending. I'm going to do a set on my phone, too.

First of all, analysis of several common methods of vegetation swing. In fact, no matter what kind of practice, the core is to make the vegetation vertex animation, some vertices move less (such as the root), some vertices moving more (such as the tree top), according to what weight to move?

Scenario 1: Use UV to make weights.

This program on the UV expansion requirements, from 0 to 1, only suitable for patch grass, so that the grass root and the top of the swing weight is a 0 to 1 linear change, casually with a positive Xuan wave can be achieved simple swinging,

[CSharp]View PlainCopy 
    1. Simple vertex animation based on UV
    2. FLOAT4 newpos = V.vertex;
    3. NEWPOS.XYZ + = _wind_simple.xyz * V.texcoord.y * _bendingfactor;



Scenario 2: Use the distance from the vertex and the origin of the model to make weights.

CE3 's main bending is this scheme. The distance from the vertex to the origin of the model is actually the vertex value of the model, then the value is divided by the bounding box parameters, you can get each vertex 0 to 1 of the swing weight, very simple, this scheme does not require UV, suitable for all vegetation, but, This scheme can not be used for the combined batch, such as Unity's own static batch, because after the batch, the model has changed, the vertex to the origin of the distance has changed.

Scenario 3: Use vertex color to make weights

CE3 's detail bending is the solution. Let the art brush vertex color, as a swinging weight, vertex color has several channels, each channel to achieve a frequency swing, so you can achieve more complex swing, such as the blue channel used to handle the backbone of the swing, red channels to handle the swing of the branch, The green channel is used to handle the detail jitter of the leaves. The benefit of this scheme is that it is not affected by UV and batch, is suitable for any vegetation, and can also achieve more complex detail jitter, which makes the jitter more realistic. The trouble is to teach art to brush the vertex color, and the most efficient cost.

This scenario should be the most perfect vegetation swing scenario, and GPU GEM3 has a detailed analysis of this:

Click to open link

In combination with the actual project, my overall plan is as follows:

1. The first type of grass, high efficiency

2. Trees and flags in the third, controlled use, and minimizing the number of vertices of this model,

Global Wind Control,

The amplitude of the swing should also be affected by wind:

The words of the grass with a kind of wind, the words of the trees alone with a wind.

[CSharp]View PlainCopy 
    1. [Executeineditmode]
    2. Public class Vegetationwind:monobehaviour
    3. {
    4. Public Vector4 wind = new Vector4 (0.85f, 0.075f, 0.4f, 0.5f);
    5. public Float windfrequency = 0.75f;
    6. private float wavefrequency = 4.0f;
    7. private float waveamplitude = 0.1f;
    8. void Start ()
    9. {
    10. Shader.setglobalvector ("_wind_vertexcolor", wind);
    11. Shader.setglobalvector ("_wind_simple", wind);
    12. }
    13. void Update ()
    14. {
    15. //Wind 1
    16. Vector4 Wind1 = Wind * ((Mathf.sin (Time.realtimesincestartup * windfrequency));
    17. WIND1.W = WIND.W;
    18. //Wind 2q
    19. //vector4 Wind2 = Wind1 * WIND1.W;
    20. Vector4 Wind2 = new Vector4 ();
    21. wind2.x + = Mathf.sin (Time.realtimesincestartup * wavefrequency) * waveamplitude;
    22. wind2.y = 0;
    23. Wind2.z + = Mathf.sin (Time.realtimesincestartup * wavefrequency + mathf.pi * 0.5f) * waveamplitude;
    24. WIND2.W = 0;
    25. Shader.setglobalvector ("_wind_vertexcolor", Wind1);
    26. Shader.setglobalvector ("_wind_simple", Wind2);
    27. }
    28. }

Unity3d Development Diary (5)-Suitable for mobile platforms with the wind swinging vegetation

Related Article

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.