Infact do I even need to do that, will set position on the instanced entity work? If so how can I get glsl to display the instanced entity... it's showing nothing.
The demo sample uses worldMatrix3x4Array , but I just want to pass position, it seems if I don't have worldMatrix3x4Array, it will just fail at glsl compile with ...
so my code looks something like this..what(): OGRE EXCEPTION(2:InvalidParametersException): Material 'material' is malformed for this instancing technique in InstanceBatchShader::calculateMaxNumInstances at /var/tmp/portage/dev-games/ogre-1.9.0-r1/work/ogre-1.9.0/OgreMain/src/OgreInstanceBatchShader.cpp (line 119)
Code: Select all
Ogre::InstanceManager *grid_segment = OgreFramework::getSingletonPtr()->m_pSceneMgr->createInstanceManager( "meh", name, Ogre::ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME, Ogre::InstanceManager::ShaderBased, 80, Ogre::IM_USEALL );
grid_segment->setNumCustomParams( 1024 );
std::vector<Ogre::SceneNode> m_instancedNodes; //Use an array of SceneNodes not created by Ogre
std::vector<Ogre::MovableObject*> mEntities;
mEntities.reserve( pow((map_size/segment_size), 2) );
m_instancedNodes.reserve( pow((map_size/segment_size), 2) );
m_instancedNodes.resize( pow((map_size/segment_size), 2), Ogre::SceneNode( 0 ) ); //Create them
for ( int x = 0 ; x < map_size/segment_size; x++) {
int x_position = 0;
for ( int y = 0 ; y < map_size/segment_size; y++) {
int entity_id = x*(map_size/segment_size)+y;
Ogre::Vector3 strip_position = Ogre::Vector3((float)x_position, 0.0, (float)y_position);
Ogre::InstancedEntity *thisInstance = OgreFramework::getSingletonPtr()->m_pSceneMgr->createInstancedEntity( "material", "meh" );
thisInstance->setCastShadows(false);
thisInstance->setCustomParam( entity_id, Ogre::Vector4((float)x_position, 0.0, (float)y_position, 0) );
thisInstance->setScale(Ogre::Vector3(1000,1000,1000));
mEntities.push_back(thisInstance);
m_instancedNodes[entity_id].attachObject( mEntities[entity_id] );
m_instancedNodes[entity_id]._update( true, true ); //Needed after attach.
m_instancedNodes[entity_id].setPosition(strip_position);
x_position = x_position + strip_offset;
}
y_position = y_position + strip_offset;
}