void CompositionHandler::SetCompositorParameter(const std::string &compositorName, const QList< std::pair<std::string, Ogre::Vector4> > &source) const { // find compositor materials Ogre::CompositorPtr compositor = c_manager_->getByName(compositorName); if (compositor.get()) { compositor->load(); for(uint t=0 ; t<compositor->getNumTechniques () ; ++t) { Ogre::CompositionTechnique *ct = compositor->getTechnique(t); if (ct) { for(uint tp=0 ; tp<ct->getNumTargetPasses () ; ++tp) { Ogre:: CompositionTargetPass *ctp = ct->getTargetPass (tp); SetCompositorTargetParameters(ctp, source); } SetCompositorTargetParameters(ct->getOutputTargetPass(), source); } } } }
bool Oculus::setupOgre(Ogre::SceneManager *sm, Ogre::RenderWindow *win, Ogre::SceneNode *parent) { m_window = win; m_sceneManager = sm; Ogre::LogManager::getSingleton().logMessage("Oculus: Setting up Ogre"); if(parent) m_cameraNode = parent->createChildSceneNode("StereoCameraNode"); else m_cameraNode = sm->getRootSceneNode()->createChildSceneNode("StereoCameraNode"); m_cameras[0] = sm->createCamera("CameraLeft"); m_cameras[1] = sm->createCamera("CameraRight"); Ogre::MaterialPtr matLeft = Ogre::MaterialManager::getSingleton().getByName("Ogre/Compositor/Oculus"); Ogre::MaterialPtr matRight = matLeft->clone("Ogre/Compositor/Oculus/Right"); Ogre::GpuProgramParametersSharedPtr pParamsLeft = matLeft->getTechnique(0)->getPass(0)->getFragmentProgramParameters(); Ogre::GpuProgramParametersSharedPtr pParamsRight = matRight->getTechnique(0)->getPass(0)->getFragmentProgramParameters(); Ogre::Vector4 hmdwarp; if(m_stereoConfig) { hmdwarp = Ogre::Vector4(m_stereoConfig->GetDistortionK(0), m_stereoConfig->GetDistortionK(1), m_stereoConfig->GetDistortionK(2), m_stereoConfig->GetDistortionK(3)); } else { hmdwarp = Ogre::Vector4(g_defaultDistortion[0], g_defaultDistortion[1], g_defaultDistortion[2], g_defaultDistortion[3]); } pParamsLeft->setNamedConstant("HmdWarpParam", hmdwarp); pParamsRight->setNamedConstant("HmdWarpParam", hmdwarp); pParamsLeft->setNamedConstant("LensCentre", 0.5f+(m_stereoConfig->GetProjectionCenterOffset()/2.0f)); pParamsRight->setNamedConstant("LensCentre", 0.5f-(m_stereoConfig->GetProjectionCenterOffset()/2.0f)); Ogre::CompositorPtr comp = Ogre::CompositorManager::getSingleton().getByName("OculusRight"); comp->getTechnique(0)->getOutputTargetPass()->getPass(0)->setMaterialName("Ogre/Compositor/Oculus/Right"); for(int i=0;i<2;++i) { m_cameraNode->attachObject(m_cameras[i]); if(m_stereoConfig) { // Setup cameras. m_cameras[i]->setNearClipDistance(m_stereoConfig->GetEyeToScreenDistance()); m_cameras[i]->setFarClipDistance(g_defaultFarClip); m_cameras[i]->setPosition((i * 2 - 1) * m_stereoConfig->GetIPD() * 0.5f, 0, 0); m_cameras[i]->setAspectRatio(m_stereoConfig->GetAspect()); m_cameras[i]->setFOVy(Ogre::Radian(m_stereoConfig->GetYFOVRadians())); // Oculus requires offset projection, create a custom projection matrix Ogre::Matrix4 proj = Ogre::Matrix4::IDENTITY; float temp = m_stereoConfig->GetProjectionCenterOffset(); proj.setTrans(Ogre::Vector3(-m_stereoConfig->GetProjectionCenterOffset() * (2 * i - 1), 0, 0)); m_cameras[i]->setCustomProjectionMatrix(true, proj * m_cameras[i]->getProjectionMatrix()); } else { m_cameras[i]->setNearClipDistance(g_defaultNearClip); m_cameras[i]->setFarClipDistance(g_defaultFarClip); m_cameras[i]->setPosition((i*2-1) * g_defaultIPD * 0.5f, 0, 0); } m_viewports[i] = win->addViewport(m_cameras[i], i, 0.5f*i, 0, 0.5f, 1.0f); m_viewports[i]->setBackgroundColour(g_defaultViewportColour); m_compositors[i] = Ogre::CompositorManager::getSingleton().addCompositor(m_viewports[i],i==0?"OculusLeft":"OculusRight"); m_compositors[i]->setEnabled(true); } m_ogreReady = true; Ogre::LogManager::getSingleton().logMessage("Oculus: Oculus setup completed successfully"); return true; }