Procedural 3D World Map based on Shader
Goals:
- the map is randomly generated within values boundaries
- the map is divided by grass, rock, sand and water
- the map is realistic (topography, textures)
- the map is alive (wind, animals, trees and vegetation)
- the map can be saved
- the map is optimized
Challenges:
- using the map as value at runtime instead of a grid system
- finding the right algorithm for a realistic topography noise
- complexity of the shader
- finding a good nanite parameter recipe that would keep the shape of the terrain – > Nanite is disabled for now
- creating a mesh at runtime for the terrain using the shader information in order to have a collision mesh matching the vertices.
2023 September : First pass of the terrain shader
2023 October : First pass of the 3D Terrain affected by the shader
It’s clear that the base noises for mountains and sand require refinement. It’s likely that I will have a better outcome with voronoi noise. Although the mountain noise did not match the island’s shape, the noise from September was a better iteration. The mountains’ shapes were more realistic at least.
The polycount of the terrain mesh is a big issue. It is also one big mesh, so the LOD system cannot be applied. Many hours have been attributed to find the correct settings for nanite with the mesh as-is and the best solution was to disable it.
For optimization, I will have to segment the terrain and find a solution to use the LOD system while keeping a good landscape resolution and avoiding any seams between segments. Not sure yet how the mapping would be done without losing any UV resolution. However, if this LOD system works, I might be able to tesselate the polycount a bit more for really close renders. Switching the mesh to a nanite version when only one segment is visible in the screen could be a good approach too if the transition is seamless.
The size of the mesh is still reasonable. I plan in my project to generate a map about 25x bigger after the player finally conquers the island. On top of nanite and LODs I will need to use level streaming or this game will only serve as a computer parts smelter.
2023 October : First pass of the trees affected by wind
Trees can now be affected by wind and seasons. The season system is not supported yet and has been implemented on a switch only for testing.
For now, trees are nanite. The culling seems fine and to the eyes, there is no issues. Although, I am not sure about performance when I will spawn close to a thousand of them in the map.
Again, switching to an LOD at distance could help with that. I feel like nanite cannot replace the LOD system entirely yet, especially when dealing with game or sims that needs resolution from a mesh far away.
2023 October : Finally managed to spawn actor using render target
Using render target, it can read each pixels and spawn an actor if it matches a specific color. In this case, I chose the dark green color as source color. Multiple colors can be selected, with their own thresholds and their own logics. Reading render targets is usually a no go at runtime since it is waterboarding the CPU with requests. The function is called when the map is loading, when the player creates a new game. All the information of the terrain will be saved (resource location and depletion, terrain shape and topology, etc).
Created spawners that spawn resource inside a box area. I needed to add a collision to the terrain, so I needed to test without any height in the shader. The moment I added the collision, the frame rate dropped significantly. The camera is not fluid anymore and this is with only 2 trees per spawners. When I selected 6 trees, unreal crashed… I will have to work on the optimization of the terrain sooner than expected.