Ogre仅在视口中显示透视相机内容的一部分

//试验自定义shader,创建一个平面,可在上面贴图
Ogre::Plane plane(Ogre::Vector3::UNIT_X, 300);  
Ogre::MeshManager::getSingleton().createPlane(  
        "plane",Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,   
        plane,500,500,1,1,true,1,1,1,Ogre::Vector3::UNIT_Y);  
Ogre::Entity* ent = mSceneMgr->createEntity("PlaneEntity", "plane");
Ogre::SceneNode *pPlaneNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
pPlaneNode->attachObject(ent);  
ent->setMaterialName("Examples/Rockwall", ResourceGroupManager::INTERNAL_RESOURCE_GROUP_NAME);  //这里可以显示
pPlaneNode->roll( Radian(60.0f * Math::PI / 180.0f) );
pPlaneNode->translate( 100, -130, 0 );


//return; //compare


const Ogre::Real zOrthoCam = -10000;
Ogre::Plane planeTex(Ogre::Vector3::UNIT_Z, 0);
Ogre::MeshManager::getSingleton().createPlane(  
        "planeTex",Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,   
planeTex,(Real)mWindow->getWidth(),(Real)mWindow->getHeight(),1,1,true,1,1,1,Ogre::Vector3::UNIT_Y);
Ogre::Entity* entPlaneTex = mSceneMgr->createEntity("PlaneTexEntity", "planeTex");
Ogre::SceneNode *pPlaneTexNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
pPlaneTexNode->attachObject(entPlaneTex);
pPlaneTexNode->setPosition(0.0f, 0.0f, zOrthoCam - 500.0f );
//设置材质
Ogre::TexturePtr texPortPlane = Ogre::TextureManager::getSingleton().createManual("testTex",  //"texPortPlane"
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, \
mWindow->getWidth(), mWindow->getHeight(), 0, Ogre::PF_R8G8B8, Ogre::TU_RENDERTARGET);


Ogre::RenderTexture *tarTexPortPlane = texPortPlane->getBuffer()->getRenderTarget();
tarTexPortPlane->addViewport( mCamera );


 Ogre::MaterialPtr materialFade = Ogre::MaterialManager::getSingleton().getByName("Car/FadeColorTex")->clone("testMat"); //克隆材质,注意释放内存


Pass *passFade = materialFade->getTechniques()[0]->getPasses()[0];
passFade->setDepthCheckEnabled(true);  
passFade->setDepthWriteEnabled(true);  
passFade->setLightingEnabled(false); 
/*TextureUnitState* stateFade =*/ passFade->createTextureUnitState("testTex"); // "texPortPlane"
GpuProgramParametersSharedPtr ptrFPFade = passFade->getFragmentProgramParameters();


ptrFPFade->setNamedConstant("img",0);
ptrFPFade->setNamedConstant("lum",1.0f);


entPlaneTex->setMaterial(materialFade);


Ogre::Camera *pOrthoCam = mSceneMgr->createCamera("testOrtho");


//设置相机属性
pOrthoCam->setFarClipDistance( 1000.0f );
   pOrthoCam->setNearClipDistance(1.0f);
pOrthoCam->setProjectionType(ProjectionType::PT_ORTHOGRAPHIC);
pOrthoCam->setAspectRatio( Real(mWindow->getWidth() * 0.5f / mWindow->getHeight()) ); //设置ratio似乎只能放在设置宽度之前,否则效果不对
pOrthoCam->setOrthoWindowWidth((Real)mWindow->getWidth() * 0.5f);


SceneNode *pCamNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
pCamNode->attachObject( pOrthoCam );
pCamNode->setPosition( -Real(mWindow->getWidth()) * 0.25f, 0.0f, zOrthoCam);


mWindow->removeAllViewports();
mWindow->addViewport(pOrthoCam, -1, 0.25f, 0.0f, 0.5f, 1.0f);

你可能感兴趣的:(Ogre仅在视口中显示透视相机内容的一部分)