r/GraphicsProgramming • u/UverseDev • 58m ago
Procedural Wildlands: how the grass, trees, stones and clouds are rendered
Wildlands runs in the browser through WebGPU and natively through DirectX 12 or Metal, using Rust, wgpu and WGSL. The vegetation, stones and clouds are generated in code. :) So therefore, not a imported 3D models.
Grass/Foliage and wind
In the CPU, each blade is rebuilt every frame from a stable hash, so this allows that it can come back in the same place without needing to store mesh for each of its blade. And Compute, in GPU, passes the selection and compacts the plants, and then prepare a indirect draws.
Vertex Shader is building each blade as curved Bézier shape and bends it depending on the wind strengthness and direction. At my testing with profiling, it showed that separate compute dispatches cost more than the extra indirect draws, so I was combining the plant types into one dispatch (at least, in my macOS machine).
Yes, the grass also thins out with distance (LOD), so, the remaining blades get wider to keep the field from the looking bare.
This line comes from the vertex shader excerpt:
let fuller = pow(1.0 / max(keep, 0.12), 0.6);
Each blade also has their own stable rank, so it gives a gradual fade around the cutoff.
The wind itself is from two layers of moving noise, so its pretty much simple and basic. The tree leans, branches moves, and flutters the leaves. Even a gust moves through both the meadow and canopy.
Related reading:
- Eric Wohllaib, Procedural Grass in Ghost of Tsushima, GDC 2021
Trees
Trees and bushes uses "space colonization", and branches grow towards attraction points inside the crown, and the points disappear once reached. With clustering with nearby groups on the crown surface gives then the silhouette separate lobes, instead one smooth blob.
Trees also uses LOD here, at further away, leaf cards and cheaper bark shading takes over, and the lost LOD level uses a card built form eight views (Imposters LOD) to maintain high details while very low vertices count.
References:
- Runions, Lane and Prusinkiewicz, Modeling Trees with a Space Colonization Algorithm, 2007
- Shinozaki et al., The Pipe Model Theory: Basic Analyses, 1964
Stones
Stone is pretty much simple here, it starts as sphere grid displaced with 3D value noise. And then there is random planes cut to get "flat surface" for the stone. Normals leans towards the cutting planes so the faces looks fractured instead just "rounded".
The material uses procedural triplanar mapping, with moss shells on upward and weather-facing surfaces.
Clouds and sunlight
Clouds was a bit of challenge to implement, clouds are raymarched into cached 4096x1280 sky image, split into 8x4 tiles. With a steady view, one tile updates like only every third frame. A fast camera movement or cloud changes triggers several updates per frame. Unfortunately, this isn't perfect yet and sometimes you will be able to see some traces of imperfections / cuts at the cloud yet...
With the cache, it stores the cloud distance along with the color and fullscreen pass uses that idstance to re-project the clouds for the current view and movement since the tile was drawn.
New tiles fade in over a few frames very slowly and in chunk-ways.
As for lightning, I was using combination of "Henyey-Greenstein-form" lobes with a cheap multiple-scattering term, so then the cloud can still keep the base pale grey. Grass / trees from the shadow uses a separate cloud-shadow texture.
And the sun shafts are marched through the shadow maps, with cloud shadow included!
For background on volumetric cloud rendering, The Real-Time Volumetric Cloudscapes of Horizon Zero Dawn, SIGGRAPH 2015:
https://www.guerrilla-games.com/read/the-real-time-volumetric-cloudscapes-of-horizon-zero-dawn
----
Explore this demo in your browser (or... simply download the files to run natively in Windows or macOS!):
https://share.uverse.dev/kpHWOGxHMldiZyBFWuRLY_X7ctE4A5WLZI-FuDM081w
AI disclosure: Orbit created the scene under my direction, with the papers and references I found. However, I've written this post by hand manually!
If you have question, I'd be happy to answer it! :)



