예제 #1
0
 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);
             }
         }
     }
 }
예제 #2
0
KBOOL Kylin::EffectFade::Initialize()
{

    Ogre::CompositorPtr spCompositor = Ogre::CompositorManager::getSingleton().create(
                                           m_sName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME
                                       );

    Ogre::CompositionTechnique *t;
    Ogre::CompositionTechnique::TextureDefinition *td;
    Ogre::CompositionTargetPass *tp;
    Ogre::CompositionPass *pass;

    t = spCompositor->createTechnique();
    td = t->createTextureDefinition("scene");
    td->width = 1;
    td->height = 1;
    td->formatList.push_back(Ogre::PF_X8R8G8B8);

    tp = t->createTargetPass();
    tp->setInputMode(Ogre::CompositionTargetPass::IM_PREVIOUS);
    tp->setOutputName("scene");

    tp = t->getOutputTargetPass();
    tp->setInputMode(Ogre::CompositionTargetPass::IM_NONE);
    pass = tp->createPass();
    pass->setType(Ogre::CompositionPass::PT_RENDERQUAD);
    pass->setMaterialName("PostFilters/Fade");
    pass->setInput(0, "scene");
    pass->setIdentifier(0xDEADBADE);

    // receive default parameters from material script
    m_fColourAmount = 0;
    m_fGrayAmount	= 1;
    if (!pass->getMaterial().isNull())
    {
        Ogre::GpuProgramParametersSharedPtr parameters = pass->getMaterial()->getTechnique(0)->getPass(0)->getFragmentProgramParameters();
        /*#if OGRE_VERSION >= 0x010300*/
        const Ogre::GpuConstantDefinition* def;

        def = parameters->_findNamedConstantDefinition("colour_amount");
        if (def)
            parameters->_readRawConstants(def->physicalIndex, 1, &m_fColourAmount);
        def = parameters->_findNamedConstantDefinition("gray_amount");
        if (def)
            parameters->_readRawConstants(def->physicalIndex, 1, &m_fGrayAmount);
// #else
// 		GpuProgramParameters::RealConstantEntry* entry;
//
// 		entry = parameters->getNamedRealConstantEntry("colour_amount");
// 		if (entry && entry->isSet)
// 			m_fColourAmount = entry->val[0];
//
// 		entry = parameters->getNamedRealConstantEntry("gray_amount");
// 		if (entry && entry->isSet)
// 			m_fGrayAmount = entry->val[0];
// #endif
    }

    KBOOL bRet = EffectCompositor::Initialize();

    if (bRet)
        m_pCompositor->addListener(this);

    return bRet;
}
예제 #3
0
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;
}