Fast-Terrain

Community Forums/Showcase/Fast-Terrain

Bobysait(Posted 2009) [#1]
Here is my terrain Engine.
For now, I just have uploaded a video ( in very low res ... I have to update this )

Watch the video on Youtube
Download the Video ( better quality ) (50 Mo 440*300 +> 5.20 min )

Actually, it supports :
+ very fast height detection
+ Texture Splating
+ shadow projection ( using shadowmap )
+ Chunked LOD
+ realtime morphing
+ water border detection
+ ... few other things I don't mention... like auto hiding entities on terrain-chunk, or "auto-LOD" entities with chunks ...etc ...

It is very similar to the WoW terrain engine.
with large amount of detail, it can runs at 600-800 fps on a amd 64 *2 4800+ ( with a radeon HD 4850 )
with a medium detail definition, it runs around 200-300 fps on a smaller computer ( old sempron 2GHz with GF 5600 )
on the lowest res, It runs at 100-120 fps on a Pentium 3 733MHz ( very old , but stil accurate :) )

ps: I 'm currently not sure about the way it will be released, so don't expect it to be released for the moment.


( click images to enlarge )
_

_


RifRaf(Posted 2009) [#2]
Most important thing for terrain systems imo, is that they stay modular, and very easy to plug into existing projects without recoding much if anything to accomodate it.


Bobysait(Posted 2009) [#3]
the terrain is a simple mesh with patchs attached to it, so we can easily get patch using getChild() or FindChild()

Else the command set is easy to use
; Create a terrain
Terrain=	TTER_Load(File$,Detail%)
; or 
Terrain=	TTER_Create(Size% [,Scale#=1.0])
; Setup the terrain
		TTER_SetScale(Terrain,MAPSIZE%,MAPSCALE#)
		TTER_SetLOD(Terrain,CountLod%)

; update terrains
TTER_Update(Camera% , PlayerPivot )

; Get terrain height
TTER_TerrainY(Terrain , pickX#,pickY# )



So it is a standart.

Then , there are the function to add splating layers, or colortemplate etc...
Those are implicits like
TTER_EnableWater(Terrain , Mode, [WaterHeight#=0.0])
TTER_EnableSplating(Terrain , Layerid%, Brush% [,AutoNormal#=0.0] )
( where Autonormal is the rate for auto building the splating layer using the terrain normal +> default is "0", mean +> no auto update )
and for "non-autosplating" :
TTER_SetSplatingMask(Terrain,LayerId%,Mask%)

I just have to mention Terrain is a type !
Terrain.TTerrain
But, it can be modified to return the root mesh, or the handle of the type ( to retreive using Object.TTerrain(TerrainHandle)

If I release the engine, I will fit the style to users' best solution.

But for now, it just has to do what I want it to :) . So it's not currently an "important thing".


Jeppe Nielsen(Posted 2009) [#4]
Looks good in the video, how does a simple example look like codewise?


Bobysait(Posted 2009) [#5]
Could you clarify "codewise" please ? ( I can't find exactly what it means <french-inside> )


Bobysait(Posted 2009) [#6]
_

_


Kryzon(Posted 2009) [#7]
Where did you manage to learn about how to use Texture Splatting in B3D, Bobysait?


_JIM(Posted 2009) [#8]

Could you clarify "codewise" please ? ( I can't find exactly what it means <french-inside> )



It means a little example of source code to show how you can use the engine.

Its looking very good, btw :)


Bobysait(Posted 2009) [#9]

Where did you manage to learn about how to use Texture Splatting in B3D, Bobysait?



I can't really explain "where" or "how" ... I just tried what I felt the best way to do it with blitz3d. At the 3rd try, it runs as a charm

@ j.Nielsen

Here is a full documented exemple :



and here is the minimalist exemple :

Graphics3D 1280,980,0,2
SetBuffer BackBuffer()

	Cam=CreateCamera	()
		MoveEntity		(cam,700,500,200)
		TurnEntity		(cam,45,45,0)

	Terrain.TTerrain=	ETter_Load("MEDIAS\HMap_04_1024.jpg" , 16 , -1)
		ETter_SetScale	(Terrain , 4.0 , 200.0)
		ETter_SetLOD	(Terrain,8)

	Repeat
		ETter_Update	(cam,p1)
		RenderWorld		()
		Flip			()
	Until KeyHit(1)

ETter_KILL()

End



Kryzon(Posted 2009) [#10]

I can't really explain "where" or "how" ... I just tried what I felt the best way to do it with blitz3d. At the 3rd try, it runs as a charm


But you just didn't test it out of the blue, you must have read some reference or seen some source, right?
Why did you think it was the best way to do in Blitz3D, what information were you using?


Bobysait(Posted 2009) [#11]
It must be about 4 or 5 years I use blitz3d... then, I tested a lot of things by myself. So It's first the result of my own experience.

For sure, I searched "howtos" for splating, but they are not relevant. Not applicable for blitz3d, or just not fast enough.

Here, I just build a terrain engine using Chunked LOD ( that I just imagined, and then realised... as many things I use to code )
And I found interesting adding multiple layers for material. ( like in World of Warcraft, that I watched and watched again to imagine how they should have made it ) It was logical for me to do it using :
+> Alpha texture for mask, then multitexture
+> or simply using vertexalpha with a duplicate mesh

I just tried the first method, that was not fast enough, and had issues depending on the cards ( that does not support the blending mode like my card )
And I finally tried the method using a surface per material, and I found logical that We need to prevent calcul, so the layers are calculated one time, each time the camera/player system move from patch to patch, and the rest of time, it just use oclusion.
And at the end, I found a way to build only tris that are visible ( so the layers for material cost very less of tris , that helps a lot in the framerate )
Like this, I have a system that don't use too much poly, benefits on LOD system, allow to use multiple material, and does not explode the framerate.

So, all this stuff is just the result of logical process applyed to blitz3d specs... I can't say more about source, because, there is no source for building such a terrain engine for blitz3d.

What I can say :
I use to code with blitz3d for long time enough to be pretty sure, there's currently less
terrain engine in blitz3d than clever-beautifull-women that love noobish-geakish-developpers ( wearing big glasses, and found of StarWar and boba feth ), in the world :) , and you 'll can see, they are no legion to allow as many as features that this one allows.

On my experience, what allow me to think it's the best way :
+> blitz3d is faster rendering triangles, than calculating every frame, so it's faster to build one time, and then render the same scene whenever we can ( that mean, until we change of patch location )

+> to prevent lag when building the patches, I update the meshes one by one using 1 to 10 frame to build all the mesh. Patch are then rendered showing the new at the same time I release the old , so It use a bit more memory for this laps time, but is released as soon as possible, and helps to preserv a good framerate.

+> Blitz3d is low using multi texture... so, the best way is to use multiple surface ^^
Lot of people think about "single surface system" , but to be right, single surface is just good for particle system or animated meshes. For a terrain if we don't use multiple material, it becomes true, but whenever you need splating-like rendering, it becomes false. and whatever , with a single surface it's just impossible to achieve...
The second choice would have been to use a second mesh for each patch. But as far as I tested, blitz3d have a faster support for multiple-surface than for lot of pivots.

+> at last but not least :
I use a pivot system that allow me to hide/show very fast using a quadtree, and it hides every patch not rendered, just parenting them to a hiden pivot. so as the pivot is hidden, other patch children of this pivot are hidden too, but not even estimated during the "renderworld" call.
+> just imagine the blitz3d "renderworld" function is something like this :

+> Call RenderWorld +> Renderentity(rootEntity);

Renderentity(entity* ent)
{
if (!ent->show==false){
render(ent);
child* entity=ent.rootchild
while child<>null{
RenderEntity(child)
child=child->next;
}
}
}

So, if we test the pivot hide state, we just see it's false, then it stop the loop, and prevent some 50 to 100 test . And, here where it becomes smart : If we attach entities to patchs, they will hide with the patch. So it ocludes every thing in the terrain. We now can have lot and lot trees, grass etc... on the terrain, they will be optimised with the terrain update.
I used this technique for a test with 2 000 000 spheres. ( with an old config... based on a pentium 3 )
Without, I just got 1 frame rendered when blitz3d accepted to work a bit ...
With, It just rendered at about 15 fps .

I've made lot of test on lot of things in blitz3d
+> the time to calculate addition, mult,div etc...
the best support for datas
( that is the type and Linked-List , then the Dim arrays but they are not very usefull in most case ... and end of all, are the banks, that are very slow compared to types)
I finally build the same TMap library as Blitzmax have.

With all those tests, I just did not need doc to build my terrain system. I just had to compute all the datas I've coded.


ps : In the french community, I am known as a surprise-box ( with a joke inside, that pop suddently when we don't care :) "Sboing!" ) full of code that grow in my head... Here, I don't post very much, but you'll learn I'm not the kind of developper we meet every day. Purist will simply hate me, others will find a way to think I'm really strange, and some will like (maybe love) me ;) ...maybe you're one of them. ( I hope )


Kryzon(Posted 2009) [#12]
Wow, very interesting read.

Thank you for your effort into writing that.


Blitzplotter(Posted 2009) [#13]
very impressive imagery, looks great.


System4 Studios(Posted 2009) [#14]
It seems similar to TerraEd Pro.. which I have..

If you are planning to sell this and provide a good demo.. then I'll buy..


Bobysait(Posted 2009) [#15]
Thanks

But it's not a TerraEd like.
Terra Ed is an editor for BlitzTerrain
This library is a "module" to build terrains differently.
The terrains made, run faster, and with more options.

the video shows my editor. I didn't think about selling it ... but maybe, it could be a good idea :)


Bobysait(Posted 2009) [#16]
I think many would like to have this ...
It's a dynamic 2 sizes array that blitz3d miss !

I made it using a collection of type and "mini static-arrays"
It allows to be resized and can be managed dynamically
It is really a fast library ( I compared it to Dim in my terrain system and it's just around the same ... just a bit faster ), without this it could not be possible to create an array for each terrain or it would have been declared with a constant size ( that I can't permit )
So, I use it in my terrain system to prevent memory.

It's all done by myself, and released as free-open source.
Just send me your remarks, and bugs ( if any, but as I didn't test the resize method yet... <as I don't really need it ^^>, so it might has issue(s) )

/!\ Currently it just store Integer, but anyone can fix it replacing in the "Dim2XBuffer" type :
Field Data_%[DIM2X_BUFFERSIZE]


with (for string)
Field Data_$[DIM2X_BUFFERSIZE]


or (for float)
Field Data_#[DIM2X_BUFFERSIZE]

and don't forget to modify SetDim2X() and GetDim2X() with the appropriate declaration.






and a simple example

; an array of 128*512 size.
MyArray.Dim2X=Dim2X(128,512)
For i = 0  to 127
  For j = 0 to 511
    SetArray(MyArray,i,j,rand(0,10000)
  Next
Next






The Terrain System will be sell in few weeks (approx 1/2 month according to the holidays )
It is called "ETer" and will cost approx 25 Euros.