The landscape now has information in the Y axis(downward), as you dig the tiles change from soil to stone to granite. It’s kept quite simple at the moment but later I want to add further noise manipulation into the algorithm so that the player can find pockets of different types of rock as they dig.
Excavation into the side of a hill
I made some progress on creating tools which the player can use to manipulate the landscape. The excavation tool allows a player to select a rectangular region to dig downward on. At the moment the excavation is done instantly but later it will be dug out by players game units.
I’ve added rudimentary support for voxel volumes.
I had wrote before about GPU picking which worked reasonably well as a temp solution. However the problem is that because the cpu is just reading the positions buffer on gpu, you can’t pick any locations that are not visible on screen. As I was using the excavation tool this became problematic and made the tool unintuitive. Not only that, on my old and useless macbook pro the PBO(pixel buffer object) was still stalling the cpu despite PBO’s being non blocking. The new solution involves casting a ray from the camera through the terrain and calculating where there is an intersection. Works a treat, don’t know why I didn’t just do this before really.
– Refactored the worldgen noise sampler.
– Refactored the precipice mesh generator
– Fixed a bug where the world tiles were actually be rendered mirrored on the Z axis.
– Fixed the camera fog distance from showing unrendered geometry when zoomed in.
– Oncreen nodes now hold a component which links to the underlying world object.
Orthographic vs Perspective
Up until now I’ve had the game camera set up as an orthographic projection. Which gives a similar style to an isometric game but in 3D. I went for this initially because I wanted it to be reminiscent of games like Age Of Empires and RCT. It wasn’t until I started working on the construction tools that I realised how it was becoming difficult to visually understand the terrain and where to place objects. It really doesnt work all that well. Because orthographic cameras have a fixed depth you essentially lose some important information regarding the position and shape of the 3D objects. It makes them slightly harder to understand and also makes it difficult to judge distances in the game world. Games like Monument Valley take advantage of this to create optical illusions and interesting puzzles. For this game though, I don’t want illusions, the most important thing is that the player can understand quickly what is happening in the game.
A slight problem with using perspective camera is that the method for grass rendering I was using did not work as well. As I was using shell rendering It only looks decent when looking downward on the world, with a perspective camera it just didn’t work. Rendering the grass that way was quite costly anyhow, so I had no problem removing it.
New Perspective Camera
I put a little time into getting a working visible day and night cycle. In free floating camera mode you can see the sun in the sky at the correct position. The sky itself now changes color according to the time of day, so for example it will turn orange near sunset. At night the distance fog is changed to give some atmosphere. At night time the focal point of the camera emits light, this makes it so you can still see the surrounding area as well as giving an eerie atmosphere.
I wrote last update about screen space ambient occlusion and how the performance hit was too large to justify the effect. I’ve been playing around with some other methods with some success. I can’t bake occlusion into the mesh because the terrain itself is actually just a displacement map. What I thought of doing however is to calculate the AO by sampling the adjacent pixels from within the displace map for each vertex. You can see the results in the day/night pictures above.
A bit of time was put into the ECS which will manage all the world objects. I put together a placeholder tree model and spawned 10,000 of them around the map. The viewing distance for the trees is not to great in floating camera mode but in normal construction mode It works fine.
Small update this time. I have started working a day job again and so haven’t spent much time on the game. For a bit of fun I’ve been thinking about implementing screen space ambient occlusion, something I haven’t written before. As I’ve been developing and experimenting with the game I’ve noticed issues with my eye being unable identify height and depth of the tiles. Often 2 tiles will sit at different heights but the same orientation, meaning they will be lit exactly the same. Take a look at this example.
The tile in middle is shaded the same as the tile behind. While it’s not difficult to understand what tile is where, It really shouldnt require any thinking. To solve this I started looking into ambient occlusion techniques, I had a form of AO in the game before using an AO value baked into the terrain verts. However, Now I have redone the terrain mesh system making that no longer an attractive option. The most common AO in games is SSAO (Screen Space Ambient Occlusion), there are different implementations but essentially you would use the positions and normals buffer to sample surrounding pixels and calculate if they occlude the current pixels.
I put together a shader which does just that. The results are decent however there is a significant performance hit. I’m using a half size AO buffer and 16 samples, then a 4×4 blur. Framerate goes from about 160 to just about keeping up at 60. I’m sure I could optimize further and improve the method, however I have played round tweaking parameter and even at high sample counts the results are not that great. I think I am going to take another look at baked AO.
SSAO After a lot of tweaking
- Added a way to recompile shaders at runtime so I can make modifications to shader code and see results instantly (Very useful, should have done this ages ago!)
- Improved pipeline for adding 3d models.
- Made headway on ECS for managing game objects.
Nothing too major this update, I’ve been working on some other personal things the last month so I haven’t done anything major on the game.
- Made it so an individual tile will highlight when hovered over with the mouse.
- You can now make square box selections with the mouse by clicking and dragging.
- Added a distance fog for when using the free floating camera
- Replaced black sky color with blue.
- Fixed a z-clipping issue where the ocean mesh intersected the land mesh.
- Optimized terrain rendering for free floating camera. Camera used to sit in the middle of the terrain chunk, now any terrain behind the camera is not calculated.
- Shaders now recompile when using free floating camera and implement a different type of z-buffer.
- In debug mode I can now switch from game camera to free floating camera at click of a button.
- Added more robust terrain tile painting tools
- When a grass tile is sloped above a certain threshold it becomes a dirt tile.
Improvements made to free floating camera, decent enough draw distance.
Drawing onto the terrain
Here is a low framerate fly over of the terrain using the free floating camera.
For me, one of the most important parts of the world generation has to be the rivers. I feel like I rarely see genuine flowing rivers in games, especially not procedurally generated ones. Minecraft and NoMansSky have ‘rivers’ but they don’t really follow any logic, they don’t really flow, and have no clear end and start. This is because the world of minecraft is on an infinite plane and NoMansSky has infinite planets. The terrain has no hard limits, so it’s not possible to do an actual simulation of erosion or rainfall. For me, rivers created from noise generation just don’t cut it, even a very simple simulation of rainfall and erosion is much more interesting.
I always like to get something working as soon as possible. So I started with a dead simple rainfall model. I attach a ‘water level’ value to each tile, then to simulate rain I increment the ‘water level’ for each tile every step of the simulation. Higher points will get slightly more rain. Then, if the water level on an adjacent tile is lower, I move a fraction of water from the current tile to that adjacent tile. I also evaporate water on each tile by a constant amount each step.
Initial simple water simulation
Initial results are quite decent, the noise generation already has decent river like formations and valleys carved into it. So the water just flows into the valleys and looks quite natural.
After running the simulation for 500 steps
Simple beginnings, next step will be to add an erosion model and actually mesh the rivers. Right now, any tile that’s above a water threshold is blue, there is no depth to water, it’s just flat.
I talked before about the improved noise system. I’ve been playing around and experimenting with different parameters, getting some interesting results. The difference between a real island and my fake video game island is that of scale. I want mountains, sweeping rivers, wildly different biomes, all on one island that spans maybe only 1.5 miles coast to coast. So it wouldn’t make sense for my islands to perfectly imitate the natural forming islands of earth. I wouldn’t say the terrain of the islands below look realistic, however these islands might not have even been created using the same tectonic processes. I’ve thought a bit about how far a fantasy world can really deviate from the real world. I think, that If the world looks like it was formed by some sort of natural process then it gets a pass. The real question is weather these maps are fun to play and build on. They definitely provide some nice variation across seeds with each map having some distinctive features.
Below I’ve demonstrated the effect of changing lacunarity on an FBM noise which acts as an input to the frequency of a Ridged Multi noise. So thats one set of noise acting as an input on another noise. Lacunarity starts at 0.0 and increments by 0.1 to a final value of 2.5.
Lacunarity (2000 x 2000)
Below you can see the effect of changing the frequency of the input noise.
The problem with this noise generation is that quite often I get a dud seed, especially when using noise of lower frequency. Sometimes an island will be very small, or overly large. I’m thinking of writing a function which discards maps based on total landmass, then keeps trying new maps until it finds a good fit. I would only need to sample the noise few times, maybe 200 samples, to get a reasonably accurate landmass approximation.
Below is the effect of changing intensity on the input noise. It starts as a sphere because there is a radial gradient subtracted from the noise to act as a falloff. With our input noise having 0 intensity it means that the main noise has a frequency of 0, the noise becomes just a flat color.
Islands with increasing temperature (2000 x 2000)
I’ve spent some time refactoring the world generation and building a useful world generation editor. I think having an actual visual interface to preview the generation in real time will be massively useful. Before, I would make changes to the algorithm in c++, then have to wait while it compiles and launches to see the changes. This is obviously painfully slow and make makes it very difficult to experiment. Now I can manipulate noise parameters in a custom editor and see the changes right away.
Before, all I could do with noise was stack them on top of each other with a blending function (Add, Subtract, Avg, Multiply..). However to get more exciting results the noise parameters need to be deviated by another noise value. So for example, now I can plug ‘Billow’ noise into the frequency parameter of an ‘FBM ‘noise. This kind of perturbation can get really interesting results.
In all but the first post I ever made on the game you can’t see any biomes on the map. I actually disabled biomes because of a bug in the code. I’ve gone and fixed the bug and tweaked the whole biome generation system. I also wrote a script which takes the current world generation parameters and outputs one large image containg lots of maps using different seeds.
These maps above are using the old noise system. The mountains are just kind of splatted on top of the base noise. Next step will be to play around with the new noise system to create more natural looking mountains which blend into the terrain.