GPU Instanced Grass in Unity
For the original post, please go to https://www.yuque.com/qwerasdwww/dfy5xd
Part 3: Add Interaction with Character
Let's add paramters of the interaction.
We use the character position to determine which area of the grass needs to bend, and the trampleRadius to control the size of that area.
We add a new parameter called quaternion inside the grass struct to calculate the bend.
We also need to fix the size of the compute buffer.
We now do the calculation inside the compute shader.
Now we use the value we get from the compute shader to calculate the acutal shape of the grass inside the V/F shader. We calculate the corresponding matrix of the quaternion and use this new matrix as our new rotation matrix. And we apply the new matrix to vertex and get the bended shape of the grass.
We use the variable trample to track down the grass bending.
This trample value will give us a grey scale 0-1 value. We will use this value to calculater how much should the grass bend based on the distance from the character.
We add trample to the grass struct in the C# script, and add the size of the compute buffer.
No comments:
Post a Comment