Instancing, Batches, and Scene Nodes

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
TheWanderer
Halfling
Posts: 44
Joined: Fri Apr 22, 2005 3:58 pm
x 4

Instancing, Batches, and Scene Nodes

Post by TheWanderer »

Hey everyone,

For the past few weeks, I've been working on a 2d isometric tile engine using Ogre, but I'm having trouble displaying scenes of significant size. I've attempted to address the issue by cutting up the scene with SceneNodes, but the expected boost in performance did not occur. I wanted to see whether perhaps my expectations are wrong or I'm simply not doing things correctly.

First, some information about my environment:
Ogre version: 1.9
OS: Windows
Graphics API: DirectX9
Graphics Card: GeForce GTX 670
IDE: MSVC 2012

The world I'm trying to display is a 3D array where every cell is represented by a 2D tile and looks pretty much as follows:

Image

Each tile is drawn using Instancing, specifically HWInstancingBasic. The terrain layers can also be scrolled through, so even tiles which are not visible are assigned an Ogre::InstancedEntity on scene creation. The terrain is also modifiable, which is why I've used individual tiles rather than a bigger mesh (I'm sure I could modify the mesh at run time, but I wanted to keep it simple, as I'm relatively new to graphics).

The first time I created a world of decent size (64x64x18), I saw that I was getting very low FPS. I therefore subdivided the scene into nodes of 16x16x1, but that did not help much. In fact, it helped very little. Given that a lot of the terrain is hidden (the above image is a bit jaggier than my usual scenes), I was expecting the FPS to increase by quite a bit.

Tracing through Ogre, I noted that the buffer being sent to the card for instancing was only being updated once during the Octree walk (more specifically, InstanceBatchHW::updateVertexBuffer is only called once. And yes, there is only one batch), which made me wonder whether I was not combining SceneNodes and Instancing correctly. Also, I note that when InstanceBatchHW::updateVertexBuffer is called, the code walks through all instances, even those not in the node.

My question is ultimately how should Instancing and SceneNodes be combined in order to maximize my performance. Do I perhaps need to have the InstanceManager create smaller batches and assign the Instances in one batch to one SceneNode? Is my approach to the scene not the best?

Any suggestions, insights are welcome. Let me know if there is any more information I can provide.
TheWanderer
Halfling
Posts: 44
Joined: Fri Apr 22, 2005 3:58 pm
x 4

Re: Instancing, Batches, and Scene Nodes

Post by TheWanderer »

So I spent some time tracing Ogre and found that a lot of my time is spent in the loop inside Ogre::OctreeNode::_addToRenderQueue() where I'm iterating over all of the visible OgreInstancedEntity objects. Given that the current scene I'm drawing is static (and I did tag the instance batches as such), it feels like this work could be reduced since most of the information required is already calculated in InstanceBatchHW::updateVertexBuffer().

I tried to see whether there was a flag I could set to reduce or remove the processing of the OgreInstancedEntity objects, but did not find one. Is there some way to actually do so? Or is there perhaps a way to do instancing without using the management class (though I fully admit it makes things a LOT easier and would consider this a last resort)?

Ultimately, I'm looking for a way to efficiently render the tiled terrain.

Edit: One more thing Ogre is doing with the InstancedEntity is merging the bounding boxes with those of the Node. Is that something which could also be avoided?
TheWanderer
Halfling
Posts: 44
Joined: Fri Apr 22, 2005 3:58 pm
x 4

Re: Instancing, Batches, and Scene Nodes

Post by TheWanderer »

For the curious (in case anyone runs into similar issue):

I ended up removing the scene nodes to which the OgreInstancedEntity objects were attached to from the Octree, thus avoiding the cost of needing to iterate over them. This, of course, has presented some other challenges since I'm the one now managing the nodes myself, but the gain in performance was substantial (4 FPS to 550 FPS on a Debug build), as shown below. Note that there is no occlusion culling, so even hidden tiles are currently being rendered.

Image
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5537
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1395

Re: Instancing, Batches, and Scene Nodes

Post by dark_sylinc »

Looks like you could gain a lot from using Ogre 2.0
See http://www.yosoygames.com.ar/wp/2013/07 ... 3x-faster/

Also look for the instancing part in the Ogre 2.0 manual, particularly batch fragmentation part (the Instancing section applies to both 1.9 and 2.0).