void FiveApp::makeMaterialReceiveDecal(const String & matName) { MaterialPtr mat = (MaterialPtr)MaterialManager::getSingleton().getByName(matName); Pass *pass = mat->getTechnique(0)->createPass(); pass->setSceneBlending(SBT_TRANSPARENT_ALPHA); pass->setDepthBias(1); pass->setLightingEnabled(true); TextureUnitState *texState = pass->createTextureUnitState("decal.png"); texState->setProjectiveTexturing(true,mDecalFrustum); texState->setTextureAddressingMode(TextureUnitState::TAM_CLAMP); texState->setTextureFiltering(FO_LINEAR,FO_LINEAR,FO_NONE); texState = pass->createTextureUnitState("decal_filter.png"); texState->setProjectiveTexturing(true,mFilterFrustum); texState->setTextureAddressingMode(TextureUnitState::TAM_CLAMP); texState->setTextureFiltering(TFO_NONE); }
//------------------------------------------------------------------------------------- void BasicTutorial2::createScene(void) { mSceneMgr->setAmbientLight(Ogre::ColourValue(0, 0, 0)); //mSceneMgr->setShadowTechnique(Ogre::SHADOWTYPE_STENCIL_ADDITIVE); Ogre::Entity* entNinja = mSceneMgr->createEntity("Ninja", "ninja.mesh"); entNinja->setCastShadows(true); mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(entNinja); Ogre::Plane plane(Ogre::Vector3::UNIT_Y, 0); Ogre::MeshManager::getSingleton().createPlane("ground", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane, 1500, 1500, 20, 20, true, 1, 5, 5, Ogre::Vector3::UNIT_Z); Ogre::Entity* entGround = mSceneMgr->createEntity("GroundEntity", "ground"); mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(entGround); entGround->setMaterialName("Examples/Rockwall"); //entGround->setMaterialName("RttMat"); entGround->setCastShadows(false); Ogre::Entity* ogreHead = mSceneMgr->createEntity("Head", "ogrehead.mesh"); Ogre::SceneNode* headNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("HeadNode"); headNode->attachObject(ogreHead); headNode->setPosition(50,120,0); Ogre::Light* pointLight = mSceneMgr->createLight("pointLight"); pointLight->setType(Ogre::Light::LT_POINT); pointLight->setPosition(Ogre::Vector3(0, 150, 250)); pointLight->setDiffuseColour(1.0, 0.0, 0.0); pointLight->setSpecularColour(1.0, 0.0, 0.0); Ogre::Light* directionalLight = mSceneMgr->createLight("directionalLight"); directionalLight->setType(Ogre::Light::LT_DIRECTIONAL); directionalLight->setDiffuseColour(Ogre::ColourValue(.25, .25, 0)); directionalLight->setSpecularColour(Ogre::ColourValue(.25, .25, 0)); directionalLight->setDirection(Ogre::Vector3( 0, -1, 1 )); Ogre::Light* spotLight = mSceneMgr->createLight("spotLight"); spotLight->setType(Ogre::Light::LT_SPOTLIGHT); spotLight->setDiffuseColour(0, 0, 1.0); spotLight->setSpecularColour(0, 0, 1.0); spotLight->setDirection(-1, -1, 0); spotLight->setPosition(Ogre::Vector3(300, 300, 0)); spotLight->setSpotlightRange(Ogre::Degree(35), Ogre::Degree(50)); //------------------ using namespace Ogre; TexturePtr texture = TextureManager::getSingleton(). createManual( "RttTex",ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, TEX_TYPE_2D,512, 512, 0, PF_R8G8B8, TU_RENDERTARGET ); RenderTarget *rttTex = texture->getBuffer()->getRenderTarget(); mReflectCam = mSceneMgr->createCamera("ReflectCam"); mReflectCam->setOrientation(mCamera->getOrientation()); mReflectCam->setPosition(mCamera->getPosition()); mReflectCam->setNearClipDistance(mCamera->getNearClipDistance()); mReflectCam->setFarClipDistance(mCamera->getFarClipDistance()); mReflectCam->setAspectRatio( (Real)mWindow->getViewport(0)->getActualWidth() / (Real)mWindow->getViewport(0)->getActualHeight()); Viewport *v = rttTex->addViewport( mReflectCam ); v->setClearEveryFrame( true ); v->setBackgroundColour( ColourValue::Black ); //MaterialPtr mat = MaterialManager::getSingleton().create("RttMat",ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); //TextureUnitState* t = mat->getTechnique(0)->getPass(0)->createTextureUnitState("RustedMetal.jpg"); MaterialPtr mat; TextureUnitState *t = NULL; Entity *entMaterial = entGround ; int nCnt = entGround->getNumSubEntities(); for ( int i=0; i<nCnt; i++) { SubEntity* _SubEnt = entMaterial->getSubEntity(i); MaterialPtr _MaterPtr; Pass * _Pass; mat = _SubEnt->getMaterial(); break; } t = mat->getTechnique(0)->getPass(0)->createTextureUnitState("RttTex"); // Blend with base texture t->setColourOperationEx(LBX_BLEND_MANUAL, LBS_TEXTURE, LBS_CURRENT,ColourValue::White, ColourValue::White, 0.65); t->setTextureAddressingMode(TextureUnitState::TAM_CLAMP); t->setProjectiveTexturing(true, mReflectCam); rttTex->addListener(this); // set up linked reflection mReflectCam->enableReflection(plane); // Also clip mReflectCam->enableCustomNearClipPlane(plane); //------------------ #if 0 // skybox //mSceneMgr->setSkyBox(true, "Examples/SpaceSkyBox");//, 10); //mSceneMgr->setSkyBox(true, "Examples/SpaceSkyBox", 5000, false); #endif #if 0 // skydome mSceneMgr->setSkyDome(true, "Examples/CloudySky", 5, 8); #endif #if 0 //skyplane Ogre::Plane plane2; plane2.d = 1000; plane2.normal = Ogre::Vector3::NEGATIVE_UNIT_Y; //mSceneMgr->setSkyPlane(true, plane2, "Examples/SpaceSkyPlane", 1500, 75); mSceneMgr->setSkyPlane(true, plane, "Examples/CloudySky", 1500, 40, true, 1.5f, 150, 150); #endif #if 0 Ogre::ColourValue fadeColour(0.9, 0.9, 0.9); mWindow->getViewport(0)->setBackgroundColour(fadeColour); //mSceneMgr->setFog(Ogre::FOG_LINEAR, fadeColour, 0.0, 50, 500); //mSceneMgr->setFog(Ogre::FOG_EXP, fadeColour, 0.005); mSceneMgr->setFog(Ogre::FOG_EXP2, fadeColour, 0.003); #endif { Ogre::ColourValue fadeColour(0.1, 0.1, 0.1); mWindow->getViewport(0)->setBackgroundColour(fadeColour); mSceneMgr->setFog(Ogre::FOG_LINEAR, fadeColour, 0.0, 10, 150); Ogre::Plane plane; plane.d = 10; plane.normal = Ogre::Vector3::NEGATIVE_UNIT_Y; mSceneMgr->setSkyPlane(true, plane, "Examples/SpaceSkyPlane", 100, 45, true, 0.5, 150, 150); } }