Jump to content
  • Advertisement
Sign in to follow this  
RobMaddison

Chunked Terrain and Component Entity Systems

This topic is 1725 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

 

Share this post


Link to post
Share on other sites
Advertisement


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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

 


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.

Share this post


Link to post
Share on other sites


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.

Share this post


Link to post
Share on other sites


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>.

Share this post


Link to post
Share on other sites


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. 

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites


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/

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!