Hey everyone!
I just wanted to show off my progress working on procedural voxel generation in UE4. Ive only spent 4 or 5 days on this but Ive made some pretty good progress on it, but it still isnt much. The voxels are 50^3 UUs each and uses 2D Perlin noise with bilinear interpolation for the world generation, it takes in a seed, X, and Y coordinate then pops out a Z value to use. The code then takes that position and checks the positions of the surrounding voxels and adds the visible vertex positions relative to that position to an array of triangles. It then loops that for each block in the chunk (32x32x4), and when it is done with that chunk it renders the stored triangles. The process then starts all over for the next chunk. Originally I was using Instanced Static Meshes for the chunks but that took too much RAM so I changed to dynamically generated meshes, which cut back on the RAM usage tenfold. The map can generate infinitely but I dont have chunk streaming (or whatever I should call it) in yet, so I have to specify a static map size. Eventually Ill also get around to adding in a third dimension for the noise generation as density to make cool overhangs and caves, but right now Im working on fixing a few bugs in it and optimizing the whole process. So far on the optimization front Ive finished removing the unneeded polys and verts, the ones that were between other voxels, effectively tripling the world generation time (~.3 - ~.5 seconds per chunk now down to ~.1 - ~.2), tripling the FPS and cutting down the RAM usage by about 2/3rds (~2.5gb down to 800kb for a 512x512 map). In the coming days I should have that all fixed on top of chunk streaming based on the camera’s distance to the border of the playable chunks and report back here to show my findings
If you have any questions on how I did it (or how I will do the future features I have planned), feel free to ask away. I didnt know a thing about perlin noise or dynamic mesh generation going into it, I spent a lot of time crawling the net to learn about perlin noise, and crawling the docs and forums for how to implement procedural meshes in UE4. Id also like to give a big thanks to any people from the community who posted on the forums and wiki about dynamic mesh generation!
Here are a few screenshots with various world generation settings that I just whipped up on the spot. As I said before, Ill add in 3D Perlin noise later, although the 2D right now is still pretty cool with the right settings. I have no clue how these specific settings will look but here they are anyway (All are on 512x512 block maps):
Smooth Map:
Seed 111111, 3 Octaves, 4000x zoom, .5 roughness, 10 intensity
Rough Map:
Seed 111111, 5 Octaves, 1000x zoom, .5 roughness, 10 intensity
Hilly Map:
Seed 206434, 3 Octaves, 4000x zoom, .5 roughness, 30 intensity
(Sorry about the grid in this next one, I forgot to turn on Game View)
UPDATE:
This is the result of the optimization I did today, because of it I was able to extend the visible map by quite a bit and retain good framerate and memory usage. On top of that I also played around with the terrain generator some more, adding a few more options to it for a more playable landscape . This will probably be the view distance I aim for when working on infinite terrain. Also I was mistaken, the 900mb RAM was for a 512x512 map, this was taking about 1.75gigs of RAM during PIE which is still pretty good for the size of the area displayed at once.
Thanks for taking a look at my procedural voxel terrain! Ill be working on new features for it soon!
~Adam
Also Id like to thank to vblanco for helping me out with this! Hes taught me quite a bit about this sort of stuff