New InstanceManager: Instancing done the right way

Discussion area about developing or extending OGRE, adding plugins for it or building applications on it. No newbie questions please, use the Help forum for that.
Post Reply
jonim8or
Goblin
Posts: 287
Joined: Mon Dec 08, 2008 4:49 pm
x 10

Re: New InstanceManager: Instancing done the right way

Post by jonim8or »

I've tried using the ShaderBased InstanceManager, but when I make the numInstancesPerBatch too big (e.g. 255), it crashes. :(

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 4501
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 936
Contact:

Re: New InstanceManager: Instancing done the right way

Post by dark_sylinc »

sparkprime wrote:I noticed this documentation appears to be copy/pasted from something unrelated
Ooops, thanks
sparkprime wrote:I've tried using the ShaderBased InstanceManager, but when I make the numInstancesPerBatch too big (e.g. 255), it crashes
First, such high number isn't technically supported (maximum theoretical value is 256 / 3 = 85, truncated) in ShaderBased. InstanceManager should be able to automatically crop it down.
Second, if you're writing in your HLSL/Cg/GLSL shader something like "float4x3 myMatrices[255]" it's probably crashing on that side because it's invalid code.
Third, check the Ogre.log. Probably InstanceManager is telling you there's something wrong with the shader, unless the shader error made Ogre crash before it could warn you.

adria
Gnoblar
Posts: 4
Joined: Thu Apr 07, 2011 1:57 pm
Location: Rennes, France

Re: New InstanceManager: Instancing done the right way

Post by adria »

Hi ,
I was testing the new instancing system myself and had what seemed a suspect behaviour.
I tried to make a setVisible(false) to some entities but it seems that when all the entities of a batch don't have the same mVisible, the visibility is not affected.
Is it a bug or am I not using the instancing system the right way ?
Thanks in advance,

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 4501
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 936
Contact:

Re: New InstanceManager: Instancing done the right way

Post by dark_sylinc »

Hi adria,

This is definately a bug. I'll check in the bug fix. Meanwhile you can solve it in your locally by going to OgreInstancedEntity.cpp lines 136 & 168 in getTransforms & getTransforms3x4 respectively, and change this line:

Code: Select all

if( mParentNode )
with this one:

Code: Select all

if( mParentNode && isVisible() )
Thanks for the bug report
Cheers
Dark Sylinc

adria
Gnoblar
Posts: 4
Joined: Thu Apr 07, 2011 1:57 pm
Location: Rennes, France

Re: New InstanceManager: Instancing done the right way

Post by adria »

That seems to work ! Thanks !

darkip
Gnoblar
Posts: 11
Joined: Sat Mar 19, 2011 12:50 pm

Re: New InstanceManager: Instancing done the right way

Post by darkip »

Really nice work! The hardware instancing is giving me some great performance improvements but I'm curious as to whether support for meshes using multiple materials will be implemented?

adria
Gnoblar
Posts: 4
Joined: Thu Apr 07, 2011 1:57 pm
Location: Rennes, France

Re: New InstanceManager: Instancing done the right way

Post by adria »

I have the same question... I'm trying to use it for instancing trees or other objects but that's not so easy to find a tree mesh using just one material...

kangshe
Gnoblar
Posts: 2
Joined: Wed Apr 27, 2011 9:53 am

Re: New InstanceManager: Instancing done the right way

Post by kangshe »

hi ,I was trying to use mutiple InstanceManager in my project. I'm new to Ogre, so I consult the sample. However when I tried to use the model jaiqua instead of robot with the technique Shaderbased , the entity became strange. and with no instancing it's the same .but HW instancing goes well.
here is a screenshot:
Image

i did add a material in the ShaderInstancing.material

can you tell me why?

or what I need is to learn shader programe?

Thank you for your time.


I'm from China,so the network may be slow. Sorry...This is a address for the screenshot
http://hi.baidu.com/twcicle/album/item/ ... 4fe9.html#
Last edited by kangshe on Wed Apr 27, 2011 1:43 pm, edited 1 time in total.

User avatar
spacegaier
OGRE Team Member
OGRE Team Member
Posts: 4293
Joined: Mon Feb 04, 2008 2:02 pm
Location: Germany
x 127
Contact:

Re: New InstanceManager: Instancing done the right way

Post by spacegaier »

No screenshot visible here.
Ogre Admin [Admin, Dev, PR, Finance, Wiki, etc.] | BasicOgreFramework | AdvancedOgreFramework
Don't know what to do in your spare time? Help the Ogre wiki grow! Or squash a bug...

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 4501
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 936
Contact:

Re: New InstanceManager: Instancing done the right way

Post by dark_sylinc »

I was able to see the screenshot. I'll take a look later.
Probably the bone count is very high and the shader doesn't hold enough data. Will research. Thanks for the report.
darkip wrote:Really nice work! The hardware instancing is giving me some great performance improvements but I'm curious as to whether support for meshes using multiple materials will be implemented?
Check the first post again, I've updated it with a code snippet showing how to do that. Hope it helps

Cheers
Dark Sylinc

darkip
Gnoblar
Posts: 11
Joined: Sat Mar 19, 2011 12:50 pm

Re: New InstanceManager: Instancing done the right way

Post by darkip »

Just a small example of what we've done using the basic HW instancing. Ignore the framerate, it's the video recorder being slow.

http://www.inflatablegoldfish.com/swarming.mov

The movement of each entity in the swarm depends on that of it's neighbours. We parallelised the algorithm using openMP and it's pretty impressive!

LBDude
Gnome
Posts: 389
Joined: Mon Jul 26, 2010 10:53 pm
x 22

Re: New InstanceManager: Instancing done the right way

Post by LBDude »

I'm going to try to use this in my deferred lighting piple to render light volumes. I think what I need is I need to be able to set a few custom variables, variables that is necessary for the radiance computations. I sync + updated to the latest and I begun to look at the code to see how I could approach this. Purely FYI. If I can contribute back anything I will.
My blog here.
Game twitter here

LBDude
Gnome
Posts: 389
Joined: Mon Jul 26, 2010 10:53 pm
x 22

Re: New InstanceManager: Instancing done the right way

Post by LBDude »

I'm going to do some testing first by creating my lights as HW basic instanced entities. For world position I can extract this out of the world transform matrix and keep rest of the parameters as shader constants. This way I can see how it performs before I proceed any further. If instancing turns out to be a good idea then I could either 1) make my own custom thing using HardwareBuffers with instancing, 2) subclass InstanceBatch and just copy what HWBasics is doing--remember I need to implement custom parameters, 3) Implement custom parameters function by modifying VTF, Shader, HW InstanceBatch classes to allow insertion of custom parameters.
My blog here.
Game twitter here

jsding
Greenskin
Posts: 105
Joined: Tue Dec 14, 2010 9:46 am
x 1
Contact:

Re: New InstanceManager: Instancing done the right way

Post by jsding »

Is GLES Render System supported ? I trying use this feature in my iphone app, but it crashes : EXE_BAD_ACCESS.

Thanks for your help!

User avatar
masterfalcon
OGRE Team Member
OGRE Team Member
Posts: 4270
Joined: Sun Feb 25, 2007 4:56 am
Location: Bloomington, MN
x 126
Contact:

Re: New InstanceManager: Instancing done the right way

Post by masterfalcon »

No, instancing is not supported in GL ES

adria
Gnoblar
Posts: 4
Joined: Thu Apr 07, 2011 1:57 pm
Location: Rennes, France

Re: New InstanceManager: Instancing done the right way

Post by adria »

Hello again,
I would like to set a material dynamically like this for an Entity :

Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().create("myMaterial",Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);

mat->setAmbient(r,g,b);
mat->setDiffuse(r,g,b,1);
mat->setSpecular(0,0,0,1);

m_Ent->setMaterialName("myMaterial");

But I see there are no setMarialName function for an InstancedEntity and I would have liked for example to color a mesh according to its velocity... Wouldn't it be possible ?
Thks in advance !

jonim8or
Goblin
Posts: 287
Joined: Mon Dec 08, 2008 4:49 pm
x 10

Re: New InstanceManager: Instancing done the right way

Post by jonim8or »

Is there a way to set a renderqueuegroupid for an instancingmanager / batch?

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 4501
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 936
Contact:

Re: New InstanceManager: Instancing done the right way

Post by dark_sylinc »

jonim8or wrote:Is there a way to set a renderqueuegroupid for an instancingmanager / batch?
Hi, not at the moment. Should be easy to add (would be per batch).

I'm currently with a severe lack of free time unfortunately. Until mid July at least don't expect updates until that time.

You may "hack" around it by calling instancedEntity->_getOwner()->setRenderQueueGroup( ... )
This will affect all instanced entities within that batch, but it won't affect new batches that gets created and you don't have a clean way to tell when when are new batches created.

Cheers
Dark Sylinc

jonim8or
Goblin
Posts: 287
Joined: Mon Dec 08, 2008 4:49 pm
x 10

Re: New InstanceManager: Instancing done the right way

Post by jonim8or »

that hack will be fine for now. Thanks!

User avatar
Mattan Furst
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 260
Joined: Tue Jan 01, 2008 11:28 am
Location: Israel
x 32

Re: New InstanceManager: Instancing done the right way

Post by Mattan Furst »

@dark_sylinc

Hello dark_sylinc,
I want to add some functionality to the instance manager. This idea is meant to improve the framerate when dealing with large animated crowds.

The idea behind this is as follows. Each entity in the crowd may have a different animation. However I make the following assumptions:
  • All entities have the same mesh and skeleton
  • There is a limited amount of unique animations states assigned to the entities. (in my case all entities share among themselves around 20 different animation states).
The idea is to use the HW_VTF instance batch as a basis. However instead of writing the animation of each entity, I only write the 20 or so different animation states into a look-up-table. The information will include only the bone matrices not the world-bone matrices. I then tell each entity through the instance vertex buffer to which area of the vertex texture it should look. I then also add in the world transform matrix of each entity to the instance vertex buffer.

When rendering large crowds with complex bone structure this method should cut down on memory usage, cpu time, and memory bandwidth.

Any thoughts?

P.S.
The next phases in this project will be to add support for this to the RTShader and texture atlasing for larger variance in the crowed.
it's turtles all the way down

User avatar
Assaf Raman
OGRE Team Member
OGRE Team Member
Posts: 3092
Joined: Tue Apr 11, 2006 3:58 pm
Location: TLV, Israel
x 76

Re: New InstanceManager: Instancing done the right way

Post by Assaf Raman »

So basically you suggest more flexibility with the option to use the same animation for different instanced entities, the price is a new 4x3 matrix in the vertex buffer (one per instance), and one more matrix multiplication in the shader. You can still use a one to one ratio of entities to animation - to get the current behavior.

Right?
Is this the only price to pay?
Do you plan also to support the current behavior (without the new 4x3 matrix and matrix multiplication in the shader) or only the new behavior will be supported?
How will the user update the animations?
Watch out for my OGRE related tweets here.

User avatar
masterfalcon
OGRE Team Member
OGRE Team Member
Posts: 4270
Joined: Sun Feb 25, 2007 4:56 am
Location: Bloomington, MN
x 126
Contact:

Re: New InstanceManager: Instancing done the right way

Post by masterfalcon »

What about using Texture Buffer Objects(in GL3Plus at least, not sure about DX) for the look up?

User avatar
Assaf Raman
OGRE Team Member
OGRE Team Member
Posts: 3092
Joined: Tue Apr 11, 2006 3:58 pm
Location: TLV, Israel
x 76

Re: New InstanceManager: Instancing done the right way

Post by Assaf Raman »

masterfalcon wrote:What about using Texture Buffer Objects(in GL3Plus at least, not sure about DX) for the look up?
Vertex texture is being used, isn't vertex texture same as "Texture Buffer Objects"?
Watch out for my OGRE related tweets here.

User avatar
masterfalcon
OGRE Team Member
OGRE Team Member
Posts: 4270
Joined: Sun Feb 25, 2007 4:56 am
Location: Bloomington, MN
x 126
Contact:

Re: New InstanceManager: Instancing done the right way

Post by masterfalcon »

It could be. I'm not familiar with the DX nomenclature. http://www.opengl.org/registry/specs/EX ... object.txt

User avatar
Assaf Raman
OGRE Team Member
OGRE Team Member
Posts: 3092
Joined: Tue Apr 11, 2006 3:58 pm
Location: TLV, Israel
x 76

Re: New InstanceManager: Instancing done the right way

Post by Assaf Raman »

Let me say it this way: vertex textures are "Texture Buffer Objects".
"Texture Buffer Objects" are being used currently in OGRE in this case, Mattan change will not change that.
Watch out for my OGRE related tweets here.

Post Reply