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.
Nickak2003
Goblin
Posts: 272
Joined: Thu Jun 10, 2004 4:19 am
x 26

Re: New InstanceManager: Instancing done the right way

Post by Nickak2003 »

Ok so the problem was I had listed all of the various shader resource directories to include and I guess they were interfering. I removed all but the glsl directory technique 0 works fine. technique 1, VTF, does not work, the program crashes, with the following error:

Code: Select all

Vertex Program:Ogre/Instancing/VTF/shadow_caster_glsl_vs Fragment Program:Ogre/Instancing/shadow_caster_glsl_ps GLSL link result : 
Exception thrown at 0x000001CA59D700E7 in testgamelib.exe: 0xC0000005: Access violation writing location 0x00000000EDBCCAC8.
Check hardware support says that VTF is supported on this machine.

*edit the error seems to happen after frame started. The actual instances were created no problem.

How does the demo browser work such that all of the various shader resource directories are included?
jho
Gnoblar
Posts: 5
Joined: Thu Apr 07, 2016 10:26 am

Re: New InstanceManager: Instancing done the right way

Post by jho »

Hi Ogre folks!

I'm trying to achieve instancing, to render a lot of entities. I'm quite new to the 3D/Shaders/... thing, so I tried for a start to mimic dark_sylinc's test source code and the NewInstancing demo. Here is my test instancing section:

Code: Select all

	mSceneMgr->setAmbientLight( ColourValue(1, 1, 1) );
	mCamera->getViewport()->setClearEveryFrame( true );

	const int numW = 10;
	const int numH = 10;

	InstanceManager *instanceManager = mSceneMgr->createInstanceManager( "MyInstanceMgr", "cube.mesh", ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME, Ogre::InstanceManager::TextureVTF, 300, IM_USEALL );
	//InstanceManager *instanceManager = mSceneMgr->createInstanceManager( "MyInstanceMgr", "cube.mesh", ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME, InstanceManager::HWInstancingBasic, 30, IM_USEALL);
	//InstanceManager *instanceManager = mSceneMgr->createInstanceManager( "MyInstanceMgr", "cube.mesh", ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME, Ogre::InstanceManager::ShaderBased, 80, IM_USEALL );
	for( int i=0; i<numH; ++i )
	{
		for( int j=0; j<numW; ++j )
		{
			InstancedEntity *ent = instanceManager->createInstancedEntity( "Examples/Instancing/VTF/Robot" );
			//InstancedEntity *ent = instanceManager->createInstancedEntity( "Examples/Instancing/HWBasic/Robot" );
			//InstancedEntity *ent = instanceManager->createInstancedEntity( "Examples/Instancing/ShaderBased/Robot" );
			SceneNode *sceneNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
			sceneNode->attachObject( ent );
			sceneNode->setPosition( 8 * i, 5, 8 * j );
			m_instances.push_back( ent );
		}
	}

	instanceManager->defragmentBatches( true );

	mCamera->setPosition( 0, 0, -10 );
	mCamera->lookAt( 0, 0, 10 );
As you can see, I've made attempts with 3 materials from 3 techniques of "NewInstancing" from the Ogre samples.

My problem is that all fail.

1st (Texture VTF) fails with:

Code: Select all

WARNING: material MyInstanceMgr/InstanceBatch_0/VTFMaterialCaster0 has no supportable Techniques and will be blank. Explanation: 
Pass 0: Fragment program Ogre/Instancing/shadow_caster_ps cannot be used - not supported.
First-chance exception at 0x7696c52f in OgreProject.exe: Microsoft C++ exception: Ogre::RenderingAPIException at memory location 0x0032e90c..
2nd (Shader) fails with:

Code: Select all

WARNING: material Examples/Instancing/ShaderBased/shadow_caster has no supportable Techniques and will be blank. Explanation: 
Pass 0: Fragment program Ogre/Instancing/shadow_caster_ps cannot be used - not supported.
First-chance exception at 0x7696c52f in OgreProject.exe: Microsoft C++ exception: Ogre::InvalidParametersException at memory location 0x0047e988..
I 'm certainly missing something here.
I'm using OgreSDK 1.9, Win7 with a lousy Intel HD chip. But the SampleBrowser demos are running fine on it.

Many thanks in advance,

// jho
paroj
OGRE Team Member
OGRE Team Member
Posts: 2093
Joined: Sun Mar 30, 2014 2:51 pm
x 1129

Re: New InstanceManager: Instancing done the right way

Post by paroj »

dark_sylinc wrote: Thu Nov 25, 2010 2:52 am OK, I've hard-coded the value '80'. You should use mSceneMgr->getNumInstancesPerBatch().
The custom material is required. Some integration with RTSS could be made, but I'm not really deep into it. Someone else would be much better doing it.
done for shaderbased and hardwarebasic techniques (for reference)