Efficiency of materials

Problems building or running the engine, queries about how to use features etc.
Post Reply
Oogst
OGRE Expert User
OGRE Expert User
Posts: 1034
Joined: Mon Mar 29, 2004 8:49 pm
Location: the Netherlands
x 32
Contact:

Efficiency of materials

Post by Oogst »

I am working on a game where I am creating some a bit complex material effects and now I am wondering how to make this run as efficiently as possible.

These are the questions I have about efficiency of materials in Ogre:

1. Does it differ in rendering speed whether 50 objects all have the same material, or all have a different material but with exactly the same settings and textures.

2. If materials and/or texture-names are swapped dynamically quite often during gameplay, does this give worse performance than when all materials stay the same? I am assuming here that I have already loaded all necessary textures and materials on start-up.

3. I have 9 textures in different colours. I know that if I make a texture-atlas with all off them in it and use that for all objects, this will be faster than 9 seperate textures. However, is this still true if each texture has a different scale and scroll in the texture-unit? Or will much of the performance be lost because these settings have to be re-set? How much will I win anyway if I use texture-atlasses that bring me from 9 tot 1 texture? Should I think around 1% or even 10%, or will it hardly be noticeable?

4. What I am making is a city-area where the player can change the colour of almost all objects between nine different colours. Changing the colour is done using nine different textures for the objects. There are three object types for this, so that makes 9*3 = 27 different textures for this. Most of these objects have their own low-res lightmap that multiplies the texture. I guess there will be at least 100 different lightmaps in the entire scene. What important optimisations should I think of for this scene? (BTW: I have all of this working already, the point is that I want to improve the framerate on older GPU's.)

User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19265
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 66
Contact:

Post by sinbad »

1. Yes, because you save the rendering state changes. It's even more efficient though if you batch those 50 objects into a single render call, which you can only do if they are not moving relative to one another (ie can use the same world matrix)

2. Yes, texture swaps are relativelly expensive as a state change. Note however that OGRE will order your passes by common texture usage in the same texture units to minimise texture state changes so if there is a case whre unit 0 uses the same texture across 3 material passes but texture 1 is different, it will place those together in the ordering so unit 0 stays constant. Only for solids though (transparency needs depth sorting)

3. Mostly. It will require state changes to alter the scroll etc but these are cheaper than switching textures.

4. If it's just changing colours, why not do this through a modulative texture unit with manual colour blend (and no texture)? Then you have no texture switch for changing colour.

Oogst
OGRE Expert User
OGRE Expert User
Posts: 1034
Joined: Mon Mar 29, 2004 8:49 pm
Location: the Netherlands
x 32
Contact:

Post by Oogst »

Thanks for the very fast and clear answer!

Your answers raise some more questions, though:

1. OK, that is clear, but batching objects together, is that possible if objects can change their material seperately? I think that would require breaking up the batch, which would give a heavy framerate hick-up, right? Also, is it not so that batching is actually inefficent if it means sending lots of polygons that are behind the camera to the GPU? In a city, typically half of it is behind the player.

4. Some of the objects actually change colour by picking a basic colour and then putting a partly transparent texture over it, so the texture is the same for all colours. The holes in the texture show the colour. For the other textures, this is not possible, because the artists need control over how parts change colour (windows should remain blue, for instance).
Last edited by Oogst on Sat Apr 22, 2006 10:07 am, edited 1 time in total.

User avatar
Kencho
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 4011
Joined: Fri Sep 19, 2003 6:28 pm
Location: Burgos, Spain
x 2
Contact:

Post by Kencho »

About 4, I guess you (your artists) can use an image mask (an alpha channel) to define how much amount of the original texture and how much amount of customized colour you want for each pixel. For instance, you can have the classical shooter where the armor colour is constant for all teams, but the pants colour isn't. Then you would paint the armour texture with alpha=1 and the pants texture with alpha=0 (you don't really need to paint that part). The most common use of partial transparency here would involve shadows/hilights; in this case, you could simulate modulative blending by alpha-blending with black (additive blending would be simulated with alhpa-blending white), so you can give some texture to the "custom colour texture part" (for instance, the pants' foldings).
An easy way to test this is by adding a background layer (not included when saving the texture) with a solid colour (the customisable colour). Changing this layer's hue, brightness and saturation should give good-looking results. If it works, you're in the right path ;)
Talk your artists about this and talk about its feasability :)

[EDIT] Sorry for the artistic speech ^__^'
Image

User avatar
Praetor
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 3335
Joined: Tue Jun 21, 2005 8:26 pm
Location: Rochester, New York, US
x 3
Contact:

Post by Praetor »

About #1b. Yeah, the materials need to be the same. Things can be batched iff the materials are the same and they don't move relative to each other. So, you have to work that part out.

As for batching and such. The StaticGeometry class is able to split sections that are "baked" in to make regions. These regions exist for LOD purposes and culling. So, by playing with the region sizes you can find a good tradoff between polies rendered and a large batch size to get good performance. Certainly even a bad regioning is better than having a city full of separate entities. I can't think of any sure fire way to find the best region size. You'll have to play around with how many entities go into a staticgeometry and how large each region is, but this is the way to go for static objects.

User avatar
Kencho
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 4011
Joined: Fri Sep 19, 2003 6:28 pm
Location: Burgos, Spain
x 2
Contact:

Post by Kencho »

Definitely, scene rendering optimisation is a hand-made craft. There's no way to optimise a scene other than tweaking and playing with the techniques and optimisations you have out there. Anyways, there are many guidelines you should definitely follow to optimise the scene (I think there's an article in the wiki about performance, that is really worth reading :))
Image

Oogst
OGRE Expert User
OGRE Expert User
Posts: 1034
Joined: Mon Mar 29, 2004 8:49 pm
Location: the Netherlands
x 32
Contact:

Post by Oogst »

For the static geometry, can this be changed at run-time at all? Can I say that for a part of it, I want to change the material or tiling? This would require totalle recalculating the static geometry and is therefor just not feasible at all. Or am I wrong here and is there some dynamic stuff possible?

By the way, I checked the optimalisation part of the WIKI once more, and this made me wonder: if an object is fully outside the viewing frustrum, for instance further away than the far clipping plane, then it is not send to the GPU at all, right? So if I set the far clipping plane very close, only a few rendering calls will be made.

@Kencho:
What you describe for the artists is _exactly_ what we are already doing for some of the objects. That is what I meant with "The holes in the texture show the colour."

User avatar
Kencho
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 4011
Joined: Fri Sep 19, 2003 6:28 pm
Location: Burgos, Spain
x 2
Contact:

Post by Kencho »

Oogst wrote:For the static geometry, can this be changed at run-time at all? Can I say that for a part of it, I want to change the material or tiling? This would require totalle recalculating the static geometry and is therefor just not feasible at all. Or am I wrong here and is there some dynamic stuff possible?
I think you would need to rebuild the static geometry if you want to change the material of some geometry there. As far as I can remember, the StaticGeometry does some optimisation batching meshes with the same material, so that would probably require to break the geometry.
Not the same with materials (I guess). Changing a material parameters such as the ambient reflectance or a texture scale/tiling is independent from the StaticGeometry. Think materials can be shared across many renderables, which is good and bad at the same time. Good because you don't need to update each renderable's material. Bad because it's actually hard to do per-renderable material changes such as opacity or colours (this is probably your case; a different material for each "team" entity, right?)
Oogst wrote:By the way, I checked the optimalisation part of the WIKI once more, and this made me wonder: if an object is fully outside the viewing frustrum, for instance further away than the far clipping plane, then it is not send to the GPU at all, right? So if I set the far clipping plane very close, only a few rendering calls will be made.
As far as I know, and according to my latest tests, yep. I'm not sure at all about this though, so a second opinion from an expert would be great, but I think you're right there ;)
Oogst wrote:@Kencho:
What you describe for the artists is _exactly_ what we are already doing for some of the objects. That is what I meant with "The holes in the texture show the colour."
Ah great!
Image

Vectrex
Ogre Magi
Posts: 1266
Joined: Tue Aug 12, 2003 1:53 am
Location: Melbourne, Australia
x 1
Contact:

Post by Vectrex »

*** WIKIED *** http://www.ogre3d.org/wiki/index.php/Op ... #Materials

also with the atlas textures, could Ogre detect that multiple materials are the same except their texture and actually pack them into one atlas? Would be a tricky but impressive automated feature. Does anyone know of any programs/plugins that can automate this offline?

Oogst
OGRE Expert User
OGRE Expert User
Posts: 1034
Joined: Mon Mar 29, 2004 8:49 pm
Location: the Netherlands
x 32
Contact:

Post by Oogst »

Some more about how it can be done can be found here:

http://www.gamasutra.com/features/20060 ... v_01.shtml

I do not know any plug-ins that will automate this, though.

User avatar
MaxWave
Halfling
Posts: 43
Joined: Fri Mar 10, 2006 6:17 pm

Post by MaxWave »

sinbad wrote: 2. Yes, texture swaps are relativelly expensive as a state change. Note however that OGRE will order your passes by common texture usage in the same texture units to minimise texture state changes so if there is a case whre unit 0 uses the same texture across 3 material passes but texture 1 is different, it will place those together in the ordering so unit 0 stays constant. Only for solids though (transparency needs depth sorting)
Sorry for the question (I do't understant this moment), but Сould you describe this moment in more detail?

User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19265
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 66
Contact:

Post by sinbad »

Which part? I thought that covered it.

User avatar
MaxWave
Halfling
Posts: 43
Joined: Fri Mar 10, 2006 6:17 pm

Post by MaxWave »

so if there is a case whre unit 0 uses the same texture across 3 material passes but texture 1 is different, it will place those together in the ordering so unit 0 stays constant.
this. What means - uses the same texture across 3 material passes
I suppose that material have 3 passes and each have same texture_unit?
but texture 1 is different
which texture? It is in different material? How many passes?
it will place those together in the ordering
place what and where?
so unit 0 stays constant
What exactly is available in view of?
Sorry for a stupid questions, I bad understant context of hardly english.

User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19265
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 66
Contact:

Post by sinbad »

Not 3 passes, 3 texture units. Each pass can have many textures assigned - ogre tries to put passes that use common textures in the same unit close together in the render order to minimise texture changes.

Post Reply