INTERACTIVE GRASS WITH UNITY
Create interactive grass with Unity is not too complicated, but there is not lots of information online about how to achieve this, and more important, nobody is explaining at all. In this Article, I will try to show you how to do interactive Grass shader in a simple way.
- We’re going to use Shader graph and C#
- We’re going to use URP, this is also Works HDRP or LWRP
- You need basic knowledge about C# and shaders programming
CREATING THE FOLIAGE MESH
First, we’re going to create the geometry and textures of our foliage, you can use any software you want for modeling like Maya, Blender, 3Ds Max, etc. But you have to be careful with the next thing:
You have to paint the mesh vertices, black vertices on the root of your foliage (this mean that the root is not going to move) and another color for the rest of your mesh (RGB or just White), these are the vertices that are going to move and interact with the player. Here we are just telling to our foliage what part is going to move and which none.
GET THE DISTANCE BETWEEN THE GRASS AND THE PLAYER
And finally, add a 'DISTANCE' node to get the distance between both objects.
Let’s proceed to divide the result by a float variable that you can call as you want, in my case I will call this “RADIUS”, and I will convert this into a property that I could manipulate from the inspector.
GET THE PLAYER'S DIRECTION VECTOR RELATED TO THE GRASS.
WRITING THE C# CODE TO OBTAIN THE PLAYER'S POSITION
FINISHING THE SHADER