Article directory
Show results
the whole frame
Content of each region
Area 1
Calculate the distance between the interactive cube and the vertices of the grass
This can be understood as the distance from the center of the cube to the vertices of the grass. The distance is an integer from 0 to The process is as shown below
Area 2
Divide the distance by a certain value. This value is the interaction range, which is equivalent to moving the white bar range to the right.
Then use the saturate node to limit the value to 0-1< /span>
Area 3
First of all, the previous step has limited the value to 0-1. This step is reversed. The intuitive explanation is to swap the black and white bars. The closer to the cube, the whiter the part, which means the stronger the influence on the grass vertex shader.
Area 4
In order to move the vertex vector of the grass, we need to know the movement method. Subtract the world coordinates of the cube from the vertex position of the grass to obtain the directions of both.
Then multiplied by the influence calculated in area 3, you can get the effect of the closer the vertex is, the greater the offset will be.
Area 5
This step may seem complicated, but it is actually very simple. Add the vertex offset obtained in area 4 to the vertex coordinates of the grassland. Since the grass does not need to move along the y-axis, you only need to add the x-axis and z-axis. .
Area 6
When the grass moves, we don't need the roots of the grass to move, so we use the vertex color. That is, when making the grass model, the vertex color (note that it is not the color of the texture) is added to the vertex of the root. It is black and can be interacted with. The part is white, so that a Lerp can be used to smoothly transition between the areas that do not need to be moved and the areas that need to be moved. Of course, vertex coordinates can also be used to calculate here.
Area 7
Finally we need to give a texture
GraphSetttings
Finally, you need to write a script to tell the material where the cube is.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TrackPosition : MonoBehaviour
{
public Material grassMat;
private void Update()
{
grassMat.SetVector("_TrackerPosition_v3", transform.position);
}
}
Then hang it on the cube and drag the material ball to the properties.
Process belowgitee site