We calculate two other points, one on each side of the midpoint.We calculate a random point in the triangle using this technique.We get random numbers based on the world position of the triangle’s vertices.We get the normal vector of the current triangle and the number of grass blades we’ll spawn (based on distance from the camera).The blade generation algorithm is as follows: The grass blades will be colored via a gradient map using their custom-assigned vertex colors and they’ll also have an additional color from the wind, giving a glossy impression as they sway around.The grass blades will sway based on a displacement texture, resembling motion via wind.Depending on the distance from the camera, the shader will generate less grass blades, for some minor optimization.The shader also calculates new UV coordinates for the generated grass blades.
The set maximum number of grass blades for now is 15.
In the next part we’ll add that stuff and some more, but if you’re in a hurry to see how to add these stuff, I highly suggest Roystan’s grass shader tutorial. The shader I’ll be showing here is more on the stylized side, and is actually completely unlit and unresponsive to shadows. The result obviously depends on the work you put in the effect. In the previous tutorial we saw some stuff around geometry shaders, which have a lot of really interesting applications, and grass shaders is one of the most popular ones! Grass shaders, like water shaders, can be infinitely fun and you can pursue any level of physical accuracy you want, from something toony or stylized to something realistic af.