A grass simulation in Vulkan.
This project implements the paper Responsive Real-Time Grass Rendering for General 3D Scenes, including Bezier curve grass blades, physical models for grass motion, and culling.
Grass is represented as Bezier curves, where
To draw the grass, vertices from the initial quad is refined through the tessellation shader. First, two separate Bezier curves are generated for each side of the grass blade. Then, the vertex position is determined by interpolating between the two curves.
Grass motion is modeled as displacements of the grass tip
🌎️ Gravity
Gravity is simulated as a combination of environmental gravity and frontal gravity:
🌬️ Wind
The deflection of grass due to wind is modeled as a function of wind magnitude and grass alignment with the wind direction:
Wind vector is modeled as a function of position and time, and it is layered using progressively smaller sinusoids.
🪃 Recovery
Elastic forces that help the grass bounce back is modeled using Hooke's law:
To allow for fast simulations, grass blades are culled through a combination of orientation culling, frustum culling and distance culling.
Orientation Culling
Grass blades that are not facing the camera are culled. This is done by checking the angle between the camera direction and the grass blade direction.
Frustum Culling
Grass blades that are outside of the view frustum are culled. Culling is performed by checking the intersection between the grass blade control points and the view frustum.
Distance Culling
Grass blades that are too far away from the camera are culled.
Let's analyze the impace of culling and number of grass blades on the performance of the simulation.
All Culling
Number of Grass Blades | FPS |
---|---|
2^22 | 34 |
2^20 | 90 |
2^18 | 250 |
No Culling
Number of Grass Blades | FPS |
---|---|
2^22 | 9 |
2^20 | 32 |
2^18 | 100 |
Orientation Culling
Number of Grass Blades | FPS |
---|---|
2^22 | 9 |
2^20 | 30 |
2^18 | 80 |
Frustum Culling
Number of Grass Blades | FPS |
---|---|
2^22 | 35 |
2^20 | 92 |
2^18 | 250 |
Distance Culling
Number of Grass Blades | FPS |
---|---|
2^22 | 8 |
2^20 | 32 |
2^18 | 78 |
From the analysis, it appears that frustrum culling has the most impact on FPS. This is likely because in a large scene, the vast majority of blades will be hidden from view.
bash build.sh debug
cd bin && ./vulkan_grass_rendering