Grass - Blade - Grass - Shader Learning

Grass

Grass - Blade

Task

Given a mesh consisting of 20 vertices, initially all vertices are located at the origin. You need to move the vertices using their index to form a block on the screen with a total height of 1, consisting of 9 equal rectangular segments.



Then change the width quadratically based on the current height, starting from 0.1 at the base and decreasing to 0 at the top.

Theory

In a mesh consisting of 20 vertices, 9 adjacent rectangles are formed, stacked on top of each other. The height increases every two vertices, so to determine the current height, you need to identify the pair number first and then divide it by the number of rectangles to find the height of the pair.



Furthermore, it can be noted that all even vertices are on the left, while odd vertices are on the right. Therefore, the parity of the vertex index can be used to determine the direction of the shift along the X-axis.


The width should vary quadratically based on the current height. This means that the width will decrease parabolically from 0.1 at the base to 0 at the top.


The formula for calculating the width can look like this:

width = 0.1 * (1.0 - height * height)