PCG Programming in NMS - Mining Down for Resources


An interesting question was asked on YouTube on @MacForADay 's Channel regarding mining down for resources in a future update. The great minds on this forum have a lot of knowledge on how the game is built. I’ve added my initial thoughts on the problem, I’m no expert, and I would love to hear your thoughts on this subject. So. Actually mining down for resources rather than gathering them on the planets surface…this was my reply to @MacForADay

Mac, I’m not actually sure whether one of these suggestions is possible in the games current state. Mining down. Because of the way the planets are created, terrain is laid on to a cube, then that modified terrain is then wrapped onto a sphere creating pinching at the sides furthest away from the player. This I think is where the poles of the planet are placed. Also the reason why you will always achieve planet fall on the equator. Also, the mining depth according to SM was 128m. Considering all of the terrain is 36 x 36 x 36 voxals with each one being populated without knowing the content of every other voxal surrounding it. The further down you go, alters the order each voxal is populated. I think. Also, if you shift the entire array of voxals in relation to the horizon down a few levels to accommodate the extra depth, you would lose that terrain from the top of the array, flattening the height of peaks somewhat. This could possibly be compensated for by extra domain warping or other techniques, but any extra generation comes at a cost. I’m not an expert, but initial thoughts on mining further down would cause a lot of unforeseen problems I think. Remember the bug when you drop through the terrain after getting out of your ship? @DevilinPixy some other great minds on the CSD forum will definitely be able to tell us more…

I also would like to say, I may be wrong on how this is all done, I’ve worked out what I know without seeing any of the source code. RayRod I would imagine will know a lot more about this I’m sure.


I think the giant mineral eggs underground where their work around for this, they gave us something to dig down for at least, though most times they break through to the surface.

I’d like the scan of underground minerals to stay on the screen a little longer, they disappear before you can turn around and see what exactly is under you, or before you can get a true lock on its location and mine towards it (boy am I glad the days of mining via grenade launcher are over! though I miss mining iron from stalagmites in bulk via grenades, or have they fixed that glitch?).

Personally I’d love to see more stuff to mine for in caves. Also water tanks for growing rigogen (also more minerals in the water so we’ve more reason to dive would be nice, and more reason to have water tank farms!).

If you’ve playing since vanilla, you’ll notice things like Marrow Bulb have always been present, just weren’t made mineable until that resource had a purpose in the game with 1.1.

Theres a bunch of other stuff that looks mineable in the caves, but isn’t. It’s just decorative, as well as some stuff on the surface too that I have a feeling will one day house resources for us to crack in to.


First of all, I’d like to post the 2017 GDC talk Innes McKendrick did on Continuous World Generation. After reading your explanation, I believe this is for a great deal actually based on that talk and it would be good to have the resource available. It has most likely been posted elsewhere already, but Discourse has yet to implement a way to index such embeds.

Now to give me my thoughts on actual mining by going down into the terrain. This is certainly possible, within of course the limits you mentioned, which is the 128m height range HG decided on, resulting in acceptable distortion between sphere calculations projected on a cube. The terrain is broken down into 1 meter voxels, resulting in a 6 byte voxel size to store density, 2 material types, and blend information. So basically adding additional terrain that can be mined, whether existing or new types, is certainly possible, within the range mentioned above.

However, the rendering described, is mostly surface rendering, while we are discussing resources hidden below the surface. This extra data needs to either become available and be rendered once you reach it, or pre-rendered ahead of time to already be available even though not visible yet. At least some data will have to be available for such a terrain resource to exist in the first place. I assume this can be done similar to dungeons or caves or the other terrain minerals we already have, like Emeril, Gold, and alike.

Speaking of dungeons and caves brings me to another type of resource. We can of course consider a resource to be similar to terrain, but it would also be possible to have mineable resources as actual objects. This would require a somewhat different approach of course, but is very well possible too. Most of the resources we find on planets, I consider to be actual objects. You fire your laser at them and they start giving resources until they disappear once emptied. Then of course there can be objects that require interaction to be added to your inventory, like the vortex cubes or albumen pearls. I certainly think it would be possible to actually have any of the objects I mentioned, ‘buried’ inside the terrain. The same generation limit is of course still in place as to how deep they can actually be buried.

Either way, I think performance impact does not have to be big, although there are of course always limits in the amount that can be (pre-)rendered. The techniques required are already being used, so I certainly think it would be possible to accomplish mining as discussed here. It may just require some shifting around in numbers of other existing things, if render limits are already reached. Maybe decrease the number of creatures or other resources a bit to make place for additional terrain/object mining.

As for falling through the terrain when getting out of your vehicle … I have yet to experience this myself. This is usually caused by the terrain not being fully rendered, leaving a hole. Likely caused by performance limitations reached. In all honesty, I do mostly see this happen on console or low spec PCs, no offence meant. You are however correct that mining we talk about, will likely cause some additional issues. Falling through the map has certainly happened to me, mostly in places where I have either tried to mine, or use my my terrain manipulator. There are still some bugs around when it comes to properly filling up polygons when terrain has been removed. I have noticed this to often happen on boundaries between different terrain types. Of course the terrain manipulator can have some weird results anyway and can use some improvements next to it.

@toddumptious I certainly agree with wanting more variety in dungeons/caves. The resources and looks are pretty much always the same for every single planet. Although mining into the ground, looking for hidden resources is interesting, I’d rather see them work out caves some more first, or maybe a combination of both. Making further use of the ‘ceiling’ for actual resources to gather would be welcome too. In general, I wish caves to get some loving, more variety of resources, looks, ands creatures.


Your vast knowledge never fails to disappoint @DevilinPixy I am fascinated by PCG and more specifically how generation priority is determined. Innes McKendrick would definitely be an interesting dinner guest…


The reason I ask this is a thought that has been buzzing around my mind the last few days. If you cannot know the contents of the voxal until it is populated, could you use a probability algorithm to effectively guess what the adjoining voxals could be and based on those guesses, prioritise generation from there. I feel like I could be on the verge of something fundamental to the way priority is determined. Ideally, the quicker you can know something the better, and ideally more that can be achieved locally or ahead of real time is so important…I feel like I’m missing an important piece of the puzzle. The resource array population is straight forward, but I do think the order that everything is generated could possibly be improved which could improve performance, especially on console with the limited hardware.


Just a few quick links for those interested in some interesting reads, check the below:


Thank you, I’ll tuck straight in…


Basically prediction would mean looking into the generation algorithm to be able to estimate what comes next. It would require resources to do so and the higher the accuracy of the prediction, the more you actually start to use the algorithm itself. With high accuracy, you would basically change your location to where you want to know what is going to be rendered/generated. There are certainly performance limitations, which is why only an area around you is being fully rendered, with lower LOD the further away. Innes explains this quite detailed in her talks. Terrain will always render first, going outward and front first. Other objects and creatures are placed after. Further away objects are often placed at an estimated location, to actually find their precise location once near enough. This is done in such a way it is least noticeable and preferably not seen at all. I am sure they handle priorities very well when it comes to order of rendering and are often forced to settle for ways to least impact performance, while still looking ‘good enough’. In a perfect world where performance would be no issue, the whole universe would render in full detail without compromises being needed. I think that may be the puzzle piece you are missing, although I could be wrong. This is the toughest part of creating the game you dream about, because you are forced to compromise. I am sure HG and basically every developer tries their best to find ways to improve, just to keep performance acceptable. With us still getting new content, I believe this proves they still find ways to improve.


It certainly is a puzzle. Compromise will always have to be struck. I suppose in an ideal world the most realistic look would be an almost homogenous generation with everything happening almost simultaneously but there are always limitations. I’m definitely going to do more reading on the subject, it’s a fertile area for research especially with the almost arrival of quantum computing, things are going to change very quickly I think…


Quantum computing is certainly improving and may be very useful for game development and users like us. At the same time I think it will still take quite a while before we see quantum computing being implemented on a large scale and available in our every day technology. I personally think the change will be gradual and not used in our computers for at least another 20 years or more. Biggest problem is containment and interference while at the same time interaction and making meaningful use of the data it provides. Still a ways to go, but certainly looking promising.


Totally agree with everything you say. I think once we get our heads fully around what can actually be possible then development will be made. It’s so much in its infancy, the possibilities won’t be known for a few years yet…fascinating subject though…


As a PS4 player (with minimal code experience so bare with me), I’ve found this graphic fault to directly correlate to the amount of terrain tecture & fixed objects in the vicinity of the player, which makes perfect sence as the process of rendering takes longer the more features there are.
The more caves, rocks , plants, grass etc. In the vicinity, the longer I must pause in-ship prior to exiting to avoid ‘fall-through’. Patience solves this issue & for me watching to ensure grass has rendered truly seems to be a good visual reference.
I’ve noticed that a player’s base will increase the likelyhood of the issue, whereas an NPC base on its ‘pedestal’ landscape never has the fault, which I presume is due to the NPC structure being a single object as opposed to a player base being many objects.
On regular occasion I witness a ‘tile’ of landscape that is delayed in its rendering, despite the terrain beyond this point already filled in.
What I don’t understand is why on occassion this missing ‘tile’ is located in a player base area when it seems the NPC base areas are immune to the fault. Is there a different code/layout for these two different locations?
Sorry, I’m using basic terminology but I’m not a coder :grin:
On 2 occasions I’ve left a base location simply because the last ‘tile’ to fill was smack in the base location, resulting in regular missing terrain. This resulted in regular 'fall-through and often the render seemed to be further delayed because exocraft would be sort of stuck in the rendering terrain bouncing about as if they were caught in a mechanical pinch point.
I was wondering if you code-cluey people could shed some light on this variation in consistency during rendering?


I think these ‘missing tiles’ are actually a bug and not a result of performance issues. For some reason they just don’t render, so giving it time does not always solve it. I have no clue what the actual cause for this is, but for some reason the game likely thinks it does not need rendering. I would have to actually observe such an issue to maybe be able to come up with a possible reason. Thinking of other times where terrain just fails to render, makes me think it may have ‘missed’ its chance. Sorry, I tried, but failed, not going to try again unless you force me to …

Sometimes extensive testing will give me clues, other times bugs like that leave me totally blank, not having a clue at all. Knowing the full source code AND understanding all of it will sure help, so hopefully the many reports of this issue will be useful for the developers to fix it.


Yeah it’s like the array gets one chance to have all of it’s attributes assigned in order block by block, if one for some reason misses its slot, there’s no going back to it and the renderer can’t render what it doesn’t know…


By the way, the terrain that comes with a structure, like for example a base building area is certainly different. It is not part of the initial general terrain generation, but generated separately once structures are added. This is why it looks different, circular and flat. I do not exactly know how this is done, but can be achieved in several ways.


Of course you’re right about terrain around bases. I completely forgot that it’s generated separately from the rest of the terrain. This will take a lot more thought and research methinks…


Well thanks anyway.
I’ve learned to accept the various quirks & enjoy looking at the game from an accepting point of view.


Me too. Quirks and bugs in the game are inevitable and add to the games character. I’m wondering about base terrain creation now lol…Once one building is placed, the other buildings positions can be plotted from the POV of the player, so closest first within the array according to the laws of item placement driven by the algorithm. I think all this information is determined and stored from that first position. But the scheduling if this rendering could be the source of the glitch. The same with the resource array. I mention this for the low flight glitch where a massive block of heridium suddenly materialises in front of you and you can’t avoid hitting it. If resource deposits can be plotted, confirmed, prioritised over other item placements and rendered first, it could possibly avoid this issue. Especially if this data can be determined at known distance out from the player consistently. I’m not completely sure about all this because I’m theorising from what I think I already know lol. Even I’m confused now…


I got my head turned around trying to theorize how many templates the worlds of NMS are based off.
Obviously the 2 sizes: moon and planet.
Then there are the tube-stone, mountainous, ravined, flat with peaks and rolling hills types with probably a few variations of each plus a few in the middle. So lets say there’s 15 base templates. Then you generate it from 10 or different orientations so there is minimal chance you would recognise the landscape unless you fluke landed in precisely the same spot in succession. This then gets masked behind all the biomes, plants, colours and the general biome variations. Very quickly you get into the huge number of possible variations.

I have an in game pic of a naturally generated cave on a tube-stone planet. It’s uniquely destinctive because of its teardrop shape and the fact exterior plants are growing in the cave. A natural non-generated cave caused by the tube-stone structure intersecting with another tube-stone structure.
I’m forever looking for its clone elsewhere on tube-stone worlds to see if my theory holds water.
On worlds this size its unlikely I’ll ever find it even if it does exist but it’s fun looking…you never know.


Well thank you for taking so much thought and consideration into this; I didn’t think my little passing idea (which was originally inspired by ROBOTBOY, whose video I will post below) would spark so much conversation.

Like Todd said, there are some underground resources, though they usually take the form of empty bubbles with a little resource on the outside of them.

Regardless, I would like it if we could mine all terrain with our mining laser and it would give us trace ammounts of whatever elements the planet contains, even if the elements don’t change further down. In addition, this would make it so autonomous mining units could be built anywhere on a planet’s surface.