Procedural Terrain Generator
A downloadable tool
Hi!
This is my submission for Acerola's Dirt Jam!
This project, implemented in Unity 6 using URP, is a procedural generator of an infinite terrain.
While a brief explanation of what I did will follow, a real-time demonstration is available here:
All the screenshots included in this brief presentation are included at full size on the side of the page. As of now, the generator implements the current features:
- Chunk system: To avoid regenerating the entire terrain on significant camera movement, the terrain is split into chunks, which can be moved and regenerated as required. Every chunk is secretly a flat mesh with a standard resolution, but each of them uses its heightmap, which is updated as requested using a compute shader, to displace its vertices. The following screenshot showcases the AABBs of each chunk:
- Terrain LODs: To avoid generating unnecessarily detailed terrain far away from the camera, multiple LODs are used. Lower LODs have increased chunk size, but the same quad resolution, resulting in a drastically increased render distance with a reduced amount of geometry. The following screenshot showcases the same view rendered at the highest and lowest LOD:
- Biomes: To generate heightmaps, I used FBM. Using additional filters on the resulting noise, I was able to create very distinct terrains, which I used to create biomes. Adding a 2D layer of continental noise (symbolizing moisture and temperature) allowed me to map vast areas of the world to their corresponding biome using a LUT (look-up table). Lastly, I assigned a color palette to each biome to visually distinguish even more between them.
Height and color are blended using a tunable smoothstep function, to allow either aggressive or relaxed blending between biomes.
This system is quite dynamic, and the removal/addition of biomes is fast and easy. The following screenshot is a terrain generated using only two biomes:
- Shadows: By leveraging certain features offered by Unity, I can render the terrain to cascade shadow maps using a custom shadow caster and depth pass, which enables me to render shadows in the vicinity of the camera. I am still working on this, so it is not perfect. The main issue I have been having is a visible black circle between areas covered by different levels of the cascade. The following screenshot showcases the shadowing effect, which is currently capped at 1.5km distance:
- Fog: Using Unity's scriptable pipeline, I added a render pass acting as a full-screen shader to implement depth-based fog. While implementing this, I experimented with SSCS (screen space contact shadow) to simulate the effect of distance shadows on the fog visibility. Additionally, the fog color is influenced by the main directional light, and its density is influenced by a stored noise texture, which mimics the effects of a slow-moving fog. The following screenshot showcases the same view rendered with and without fog (max fog density set at 7.5km)
The following features are still WIP and are far from being completed, but I believe they have reached a presentable state:
- Procedural Scattering: Foliage, rocks, and miscellaneous objects are what truly make biomes distinct. I have a working system, based on the already existing chunk system, that can draw indirectly tens of thousands of meshes and execute culling using a compute shader. However, this system was implemented before the addition of LODs, and I haven't managed yet to combine the two. The following screenshot showcases the mesh culling, and the actual render (using default cubes):
- Water: Rendering interesting water is hard! I tried a bunch of approaches, like mesh-based or a full-screen shader, but I was not able to reach an acceptable. For now, I am using a basic depth-based full-screen shader that mimics a water plane (or at least, it tries to). The following screenshot showcases the simple plane water shader:
Published | 28 days ago |
Status | In development |
Category | Tool |
Author | Mobaster |
Comments
Log in with itch.io to leave a comment.
Okaaay, this looks really great IMO !
Thank you very much :)