   Octree advice
  I'm working on octree realization in my engine, which contains scene triangles (map, game objects, etc). After octree render finished, I have a bunch of triangles that intersects the frustum, but there are from different objects. Should I sort them by object, texture ? Or something else?   
  I beleive that sorting by texture is most important.Shaders also have an effect. Note that even if you aren't using shaders, the driver generates a shader since all GPUs are shader based now.   ;Quote:Original post by StormherzI'm working on octree realization in my engine, which contains scene triangles (map, game objects, etc). After octree render finished, I have a bunch of triangles that intersects the frustum, but there are from different objects. Should I sort them by object, texture ? Or something else?Do you really collect all triangles individually, even for dynamic objects? I'd consider that too slow since modern hardware really excels in rasterizing triangles. You might instead just cull and collect (sub)objects even if they are only partially visible.Then you should sort them by material (i.e. combination of shader, texture, render state etc.). From a performance point of view, shader and texture switches are among the most expensive, so you might want to sort by those first. From a visual quality/correctness point of view you should also consider sorting by transparency (in general just opaque or transparent), render state (depth test on/off, etc.), depth (especially for transparent objects) etc. depending on the algorithms you use (e.g. depth peeling might make transparency related sorting unnecessary).;Quote:Do you really collect all triangles individually, even for dynamic objects? I'd consider that too slow since modern hardware really excels in rasterizing triangles. You might instead just cull and collect (sub)objects even if they are only partially visible.I think this solution is more acceptable, because the engine is not very big. But what kind of division should I make ? Earlier I was using AABB for objects in scene, but what should I do with the level model ? Split it by BBox maybe, rooms ?   ;  Dependening on how you setup your static geometry, splitting it into subparts on a per-triangle basis would be ok. However, you should not do that for dynamic geometry and objects.Additionally you might consider using a loose octree which would allow objects/triangles that stradle a node's boundary be inserted much deeper in the tree. For example, an object whose AABB includes the octree's center would end up in the root if the octree was not loose and the object would not be split. With loose octrees it might however be inserted much deeper, even at a leaf, at the cost of more nodes having to be processed.   ;  Going through the level geometry each frame to reevaluate which triangles are visible and which are not will kill your performance for bigger scenes. Just enforce XYZ (insert your most famous hierarchy subdivision scheme name here) partitioning of your static level map geometry upon initialization such as a binary bounding box here or an octree who's leaves has no less than X triangles with X being 1000 or bigger. Then just check visibility for your octree leaves each frame. You will end up rendering some thousands of invisible triangles but that is still much faster than sorting the octree down to the level of triangles. Obviously that makes sorting a bit tricky but with texture atlases for your level geometry you should not be forced to change the texture during rendering calls thus stalling the rendering. Just make sure each of your big octree leaves has just a single texture atlas with all textures all triangles in that particular leaf require.Next, do not mix rendering dynamic objects with rendering your static level geometry. Rendering dynamic objects such as characters most likely involves switching shaders while rendering ALL level geometry octree leaves can use the same shader. Just render all visible level octree leaves first without switching shaders and with as few texture switches as possible. Then render your complex dynamic objects such as characters one by one if they are located in a visible level geometry octree leaf.   ;  Thanks for all replies, this is very valuable advices, most of them I've seen the first time, so thanks a lot   