Tested on: Windows 10, Intel Core i7-7700HQ CPU @ 2.80 GHz, 8GB RAM, NVidia GeForce GTX 1050
The goal of this project was to simulate real time grass movement in Vulkan. This project is an implementation of this paper.
- Gravity Force Simulation
- Recovery Force Simulation
- Wind Force Simulation
- Orientation Culling
- View-Frustrum Culling
- Distance Culling
The hardest part for this project by far, was just getting something to show up. Like, just anything. Because I did not have that much experience with Vulkan going in, debugging errors was annoying. There were many points where my errors were due to me not completely finishing the code but I couldn't figure that out. This caused me to go on a wild goose/bug chase for many hours for no reason. Once I had just basic grass showing, the rest was straight-forward implementation of the paper. It took me 5 days to get this to show up:
Fairly easy and straightforward. Once I had done it, things started to show up. It looked kinda cool at this point, and I was starting to get excited!
For wind, I just made up a fairly simple 2D-sin function that attenuates the wind vector, wi = (1,1,1)
based on the function value. Here is what my wind function looks like, where z is multiplied by wi
:
This is what my scene looks like with wind:
This isn't really that pretty to look at, and it wasn't pretty to write, but here is what it looks like with an extreme culling threshold:
As you can see, as blades become thinner and thinner with respect to the camera they disappear.
Again, based on the paper. Anything outside the view frustrum is culled since you don't see it. You also add a tolerance value just in case part of a blade is visible. Modifying that threshold to cull more inside, you can see how view frustrum culling works:
This is when you have the tolerance be negative, in my final code I have it be positive.
Fairly annoying to get right, but I was able to. First things first, you can set a max distance to cull all blades at:
But then instead, you can just place the blades in buckets, and then cull more or less based on how close you are, with the farther buckets being culled more, here it is in action:
In the GIF, the farther away buckets are culled more, here is a better side-by-side view of this:
Where as you can see, in the three regions, there is a distinction between the amount of blades we cull. I do this using a pseudo-random function that I got from this StackOverflow thread
It took me forever to get started with this project. For future projects, I really hope we get more experience with Vulkan before being tasked with an assignment like this! I also had a problem where RenderDoc didn't work on my machine because, I don't know... There was a bug in RenderDoc and I had to message the creator to fix it as you can see here. I guess a lot of this was just my dumb luck that RenderDoc only failed on my computer...