JSON Terrain

A quieter space for design discussion of long-term projects
FluffyFreak
Posts: 1343
Joined: Tue Jul 02, 2013 1:49 pm
Location: Beeston, Nottinghamshire, GB
Contact:

JSON Terrain

Post by FluffyFreak »

Due to reading an SoA Article some months ago I decided that it would be nice to be able to define terrain definitions using a structured data format.

Since we already have a loader for it I picked JSON for the data format, and there's a nifty editor called JSONEdit to make dealing with it a bit easier.

The idea itself is pretty simple, you define nodes which can generate noise, provide a constant value, raise something too a power etc.
Each node can perform one of 4 operations (3 in that article) on the data like ADD, SUB, MUL, DIV, in addition to clamping the value.
Each node can have any number of children, and each child node can have it's own children, each call to a child node modifies the previous nodes output in some way until it reaches the last child in the hierarchy.

That said there are some subtleties which are currently kicking my arse :(
In fact that is why I am posting here and now :)

For example the current terrain configuration being loaded is within "\data\terrain\terra.json" which produces some cool terrain however there is a more complete version within "\data\terrain\terra_bak.json" that ... um, goes completely insane and breaks the rendering of the planet so completely that the game actually just dumps you in space somewhere... not a great result.

What would be great is if someone can spend an hour looking through that Call method and tell me if I've done something that is stupid, odd or just confusing. I ask as I have gone a little bit code blind from looking at it and will be resorting to pen & paper now to work through the logic, again.

This code/branch will not be used verbatim!
I don't want to panic anyone so just to make this clear: my branch "terrain-json" is purely for idea development and testing, it will all be completely rewritten from master when the time comes.
In fact you can ignore 99% of that branch and just take a look at the Call method within TerrainNode.cpp as this is where all of the work is done.

Thanks and hopefully once this is working we'll have a way of defining planet types without writing code, and from that, of generating terrain generating shaders again without (much) programmer input.
That's the dream, of opening up all the terrain stuff to non-coders.

Other things:
  • the SoA Article only uses each file for one planet whereas I'll need to, LATER, add a way of re-using them.
  • ignore the rest of the branch, much madness and hacking lies in there, stand well clear - comments on those parts will be ignored :P
  • I am very aware of NevilClavain's similar work - yes, I am jealous.
  • The mistake is probably simple, I have mostly likely just been dumb.
Andy/FluffyFreak
FluffyFreak
Posts: 1343
Joined: Tue Jul 02, 2013 1:49 pm
Location: Beeston, Nottinghamshire, GB
Contact:

Re: JSON Terrain

Post by FluffyFreak »

One possibility is that I should be doing the clamping, scaling, or both after the operation on the accumulated value.

So instead of:

Code: Select all

	localH = m_bClamp ? Clamp(Scale(localH), m_clamp.first, m_clamp.second) : Scale(localH);
	
	// wtf?
	switch (m_op)
	{
	case TO_ADD: accumH += localH; break;
	case TO_SUB: accumH -= localH; break;
	case TO_MUL: accumH *= localH; break;
	case TO_DIV: accumH /= localH; break;
	}
maybe it should be:

Code: Select all

	// wtf?
	switch (m_op)
	{
	case TO_ADD: accumH += localH; break;
	case TO_SUB: accumH -= localH; break;
	case TO_MUL: accumH *= localH; break;
	case TO_DIV: accumH /= localH; break;
	}

	accumH = m_bClamp ? Clamp(Scale(accumH), m_clamp.first, m_clamp.second) : Scale(accumH);
Or even split?

Code: Select all

	localH = Scale(localH);
	
	// wtf?
	switch (m_op)
	{
	case TO_ADD: accumH += localH; break;
	case TO_SUB: accumH -= localH; break;
	case TO_MUL: accumH *= localH; break;
	case TO_DIV: accumH /= localH; break;
	}
	
	accumH = m_bClamp ? Clamp(accumH, m_clamp.first, m_clamp.second) : Scale(accumH);
I need to find time to work the "Rivers" example chunk out on paper as it's the most mangled by these operations.

Andy
FluffyFreak
Posts: 1343
Joined: Tue Jul 02, 2013 1:49 pm
Location: Beeston, Nottinghamshire, GB
Contact:

Re: JSON Terrain

Post by FluffyFreak »

Progress is probably the wrong word, I think I've been getting a lot of this wrong :(

Looks like I'll be reworking it quite significantly. Dammit.
impaktor
Posts: 1007
Joined: Fri Dec 20, 2013 9:54 am
Location: Tellus
Contact:

Re: JSON Terrain

Post by impaktor »

Look on the bright side, that in a way you've found the bug.

Also, this way, you'll have fun the whole weekend! ;)

Sorry I can't be of help here. (even if I had the time, it would be beyon my knowledge, I suspect)
FluffyFreak
Posts: 1343
Joined: Tue Jul 02, 2013 1:49 pm
Location: Beeston, Nottinghamshire, GB
Contact:

Re: JSON Terrain

Post by FluffyFreak »

Yeah it's just frustrating, I think that I'm actually over complicating it, or maybe making it less hacky than it will end up being. I'm just missing ... something, about how it needs to work. It's very annoying.

The idea is to define nodes, each node does something, call's it child nodes and eventually you end up with a height value.
Really it should not be too complex but somehow I'm cocking it up!

Well, will try to find some time this weekend again.
impaktor
Posts: 1007
Joined: Fri Dec 20, 2013 9:54 am
Location: Tellus
Contact:

Re: JSON Terrain

Post by impaktor »

Best of luck! Would be sweet if you pull it off!
FluffyFreak
Posts: 1343
Joined: Tue Jul 02, 2013 1:49 pm
Location: Beeston, Nottinghamshire, GB
Contact:

Re: JSON Terrain

Post by FluffyFreak »

Ok, 50% of the way there, i had completely misunderstood the order and implications of some parts and have gotten that mostly resolved for the simple noise and mixing operation logic.

The last 50% is all of the constant and special operation nodes which I haven't quite understood so far.
FluffyFreak
Posts: 1343
Joined: Tue Jul 02, 2013 1:49 pm
Location: Beeston, Nottinghamshire, GB
Contact:

Re: JSON Terrain

Post by FluffyFreak »

In fact I may omit the special stages entirely for now and solve other problems first!
FluffyFreak
Posts: 1343
Joined: Tue Jul 02, 2013 1:49 pm
Location: Beeston, Nottinghamshire, GB
Contact:

Re: JSON Terrain

Post by FluffyFreak »

Ok, anyone wanting to follow along can do so here https://github.com/fluffyfreak/pioneer/ ... rain-nodes
sturnclaw
Posts: 82
Joined: Tue Sep 18, 2018 12:20 am

Re: JSON Terrain

Post by sturnclaw »

@FluffyFreak: How's the state of the branch? Are we looking at being able to merge this at some point in the near future?
Post Reply