Managing scene's (level's) geometry - how to do if efficiently

Started by
1 comment, last by RippeR37 10 years, 9 months ago

Hey, im working on engine for future game and i stumbled on a problem. I'm not sure how to efficiently manage (mostly store and send to GPU) data of my level geometry.

Game will be with Top-Down camera (3D), so visibile area will be reduced, also most of objects will be pretty low-poly since nobody needs extra sharp(/smooth) models if u barely can see some details on it. ;) Problem is that i'm not sure how to store it, (update if needed* - though geometry is static, just what is visible) and send to GPU.
I've come up with some ideas:

1. Most basic - load everything right in one VBO (as models are very low-poly it won't have too much data as you might think?).
I think that though vertex shadders will work on every vertex, fragment shaders will work only on visible fragments and "discard" others automatic, right?

+ simple to write
+ dont have to bind multiple VAOs/VBOs/textures every frame
+ don't have to send new data every frame to GPU (using CPU time) and compute it!
- lot of data is on VBO (though size won't change during game) and will go through Vertex Shader (i think not by F.S. - right?)
- it seem's not so optimized?
- everything must be in one texture atlas which limits possibilities

2. Load every distinct object at startup of level, and then every frame create new VBO with new mesh, that would be made from objects that are currently visible at scene (modified with transformation matrix so that it all works ok).

+ it sounds as its an optimization ;p (but after some thought i'm not so sure)
+ i manage what i send to draw, so i could do some work (like LOD, though not in that kind of game, becouse all models are usally at same distance from camera...) so it's not actually "pro" per se...
+ i bind one VAO/VBO after creating that whole scene's mesh and dont change it for frame.
+ only visible vertexes (objects, somevertex might be little out of course) are sent to GPU
- loooooot of work on CPU, which may result in: GPU waits for CPU data ..... CPU waits for rendering by GPU ... and again GPU waits...
- looks much more complicated to build efficiently (at least as much as can)
- everything visible must be in one texture atlas...

3. Split level on smaller areas like 2D-tiles, each tile contains every object's data that is (at least partial) in this tile. Just not too small tiles, so that per visible scene there would be 3x3 or 4x4 tiles max. (or even 2x2?).

+ sound pretty fast (only needed data, not many VAO/VBO binds per frame, VAO/VBO would be already set-up at loading-time so no computing time needed per frame, only draw call).
+ somehow more flexible with textures, becouse i need current texture only for small tile which can be only couple meshes.
- seems hard to code it efficient, some problems (look below)
- some meshe's that would be on more than one tile would have to be doubled or splitted (not easy job i guess to do it right and fast! doubled seems better somehow)
- lot of pre-processing so as long as #1 pre-processing or even longer.

4. Render each object separate. If it's visible multiple times, render it using some kind of mechanism to do it efficiently like instancing (or something else? suggestons? i dont know instancing yet, but i heard of it).

+ normally it may be common way to render scenes (when meshes have many triangles its ok, becouse switching vbo doesnt cost so much then)
+ easiest to implement
+ easy to manage scene
+ easy to create a scene (just add description of mesh - pos/rotate/scale and which object it is just to add it).
+ i could create VAOs/VBOs earlier so no computing time needed on CPU side every frame
+ only visible models would be rendered
- lot of switches between every objects (maybe not that much, but when meshes are low-poly, i guess switching would take long time compared to rendering)
- it doesn't seems too optimized.

As i said, mostly i'd like to balance between complexity and performance, since i'm not working on some top-level, AAA project, just smaller project that may be very playable, may not ;)

PS. Could someone write in some order or with "weights" how much OpenGL actions cost (about)? Like: single draw call, bind VBO, bind VAO, bind texture, etc... so i'd knew what to watch for :)

Advertisement
fragment shaders will work only on visible fragments and "discard" others automatic, right?

Not necessarily, deferred rendering is meant to address this issue. Some other behind the scenes optimizations require some thought on your part. Depth sorting for one...

If you load 1 big VBO then you can still access them individually by using the models indices. I would not do this. Accessing a component still requires additional draw calls if you want to change anything. If you combine this with the headache and nuisance of adding and subtracting and hopping through indices then it may not be worth the extra few percentage points of performance increase. Some implementations may slow down, who knows? Messing up the index management can crash a computer. You won't know all your particular issues until you try what you've built on every single machine that you can get your hands on.

Even most of those silly little handheld phones can handle at least several dozen VBO draw calls before they start complaining too much, some of them will do 100 or more per frame, easily. This is combined with changing shaders and textures for many of those models.

Depending on your setup:

(i)You can use a distance check to disable whatever is off screen. if(modelPosX > -5.0 && modelPosX < 5.0){displayArea_1();} helps a lot to manage top view and side view games. Also if you isolate collision + animation within these screen-sized chunks then you can get really carried away for every discrete area.

(ii)If, when you change rooms it's only vertically or horizontally, then you will never have to display more than two areas at a time which gives you lots of flexibility in how many draw calls, texture and shader swaps can take place.

You could pack all the floor tiles for a room into one VBO, I think this would be practical and easy and safe. Same for trees, rocks, bushes. Now for the tiles, rocks, trees, and bushes you would have only 4 VBO's to switch between. Even a wrist watch running Java could handle that much.

Pay attention to optimization but don't become so hung up on it that you set yourself behind several years worrying about it. Stability is far more important. Finishing something is also good.

p.s. You mentioned something about creating the required VBO's every frame. I would say, avoid that. Even changing them per-frame can stall things, I imagine creating them per-frame will be far worse. My imagination can't be stretched far enough for me to come up with a good reason to do this.

Consider it pure joy, my brothers and sisters, whenever you face trials of many kinds, 3 because you know that the testing of your faith produces perseverance. 4 Let perseverance finish its work so that you may be mature and complete, not lacking anything.

You can use a distance check to disable whatever is off screen. if(modelPosX > -5.0 && modelPosX < 5.0){displayArea_1();} helps a lot to manage top view and side view games. Also if you isolate collision + animation within these screen-sized chunks then you can get really carried away for every discrete area.

But then i guess u mean that every mesh has its own VBO, right?

when you change rooms it's only vertically or horizontally, then you will never have to display more than two areas at a time which gives you lots of flexibility in how many draw calls, texture and shader swaps can take place.

I plan for it to be outdoor top-down shooter. Something similiar to Left 4 Dead, but top-down, now for PC and maybe in the future for Android(/iOS). Test pic (a lot to do yet): http://i.stack.imgur.com/XC0ga.png S(it had some debugging on so actually rendering time is not even half now)

I thought about making group of objects but it doesnt help me too much, if i put - in example - all trees in one VBO...

p.s. You mentioned something about creating the required VBO's every frame. I would say, avoid that. Even changing them per-frame can stall things, I imagine creating them per-frame will be far worse. My imagination can't be stretched far enough for me to come up with a good reason to do this.

I guess i'll have to update my shadow-map generation so that i'm not creating new texture every frame (for each light) but use same texture and just update it... Luckily its only couple lines...

In the end i still dont know how should i keep it. Group it by position in bigger VBOs and use only 2-4 VBOs per frame looks best, right? But the question is - should i keep it in VRAM or RAM and just send it if i need it? 2nd option would allow me to create very big maps since it holds very little data in vram (and ram is usally much bigger), but seems slower...

Btw. as i asked before - how slow is binding VAOs, binding VBOs, binding Texture, drawing 100 triangles, drawing 100k triangles, drawing 500k triangles, turning of depth test, something else that could be important here too, etc. ? I'd like to know what should i avoid and how hard should i optimize things to use as few as possible.

This topic is closed to new replies.

Advertisement