I'm still struggling with getting good vegetation rendering performance. Basically, what I have is this:
With the right ground texture and lighting, it looks... okay.
Sadly, the draw distance is limited as hell, and due to this, we basically need to make the grass extremely boring and feature-less so the fading in the distance isn't noticeable. I want faster, taller, thicker, more distinct grass with higher render distance without the performance cost. The current grass takes around 2 milliseconds, half being drawing the grass to the G-buffer (including depth pre-pass) and the other half being the SRAA pass. Basically, the grass is a bunch of flat triangles.
What I've learned so far:
- Do a depth prepass if you're not doing MSAA. It saves a SHITLOAD of time since depth-only+alpha-test is really cheap, and GL_EQUAL depth testing in the second G-buffer pass is literally 4 times as fast. Basically doubles my performance, but it isn't usable in the SRAA (MSAA) pass.
- The shape of the grass meshes matters a lot. At first we had randomly rotated flat meshes, but these looked like crap and tended to lump together. We switched to 3 intersecting quads rotated 120 degrees from each other, which had a more volumetric and even look, but it looked like crap from above. In the end, we went with http://i.imgur.com/h0LilV0.jpg, which looks good from most angles, especially above.
- The area of the mesh is what matters. Even transparent fragments that get discarded by the alpha test are essentially full-cost fragments. We "optimized" our textures to be as little transparent cutout as possible and as much grass as possible to minimize the number of wasted fragments.
- Fading the alpha value of the grass looks like crap with alpha testing, and even worse with alpha-to-coverage. A better solution was to simply slowly sink the grass into the ground, which had less popping and flickering.
- Shadows are completely out of the question. Don't draw shadows for the grass.
With all these tricks, our grass went from 20ms to 2ms at... "acceptable" quality. I still don't like it, but frankly, I'm at a loss at what to do next. Then I see something like this:
And I'm just like "What the hell". The have significantly longer render distance than us, but don't have seem to have any significant performance problems. The grass is also significantly taller, and in Crysis 3 you even walk around with the camera inside it. My guess is that the are rendering those blades as meshes, not alpha-tested billboards. I would like to test that out anyway.
Is there any tools out there to generate a triangle mesh from an image with alpha cutouts? Preferably one that allows for multiple LODs of the same model to be generated.