Procedural Terrain Generator

Community Forums/Graphic Chat/Procedural Terrain Generator

Bobysait(Posted 2016) [#1]
Absolutely unrelated to No Man's Sky ( ;) ), I'm working on a procedural terrain generator.
I intend to create a visual node editor and have already implemented some features (perlin noise, voronoi, diamond algorithms)

Currently, still not sure how I'll implement the modifiers in the UI.

- erosion filter -

( source image is generated with the perlin noise generator )

- nodes UI -


- Realtime sample (quick and dirty with poor textures and look) -


Not to mention, it's rendered with the Bigbang engine.
Be patient, it will be released in few weeks (once the collision module is fully finished and featured).


RemiD(Posted 2016) [#2]
Hey :)

This looks good (except the blue stuff imo), (i don't understand what the "rain map" is supposed to be)

Can you tell us more about how a terrain is structured (one height each 1x1z ?, heights between 0 and 255 with a "heightmap"), and if there are lods and stuff like that.


Bobysait(Posted 2016) [#3]
The terrain in the last screen is just a grid elevated with the height array.
Heights are stored in Double[w][h], so it's not limited to 0-255 values.
There is no format at the moment for any kind of export, but ... there is at least two ways to export :
- the final array as double/double (with some zlib compression)
- export the stuff that generate the final array (hudge terrains stored in few octets, but require to be computed at runtime)

There is no terrain algorithm implemented in the engine, because there is no way to distribute a "good" generic method that will support every thing, every users can want. I will just publish at least 2 kind of working algorithm as external modules. One with chunked LOD, the other one with tesselation ( like the blitz3d terrain )

But at the moment, I didn't spend any time on it. And, I really don't think (I'm strong enough nooow ...Do you beleiiiiive in life after love ?) terrain algorithms are really usefull for many codes. (most of the time, a simple static mesh is way better and far more optimized, just because of nowaday hardware render faster massive mesh than anything you can do based on CPU)

In a (veryyy) further update, I'll probably add some support for Geometry shader (which is more efficient), but for now, blitzmax does not support them (whether or not I updated the glew module)


About the tool :
- It's just an extra stuff I wanted to create (and I have actually already started some several times, and gave up each time for the same reason at a very advanced stage ... I can't stay more than a few days on the same project, then my brain get used to it, and I feel bored ... my bad)

The rain map is procedurally generated based on the terrain elevations ( the curves ), it can be required for some procedurally generated rivers, and at least for the moment, it allows to erode the terrain and use sedimentation.

ps : the blue is just ugly ... But that's just the part that is unrelated to the project, so, I left it like this, you know, just because I didn't care that much ^_^


Flanker(Posted 2016) [#4]
Interesting stuff and news, still looking forward for a good working 3D engine for bmax, I can't wait to test BigBang. Just a question I didn't ask on the other thread I guess, how fast is your engine to generate a mesh from code compared to blitz3d ?

Some time ago I tried something similar to what you call the "rain map". Starting from highest points of a heightmap, the algorithm tried to go down like rivers would do. If it can't go further down, it fills the area until it can. It was supposed to create rivers and lakes but I never completed it because like you, I can't stick on the same project for very long ^^


Bobysait(Posted 2016) [#5]
At the moment, I successfully implemented (for my very personnal use) metaballs, marching square caves, marching cubes, dynamic terrain, dynamic skydome, see mesh and automatic grass generation.
All of these create vertices/triangles on the fly in realtime, and it does not seem to consume much time in the render loop, but :
- I remember it also worked on blitz3d (so, I'd have to compile same codes with blitz3d to have a good comparision)
- phenom II x6 -> 6* 3.2GHz, It run pretty fast, but I also try to use 6 cores whenever it's possible ... Then it's hard to say if it will be fast enough.

Whatever, all the tests I've done until now to compare with Blitz3D was pointing Bigbang as the faster one (sometimes from a very little amount of ms, sometimes Blitz3D just shown how old it is, but there might be some situations where Blitz3D is faster...)
The mesh building process can be very similar to blitz3D's (it was the purpose at start), but there is also all the optimized stuff that is available for better/faster access : it requires a bunch of more lines of code.
For example, for building a surface, we can choose to work on the vertex banks instead of using a "Surface" method (with a pointer on the data) which is really really faster.

Local surf:BSurface = Mesh.GetSurface(1)
Local coords:VCoords = surf.GetCoords()
' works with the coordinates
coords.Set(Index, x,y,z);

' blitz3d-like stuff :
VertexCoords(surf, Index, x,y,z)

So you might want to use the blitz3d command which is faster to code (1 single line)
But, a call a method to VertexCoords will call Surf.Coord(Index,x,y,z) which calls a private method that finally calls the coords.set() Method.
So the result is the same, in the end it's just a matter of "coding time" vs "runtime".


Flanker(Posted 2016) [#6]
Thanks for you answer, BigBang seems to be quite complete :)

About the terrain generator, something you mays want to do (as it's totally unrelated to no man's sky ^^), is enabling junctions beetween 6 noise maps to be able to generate a planet from a geosphere.


Blitzplotter(Posted 2016) [#7]
Interesting work, great stuff!


gpete(Posted 2016) [#8]
try this Bobby- (you might already have seen this code)


;code to create random terrain 

Graphics3D 1366,768,32,2 

;this is the create and save portion

Const Size = 512
Const Maxheight=511
Dim Terrain#( 511 , 511 )
SeedRnd MilliSecs()
MyTerrain = TERRAINcreate(Rnd(4,511),Rnd(4,511),1)
Global player=1
Global scenary=2

;       show it
DrawImage MyTerrain , 0 , 0

ok=SaveImage (MyTerrain,"bmp/myterrain.bmp")

MyTerrain=LoadTerrain("bmp/myterrain.bmp")
ScaleEntity MyTerrain,2,15,2

; Print results 
If ok=1 Then 
;Color 200,200,0
Write "Hello there, Save successful!" 
Else 
Write "There was an error saving!" 
End If 

; these are the Functions

Function TERRAINcreate( Seed , Passes ,SmallNo )
	
	;reset values to 0
	Dim Terrain( Size, Size )
	
	;set random seed
	SeedRnd Seed
			
	;generate terrain
	For Parts =1 To Passes
	
		StartX = Rand( 0 , size )
		StartZ = Rand( 0 , size )
		SlopeType = Rand( 0 , 1 )
		
		;Smaller Bits
		If Parts > ( Passes - SmallNo ) 
			StartY = Rnd( 4, 8 )
			Radius = Rand( 4,8 )
		Else
			StartY = Rnd(4,32)
			Radius = Rand(4,32)
		EndIf
			
		For z=-radius To radius
			For x=-radius To radius
				Distance# = Sqr( x*x + z*z )
				If Distance < Radius
					If SlopeType = 0 py#=Cos( Distance / Radius * 90) * StartY * 2.0
					If SlopeType = 1 py#=( 1.0 - Sin( ( Distance / Radius ) *90 ) ) * StartY *3.0
					px = WRAP( StartX + X , Size)
					pz = WRAP( StartZ + Z, Size)
					NewHeight# = LIMIT( terrain( px, pz) + py , 0, 255 ) 
					Terrain( px , pz ) = NewHeight
				EndIf
			Next
		Next
	Next
		
	;make heightmap
	Heightmap = CreateImage( Size , Size )
	SetBuffer ImageBuffer( Heightmap )
	Color 0,0,0:Rect 0,0,size,size,1
	For z =0 To size -1
		For x =0 To size -1
			c = Terrain( x , z )
			Color c,c,c
			Plot x,z
		Next
	Next
	SetBuffer BackBuffer()
	
	Return Heightmap
						
End Function
;===========================

Function WRAP#( q# , hi# , lo#=0 )
	
	If q < lo Then q = hi + (q-lo)
	If q >= hi Then q = lo + (q-hi)
	Return q
	
End Function
;===========================

Function LIMIT#( q# , lo# , hi# )

	If q < lo q = lo
	If q > hi q = hi
	Return q
	
End Function




Blitzplotter(Posted 2016) [#9]
There is no format at the moment for any kind of export, but ... there is at least two ways to export :
- the final array as double/double (with some zlib compression)
- export the stuff that generate the final array (hudge terrains stored in few octets, but require to be computed at runtime)



Very interesting ;)


Bobysait(Posted 2016) [#10]
@gpete :
Thanks, I already have everything required for the terrain creation part. The purpose of the tool is to use nodes to create heightmaps, in realtime (or "almost realtime" ... not fast enough for a per loop update, but one update shouldn't take more than 100-200 ms), and it must be fully reliable.

But, seeing the result, it may be a good filter, whatever I remember having done something similar looooong time ago (like, 10 years ago or more), at least, I won't need to look for it.

- So, what's up for now -
The tool is in standbye, I'm working (again) on the engine to finalize it, but I must admit, I'm not very consciencious ... I spend a lot of time coding random demos of various stuff ... that are not required for anything ^^
Actually, I was implementing a verlet integration for blitz3d (yep, the old thing), just because I managed to compile bb code with sublime text...

So, it's time to return to the engine once for all !


RemiD(Posted 2016) [#11]
@Bobysait>>Focus !
https://www.youtube.com/watch?v=rJgrCuOTXoM