Jump to content

  • Log In with Google      Sign In   
  • Create Account

Chunked Terrain and Component Entity Systems


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
10 replies to this topic

#1 RobMaddison   Members   -  Reputation: 698

Like
1Likes
Like

Posted 29 August 2013 - 04:30 AM

I'm just wondering what the best practice is with chunked terrains and component entity systems.  Should each chunk be an entity in itself?  Or should the whole terrain be an entity?

 

I'm trying to streamline and refactor my rendering process, and indeed, design parts of it that haven't been done yet.  I have a sandbox project that doesn't use my new architecture and it has my terrain system in it, which is honed and extremely efficient.  Porting it to my new game engine is throwing up lots of design decisions.  My rendering engine essentially works sequentially through a vector of render 'tokens' which allow me to sort it on various criteria.  My main question is "should" my terrain parts (i.e. chunks) be just another render token in the list or should I contain my specialised terrain rendering code in its own render method.

 

It feels wrong to keep it in its own method, but its quadtree and relational nature doesn't really lend itself to a linear list of completely unrelated render tokens.  My set up is essentially like this at the moment:

 

Entity (contains standard orientation data)

---> RenderableComponent (there is a link to this object in each 'RenderToken' which just holds the sortable key, the material and link)

---> SkeletonComponent (this is just the skeleton data)

---> MeshComponent (this is just the mesh data)

---> AnimatorComponent (this builds skeletal poses based on animation data)

---> etc..

 

My entity system doesn't really have 'systems' that control the entities/components, rather the functionality exists within the components.  This was an early design decision that I quite like but it's easily changable.

 

So how would you go about moving a quadtree-based terrain system into this architecture?  Keep it a self-contained terrain system or integrate it into the pipeline properly?

 



Sponsor:

#2 swiftcoder   Senior Moderators   -  Reputation: 9992

Like
2Likes
Like

Posted 29 August 2013 - 08:21 AM


I'm just wondering what the best practice is with chunked terrains and component entity systems.  Should each chunk be an entity in itself?  Or should the whole terrain be an entity?

Wrong abstraction, in my book. Why would you want it to be either?

 

Unless you have many different terrains on screen at once, it's basically a background construct of both the rendering and physics systems.


Tristam MacDonald - Software Engineer @Amazon - [swiftcoding]


#3 Ingenu   Members   -  Reputation: 892

Like
0Likes
Like

Posted 29 August 2013 - 08:58 AM

It really depends how your engine works, and how much work you want to put in the Terrain.

Can terrain patches have different shaders ? (For LoD for example) If so, do they need to be different render 'tokens' ?

 

There are a number of questions like that you'll need to ask yourself.

I'm a little familiar with entity systems but they always seemed to be more engineering fun that real benefit to me... ie Keep It Simple, Stupid.


-* So many things to do, so little time to spend. *-

#4 RobMaddison   Members   -  Reputation: 698

Like
0Likes
Like

Posted 29 August 2013 - 06:35 PM

 


I'm just wondering what the best practice is with chunked terrains and component entity systems.  Should each chunk be an entity in itself?  Or should the whole terrain be an entity?

Wrong abstraction, in my book. Why would you want it to be either?

 

Unless you have many different terrains on screen at once, it's basically a background construct of both the rendering and physics systems.

 

 

It keeps everything neat and generic I think.  I've implemented it using my component entity system and it works a treat, I can sort my terrain chunks as if they were any object.



#5 swiftcoder   Senior Moderators   -  Reputation: 9992

Like
0Likes
Like

Posted 29 August 2013 - 06:50 PM


It keeps everything neat and generic I think.  I've implemented it using my component entity system and it works a treat, I can sort my terrain chunks as if they were any object.

I mean, if it works, go for it.


Tristam MacDonald - Software Engineer @Amazon - [swiftcoding]


#6 Norman Barrows   Crossbones+   -  Reputation: 2125

Like
0Likes
Like

Posted 29 August 2013 - 10:42 PM


My main question is "should" my terrain parts (i.e. chunks) be just another render token in the list or should I contain my specialised terrain rendering code in its own render method.

 

my chunks are basically memory images of my renderables list (my drawlist of Zdrawinfos) for a single chunk, ready to draw. but i use separate dedicated code to do it. 

 

in your token system, the equivalent would be breaking a chunk into its tokens in a dedicated list, and strong the chunk that way. then having dedicated code just to draw that.

 

however it appears you want to treat a chunk as a single renderable. my chunks consist of 1 ground mesh per texture, plus all the plants, rocks, and water in the chunk. obviously more than one renderable. a complex chunk can have 4000+ renderables.

 

my layout happened by accident. the current drawlist data structure was originally invented for the chunk system. its worked so well, the drawlist was changed to use it. thus the two dedicated drawing routines. it could probably be done as one routine.

 

treating a chunk as just another token is the clean way to do it. everything is just a token, one token drawer. job done. gimme a beer! <g>.


Norm Barrows

Rockland Software Productions

"Building PC games since 1988"

 

rocklandsoftware.net

 


#7 Norman Barrows   Crossbones+   -  Reputation: 2125

Like
0Likes
Like

Posted 29 August 2013 - 10:59 PM


It feels wrong to keep it in its own method, but its quadtree and relational nature doesn't really lend itself to a linear list of completely unrelated render tokens.

 

sounds like its just a token with a very complex draw method, that's all.

 

OTOH, rendering a scene is usually easier accomplished in stages, rater than just stuffing everything in one big list and going for it.

 

even with my drawlist, i actually clear, populate, and draw it 3 or 4 time each frame. only then do i draw the ground - with a separate but almost identical routine.

 

so from that point of view, it would be nice to be able to draw the ground separately, before or after other things in the scene.

 

so that's a good case for having a stand alone ground drawing routine.

 

also, it would probably be faster / easier to implement as two routines. that's basically what you already have in separate files. another good case for having two. 


Norm Barrows

Rockland Software Productions

"Building PC games since 1988"

 

rocklandsoftware.net

 


#8 RobMaddison   Members   -  Reputation: 698

Like
0Likes
Like

Posted 30 August 2013 - 01:14 AM

My main question is "should" my terrain parts (i.e. chunks) be just another render token in the list or should I contain my specialised terrain rendering code in its own render method.

 my chunks are basically memory images of my renderables list (my drawlist of Zdrawinfos) for a single chunk, ready to draw. but i use separate dedicated code to do it.  in your token system, the equivalent would be breaking a chunk into its tokens in a dedicated list, and strong the chunk that way. then having dedicated code just to draw that. however it appears you want to treat a chunk as a single renderable. my chunks consist of 1 ground mesh per texture, plus all the plants, rocks, and water in the chunk. obviously more than one renderable. a complex chunk can have 4000+ renderables. my layout happened by accident. the current drawlist data structure was originally invented for the chunk system. its worked so well, the drawlist was changed to use it. thus the two dedicated drawing routines. it could probably be done as one routine. treating a chunk as just another token is the clean way to do it. everything is just a token, one token drawer. job done. gimme a beer! <g>.

Well after a whole day of refactoring yesterday, my terrain chunks are now just normal render tokens. My ground chunks don't have anything else associated with them (foliage, trees, etc), but that's not to say they won't at some point ( in some spatial form). There won't be any special links between eye candy and the terrain where the renderer is concerned though, it just takes a token and renders it, all the ordering is done before that. This feels like a nice system.

My terrain works in blended layers for texturing so if a chunk (32x32) has x number of textures on it, that's x draw calls - I didn't want to be restricted by passing all of my textures in one draw call especially as I have normal, specular, bump, etc too. So each terrain layer is also a token now and they are sorted to be drawn after the base terrain detail and blended on top. I blend out the detail texture layers at a very short distance (40m or so) so you only ever end up drawing layers on one or two chunks keeping the draw count down nicely - the overall surface texture (which covers 512x512 of the terrain) blends in beautifully - think Crysis,

It's really interesting to hear all your views. Norm, do you have any demos/screenshots of your engine in action?

#9 RobMaddison   Members   -  Reputation: 698

Like
0Likes
Like

Posted 30 August 2013 - 01:22 AM

OTOH, rendering a scene is usually easier accomplished in stages, rater than just stuffing everything in one big list and going for it.
 
even with my drawlist, i actually clear, populate, and draw it 3 or 4 time each frame. only then do i draw the ground - with a separate but almost identical routine.
 
so from that point of view, it would be nice to be able to draw the ground separately, before or after other things in the scene.


Even though everything is in one big list, the list is keyed on a sort code which can contain any criteria you like, so if I 'or' in a numerical hash of 'TerrainPatch' for instance, all terrain patches will be batched together, this makes perfect sense as they all use the same shader.

So it's both generic and flexible. I've even pushed my post processing filters onto the renderqueue. Their mesh being just a full screen quad and the RenderableComponent having some specialised shader setup code (for passing results of previous renders, etc). I know with this type of development (if not, all) if something doesn't feel right, it probably isn't and this does feel very right (for once!). I'm on my 4th engine now so hopefully I'm starting to get things right. Getting some game logic in there too now, so it's coming together nicely.

#10 Norman Barrows   Crossbones+   -  Reputation: 2125

Like
0Likes
Like

Posted 02 September 2013 - 11:40 AM


It's really interesting to hear all your views. Norm, do you have any demos/screenshots of your engine in action?

 

CAVEMAN, and Airships! both use the "drawlist" render queue. CAVEMAN also uses the chunk based terrain system.

 

right now, i use tiled ground textures, no blending. but i too do one draw call per ground texture. i actually create one mesh for each ground texture in the chunk, and draw each separately.

 

 

gallery_197293_593_71361.jpg

 

 

gallery_197293_672_66488.jpg

 

 

more screenshots:

http://www.gamedev.net/gallery/member/197293-norman-barrows/


Norm Barrows

Rockland Software Productions

"Building PC games since 1988"

 

rocklandsoftware.net

 


#11 Norman Barrows   Crossbones+   -  Reputation: 2125

Like
0Likes
Like

Posted 02 September 2013 - 11:52 AM


I'm on my 4th engine now so hopefully I'm starting to get things right. Getting some game logic in there too now, so it's coming together nicely.

 

sounds like we're working the same issues. but you're doing a full engine / game, while i'm playing with a testbed just to implement different architectures and code organization. the testbed program is yet another app of mine, and it's not yet up in my gallery.  but already you can move around and shoot stuff, with about 200 lines of user code. implementing the user collision handler in the demo program is next. right now its just displays a message saying "target x collided with (whatever)" for testing purposes.  the nice thing about the testbed is you can try things quickly. I've done 4 engine designs in the last 2 weeks with it.

 

now i need to figure out the best way to implement an optional ground drawing routine. i already have both chunk and dynamic mesh technology working. but i need to figure out what's best for all types of ground: shooters, flight sims, RTS, etc.   one ground drawing routine to rule them all.

 

any suggestions?

 

 

 

i've got about 6 titles on my short todo list (beyond CAVEMAN, AIrships!, Armies of Steel II, and CIty States) , so i'm trying to get my library / boilerplate code / engine whipped into shape so i can use it for all of them.   but the REAL problem is content. all those models required. as coders, we can use libraries, engines, and good old copy / paste / edit to get the coding done quickly. but i see no speedups for the typical week+ required for a fully rigged and animated character model with matching equipment.

other types of models also take time to create.   until there's a good supply of ready to go content available free/cheap, it will be a barrier to those without artists on the team or deep pockets.


Edited by Norman Barrows, 02 September 2013 - 12:06 PM.

Norm Barrows

Rockland Software Productions

"Building PC games since 1988"

 

rocklandsoftware.net

 





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS