A similar question was asked previously in http://stackoverflow.com/questions/1123 ... h-objects/, however no satisfactory answer seems exist. Enabling [depth shadow mapping as described here](http://www.ogre3d.org/tikiwiki/tiki-ind ... ow+Mapping) does not seem to fix it. Below I have attached the way I have tried to integrate this in to demo 6.
I mainly ask because the [Gazebo](http://gazebosim.org) physics simulator uses the projective texture to emulate projectors on robots, which are used to generate simulated data for testing algorithms for [3D scanners doing depth reconstruction using structured light](http://en.wikipedia.org/wiki/3D_scanner ... ured_light). However, because the projection goes through objects, rather than having "shadows", the simulated data is wrong. I'd like to fix this implementation, but I would rather use something built in to Ogre if possible rather than implementing it in a material script.
Code: Select all
void IntermediateTutorial6::createScene(void)
{
mSceneMgr->setShadowTextureSelfShadow(true);
// Set the caster material which uses the shaders defined above
mSceneMgr->setShadowTextureCasterMaterial("Ogre/DepthShadowmap/Caster/Float");
// Set the pixel format to floating point
mSceneMgr->setShadowTexturePixelFormat(Ogre::PF_FLOAT32_R);
// You can switch this on or off, I suggest you try both and see which works best for you
mSceneMgr->setShadowCasterRenderBackFaces(true);
// Finally enable the shadows using texture additive integrated
mSceneMgr->setShadowTechnique(Ogre::SHADOWTYPE_TEXTURE_ADDITIVE_INTEGRATED);
mSceneMgr->setAmbientLight(Ogre::ColourValue(0.2f, 0.2f, 0.2f));
Ogre::Light* light = mSceneMgr->createLight("MainLight");
light->setPosition(20, 80, 50);
mCamera->setPosition(60, 200, 70);
mCamera->lookAt(0,0,0);
//set up the ogre heads
Ogre::Entity* ent;
for (int i = 0; i < 6; i++)
{
Ogre::SceneNode* headNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
ent = mSceneMgr->createEntity("head" + Ogre::StringConverter::toString(i), "ogrehead.mesh","General");
ent->setCastShadows(true);
headNode->attachObject(ent);
Ogre::Radian angle(i + Ogre::Math::TWO_PI / 6);
headNode->setPosition(75 * Ogre::Math::Cos(angle), 0, 75 * Ogre::Math::Sin(angle));
}
//create the projector and turn it on
createProjector();
for(unsigned int i = 0; i < ent->getNumSubEntities(); i++)
{
makeMaterialReceiveDecal(ent->getSubEntity(i)->getMaterialName());
}
}
Code: Select all
void IntermediateTutorial6::makeMaterialReceiveDecal(const Ogre::String& matName)
{
//get the material information so that we can modify it
Ogre::MaterialPtr mat = (Ogre::MaterialPtr)Ogre::MaterialManager::getSingleton().getByName(matName);
Ogre::Pass* pass = mat->getTechnique(0)->createPass();
//set the scene blending so that we don't get smears at the edge of our texture
pass->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA);
pass->setDepthBias(1);
pass->setLightingEnabled(false);
pass->setDepthCheckEnabled(true);
pass->setDepthFunction(Ogre::CMPF_LESS);
Ogre::TextureUnitState* texState = pass->createTextureUnitState("Decal.png");
texState->setProjectiveTexturing(true, mDecalFrustum);
texState->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);
texState->setTextureFiltering(Ogre::FO_POINT, Ogre::FO_LINEAR, Ogre::FO_NONE);
texState = pass->createTextureUnitState("Decal_filter.png");
texState->setProjectiveTexturing(true, mFilterFrustum);
texState->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);
texState->setTextureFiltering(Ogre::TFO_NONE);
}