Quick batch question

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
Post Reply
JonnyJP
Goblin
Posts: 231
Joined: Sun Nov 01, 2009 4:23 pm
x 2

Quick batch question

Post by JonnyJP »

You know Ogre prefers a single batch with lots of geometry as opposed to lots of batches with little geometry?

Well, suppose I'm creating a building that doesn't have many windows and is pretty regular. Couldn't I just use the same mesh (i.e. a quad) for every surface but scale it to fit the wall or floor that it represents?

Then I'd only have one batch so should get a decent performance rate compared to if I created many walls seperately.

Is my logic right here?
User avatar
Jabberwocky
OGRE Moderator
OGRE Moderator
Posts: 2819
Joined: Mon Mar 05, 2007 11:17 pm
Location: Canada
x 218
Contact:

Re: Quick batch question

Post by Jabberwocky »

The only thing that seems off is that you talk about reusing the same mesh many times over.

Every mesh counts as at least one additional draw call. If the meshes share the same material, you can merge them together into one big mesh using Static Geometry. Or else you can just model your building as one big piece (or a few large pieces) to begin with.
Image
User avatar
xavier
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 9481
Joined: Fri Feb 18, 2005 2:03 am
Location: Dublin, CA, US
x 22

Re: Quick batch question

Post by xavier »

JonnyJP wrote:but scale it
And how do you propose to do that?
Do you need help? What have you tried?

Image

Angels can fly because they take themselves lightly.
JonnyJP
Goblin
Posts: 231
Joined: Sun Nov 01, 2009 4:23 pm
x 2

Re: Quick batch question

Post by JonnyJP »

Well, you can scale a mesh in the x, y and z direction so just using that.

E.g. If my mesh was:
(0, 0, 0)
(0, 10, 0)
(0, 10, 10)
(0, 0, 10)

Then I could scale it to make walls of any size and then scale and rotate it to make floors.

That make sense?
User avatar
madmarx
OGRE Expert User
OGRE Expert User
Posts: 1671
Joined: Mon Jan 21, 2008 10:26 pm
x 50

Re: Quick batch question

Post by madmarx »

If you use 1 quad mesh, that you scale to do 5 walls, then it is 5 batches.

Il you want to reduce the batch count, you have to build a single mesh with all the walls. That would make a single batch.
Tutorials + Ogre searchable API + more for Ogre1.7 : http://sourceforge.net/projects/so3dtools/
Corresponding thread : http://www.ogre3d.org/forums/viewtopic. ... 93&start=0
JonnyJP
Goblin
Posts: 231
Joined: Sun Nov 01, 2009 4:23 pm
x 2

Re: Quick batch question

Post by JonnyJP »

RIght, ok.

But I thought that if you had a load of entities using the same mesh then they would be rendered as one batch?
User avatar
Jabberwocky
OGRE Moderator
OGRE Moderator
Posts: 2819
Joined: Mon Mar 05, 2007 11:17 pm
Location: Canada
x 218
Contact:

Re: Quick batch question

Post by Jabberwocky »

JonnyJP wrote:But I thought that if you had a load of entities using the same mesh then they would be rendered as one batch?
Nope.
Not unless you merge them using StaticGeometry. Which is the same as simply modeling it as one big object to begin with.
Image
User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7157
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia
x 534

Re: Quick batch question

Post by Kojack »

When you do a typical render (without using specific instancing techniques) a single draw call only has one material and one set of transform matrices (world, view and projection in directx terms, or possibly a single combined matrix if using shaders). Rendering 2 things which differ by material or transform requires 2 draw calls (batches). So scaling, moving or rotating a mesh means it must use an extra batch to render. Ogre will render things ordered by material so there's less overhead from changing material states, but it still has to change the matrices for every mesh, resulting in more batches.

One technique to cut the batch count is the Static Geometry class. It bakes the transforms of all meshes sharing the same material together, creating a single large mesh (actually there's more to it, such as regions to improve frustum culling). But that takes time, you need to software transform all the meshes and generate a new mesh from them, so ogre can't do that all the time automatically. So static geometry is typically built once (which is a cpu hit) then left as is. It's great for static scenes, not so good for moving stuff.

There are also instancing methods which try to handle multiple meshes with unique transforms all in one draw call, possibly passing the matrices to a shader. Ogre had one style, but apparently it didn't work too good so there's a thread in the developer forum with a new one (I haven't checked it out yet).

A combination of static geometry and texture atlases (lots of textures stored in a larger texture) would let you potentially do a whole building (and it's contents) in one batch.
User avatar
xavier
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 9481
Joined: Fri Feb 18, 2005 2:03 am
Location: Dublin, CA, US
x 22

Re: Quick batch question

Post by xavier »

Kojack wrote: A combination of static geometry and texture atlases (lots of textures stored in a larger texture) would let you potentially do a whole building (and it's contents) in one batch.

If you resist the urge to use 1024x1024 textures for all the different parts...but I digress.
Do you need help? What have you tried?

Image

Angels can fly because they take themselves lightly.
User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7157
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia
x 534

Re: Quick batch question

Post by Kojack »

On a high end card you could probably get away with 64 1024x1024 textures in an atlas. :)
User avatar
xavier
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 9481
Joined: Fri Feb 18, 2005 2:03 am
Location: Dublin, CA, US
x 22

Re: Quick batch question

Post by xavier »

8192 x 8192 x 4 = 256MB for a single building. I can't even begin to imagine the sampler cache pressure that's going to create, for a single object. :P
Do you need help? What have you tried?

Image

Angels can fly because they take themselves lightly.
JonnyJP
Goblin
Posts: 231
Joined: Sun Nov 01, 2009 4:23 pm
x 2

Re: Quick batch question

Post by JonnyJP »

Thanks guys. I've not had my head screwed on this week!
Gandonov
Gnoblar
Posts: 4
Joined: Fri Apr 15, 2011 4:24 am

Re: Quick batch question

Post by Gandonov »

Hi,

I had a question regarding efficiency as well. I made a hexagonal grid with a height map that should be possible to change during run-time.
Basically, whole grid is stored in one mesh which has shared vertices all in one Vertex Buffer.
Then,
I create [width * height] sub meshes, where each mesh contains their own index buffer that point to shared Vertices in the parent Mesh.

I am still a beginning Ogre3d user, so I am not sure what would be the best way to go about this. So I had two questions actually:

1.) What would be the best way to go about it? to have one Shared Index Buffer among all sub Meshes or each sub Mesh has it's own index Buffer

2.) Is it possible to avoid having [width * height] batches?

Thank you
Post Reply