Near to far levels of detail include (ordered closer to further):
- Individual curved grass blades formed by tessellating the original triangle into many polygons
- Single triangle, textured grass blades that move in the wind
- Single triangle, untextured green grass blades with no wind
- Larger triangles formed from recursively merging two adjacent grass blades into a single triangle where area = sum(areas) and color = average(colors)
- Coarse triangles that translate down into the terrain mesh with distance until they disappear
- Simple grass texture applied to the 3D mesh surface consisting mostly of green color + noise
A set of 32 grass tiles is generated, and random tiles are selected for use across the terrain. The vertex shader calculates the z-value (height) of each grass blade from the heightmap textures. All vertex data for all levels of detail are stored on the GPU for efficiency. Hardware instancing is used to render all instances of each of the 32 grass tiles in a single draw call.
Here is an example video where I use the camera speed modifier keys to zoom in and out on the grass. The actual rendering is much sharper; video compression has made the grass somewhat blurry. I've disabled the trees, plants, and flowers in the config.txt file to make the grass stand out more and avoid distractions. Without the overhead of video compression, this normally runs at around 300 FPS (frames per second).
As you can see, grass has a nearly seamless transition from a distance of inches to miles. The result is a lush green field that stretches out to the horizon and scrolls to follow the player camera. It's possible to have the entire terrain draw as grass at 150-200 FPS.
Note that the grass colored ground texture is always used. This is here to fill in the space between the grass so that the blades don't need to be packed together as densely to achieve a thick looking cover. The texture and grass blades use the same average colors (across texels) so that they blend together better in the distance. They also use the same normals and shader lighting calculations. To make this work, grass normals are derived from the terrain mesh normals.
Here is a series of images captured of grass, from close up to far away. There are some scattered areas of sand and dirt with lower grass density to break up the scene and add more variety. These can be seen in the last two images. Again, non-grass vegetation and other scenery has been disabled for these screenshots.
The only problem I see with this approach is the tiling artifacts of the distant grass texture. Tiling is most noticeable in the final two images. I spent some time trying to fix this, but never really succeeded. If I use a highly detailed texture, it looks too repetitive. If I use a low contrast green texture, it looks too plain and uninteresting. If I transition between texture scales, the effect is noticeable, and it ruins the immersion. I was able to get away with that last texture scale trick with water because it was moving, but apparently not with grass. Interestingly, this isn't as much of a problem with the rock and snow textures. I wonder what's different about them?
I think using a multi-scale "detail texture" is the conventional way to solve the tiling texture problem. You need to blend it so the individual cells of the large-scale texture aren't noticable, but it kind of looks as if you're doing that already? It might be good to have some sort of weather system (temperature, humidity, rainfall) to tie the foliage color to the underlying terrain. Not sure how much you want to turn this into Shamus' Project Frontier.
ReplyDeleteI already have a detail texture, which is used when the player is close to the ground. Do I need three different textures? Maybe, but that would be an awful lot of texture lookups per fragment. This is mostly a problem when the player is far above the terrain looking down, which isn't all that common except for these types of screenshots. When I enable trees, plants, flowers, rocks, stumps, etc. that tends to break up the repetition pretty well.
DeleteI have a biome system that will make some dry/desert areas, sand vs. dirt shores, etc. You can see in that last image that the shore on the left is dirt, while the shore on the right is sand. Grass is brown in the dry areas, though I'm not sure that's enabled/present in any of these screenshots.
I haven't attempted to simulate temperature, humidity, or rainfall. I'm not sure how to do this for infinite tiled terrain in a way that works across tile boundaries. I could do this for the fixed size heightmap terrains like the ones I used for erosion. These aren't really planets with different zones though, they're big flat planes, so I'm not sure how the climate would work.