void StereoController::TakeScreenshots(QString path, QString filename)
    {
      
      if (stereo_views_.count() == 0) 
      {
          LogError("StereoController: Cannot take stereographic screenshots. Stereo not enabled!");
          return;
      }

      // FIXME relies on that there is only one external window and
      // its the right side window for stereographical stuff
      QString leftname = filename.replace(".jpg", "_left.jpg");
      QString rightname = filename.replace("_left.jpg", "_right.jpg");

      Ogre::CompositorInstance* comp = stereo_views_["stereoview0"]->GetCompositor();

      if (!comp) 
      {
          LogError("StereoController: Wrong stereographic mode. No Compositor. Cannot take screenshots!");
          return;
      }

      comp->getRenderTarget("Stereo/Left")->writeContentsToFile(path.toStdString() + leftname.toStdString());
      comp->getRenderTarget("Stereo/Right")->writeContentsToFile(path.toStdString() + rightname.toStdString());
    }
Exemple #2
0
    bool CompositionHandler::AddCompositor(const std::string &compositor, Ogre::Viewport *vp, int position)
    {
        bool succesfull = false;

        if (c_manager_!=0 && vp != 0)
        {
            Ogre::CompositorInstance* comp = c_manager_->addCompositor(vp, compositor, position);
            if(comp != 0)
            {
                if(compositor == "HDR" || compositor == "Strong HDR")
                {
                    comp->addListener(&hdr_listener_);
                    hdr_listener_.notifyViewportSize(vp->getActualWidth(), vp->getActualHeight());
                    hdr_listener_.notifyCompositor(comp);
                }
                else if(compositor == "Gaussian Blur")
                {
                    comp->addListener(&gaussian_listener_);
                    gaussian_listener_.notifyViewportSize(vp->getActualWidth(), vp->getActualHeight());
                }

                c_manager_->setCompositorEnabled(vp, compositor, true);
                succesfull=true;
            }
        }
        
        if (!succesfull)
            ::LogWarning("Failed to enable effect: " + compositor);
        
        return succesfull;
    }
void MainCamera::enableCompositor(const std::string& compositorName, bool enable)
{
	if (enable) {
		S_LOG_INFO("Enabling compositor '" << compositorName<< "'.");
	} else {
		S_LOG_INFO("Disabling compositor '" << compositorName<< "'.");
	}
	if (std::find(mLoadedCompositors.begin(), mLoadedCompositors.end(), compositorName) == mLoadedCompositors.end()) {
		Ogre::CompositorInstance* compositor = Ogre::CompositorManager::getSingleton().addCompositor(mWindow.getViewport(0), compositorName);
		if (compositor) {
			bool hasErrors = false;
			//There's a bug in Ogre which will causes a segfault during rendering if a compositor has an invalid shader.
			//We therefore need to check for this here, and disable the shader if so is the case.
			compositor->getCompositor()->load();
			hasErrors = !validateCompositionTargetPass(*compositor->getTechnique()->getOutputTargetPass());
			if (!hasErrors) {
				Ogre::CompositionTechnique::TargetPassIterator targetPassIter = compositor->getTechnique()->getTargetPassIterator();
				while (targetPassIter.hasMoreElements() && !hasErrors) {
					hasErrors = !validateCompositionTargetPass(*targetPassIter.getNext());
				}
			}
			if (hasErrors) {
				S_LOG_FAILURE("Compositor "<< compositorName <<" has errors and will be disabled.");
				Ogre::CompositorManager::getSingleton().removeCompositor(mWindow.getViewport(0), compositorName);
			} else {
				compositor->setEnabled(true);
				mLoadedCompositors.push_back(compositorName);
			}
		}
	} else {
		Ogre::CompositorManager::getSingleton().setCompositorEnabled(mWindow.getViewport(0), compositorName, enable);
	}
}
	void Main::InitCompositor()
	{
		mSceneRenderCompositor = Ogre::CompositorManager::getSingleton().addCompositor(GetViewport(), "RenderHDRScene");
		mSceneRenderCompositor->addListener(new VolumetricLightListener());
		Ogre::CompositorManager::getSingleton().setCompositorEnabled(GetViewport(), "RenderHDRScene", true);
		Ogre::CompositorInstance *hdrinstance = Ogre::CompositorManager::getSingleton().addCompositor(Main::Instance().GetViewport(), "DownsampleHDR1");
		HDRListener *hdrListener = new HDRListener(); 
		hdrinstance->addListener(hdrListener);
		hdrListener->notifyViewportSize(mViewport->getActualWidth(), mViewport->getActualHeight());
		hdrListener->notifyCompositor(hdrinstance);
		Ogre::CompositorManager::getSingleton().setCompositorEnabled(GetViewport(), "DownsampleHDR1", true);
	}
		void PostEffect::AssignToViewport(Viewport& viewport)
		{
			#if defined ION_RENDERER_OGRE3D
			Ogre::CompositorInstance* compositorInstance = Ogre::CompositorManager::getSingleton().addCompositor(viewport.GetOgreViewportInterface(), mName.c_str());
			ion::debug::Assert(compositorInstance != NULL, "PostEffect::AssignToViewport() - Could not create compositor instance, did its materials load successfully?");
			compositorInstance->setEnabled(true);

			if(mOgreCompositorListener)
			{
				compositorInstance->addListener(mOgreCompositorListener);
			}
			#endif
		}
void DeferredShadingSystem::logCurrentMode(void)
{
	if (mActive==false)
	{
		Ogre::LogManager::getSingleton().logMessage("No Compositor Enabled!");
		return;
	}

	Ogre::CompositorInstance* ci = mInstance[mCurrentMode];
	assert(ci->getEnabled()==true);

	Ogre::LogManager::getSingleton().logMessage("Current Mode: ");
	Ogre::LogManager::getSingleton().logMessage(ci->getCompositor()->getName());
}
Exemple #7
0
void CameraBlurListener::notifyMaterialRender(Ogre::uint32 pass_id, Ogre::MaterialPtr &mat)
{
	if (pass_id == 999) 
	{
		if(mApp->pGame->pause == false)
		{
			//acquire the texture flipping attribute in the first frame
			if(compositorinstance)
			{
				mRequiresTextureFlipping  = compositorinstance->getRenderTarget("previousscene")->requiresTextureFlipping();
				compositorinstance=NULL;
			}
			// this is the camera you're using
			#ifndef ROAD_EDITOR
			Ogre::Camera *cam = mApp->mSplitMgr->mCameras.front();
			#else
			Ogre::Camera *cam = mApp->mCamera;
			#endif
			// get the pass
			Ogre::Pass *pass = mat->getBestTechnique()->getPass(0);
			Ogre::GpuProgramParametersSharedPtr  params = pass->getFragmentProgramParameters();
       
			const Ogre::RenderTarget::FrameStats& stats =  mApp->getWindow()->getStatistics();
			float m_lastFPS =stats.lastFPS;
	
			Ogre::Matrix4 projectionMatrix   = cam->getProjectionMatrix();
			if (mRequiresTextureFlipping)
            {
                // Because we're not using setProjectionMatrix, this needs to be done here
                // Invert transformed y
                projectionMatrix[1][0] = -projectionMatrix[1][0];
                projectionMatrix[1][1] = -projectionMatrix[1][1];
                projectionMatrix[1][2] = -projectionMatrix[1][2];
                projectionMatrix[1][3] = -projectionMatrix[1][3];
            }
			Ogre::Matrix4 iVP = (projectionMatrix * cam->getViewMatrix()).inverse();

			if (params->_findNamedConstantDefinition("EPF_ViewProjectionInverseMatrix"))
				 params->setNamedConstant("EPF_ViewProjectionInverseMatrix", iVP);
			if (params->_findNamedConstantDefinition("EPF_PreviousViewProjectionMatrix"))
				params->setNamedConstant("EPF_PreviousViewProjectionMatrix", prevviewproj);
			if (params->_findNamedConstantDefinition("intensity"))
				params->setNamedConstant("intensity", mApp->pSet->motionblurintensity);
	
			float interpolationFactor = m_lastFPS * 0.03f ; //* m_timeScale m_timeScale is a multiplier to control motion blur interactively
			Ogre::Quaternion current_orientation = cam->getDerivedOrientation();
			Ogre::Vector3 current_position = cam->getDerivedPosition();
			Ogre::Quaternion estimatedOrientation = Ogre::Quaternion::Slerp(interpolationFactor, current_orientation, (m_pPreviousOrientation));
			Ogre::Vector3 estimatedPosition    = (1-interpolationFactor) * current_position + interpolationFactor * (m_pPreviousPosition);
			Ogre::Matrix4 prev_viewMatrix = Ogre::Math::makeViewMatrix(estimatedPosition, estimatedOrientation);//.inverse().transpose();
			// compute final matrix
			prevviewproj = projectionMatrix * prev_viewMatrix;

			// update position and orientation for next update time
			m_pPreviousOrientation = current_orientation;
			m_pPreviousPosition = current_position;			
		}

	}
}
	//---------------------------------------------------------------------
	void CompositorDemo_FrameListener::updateDebugRTTWindow(void)
	{
		// Clear listbox
		mDebugRTTListbox->resetList();
		// Clear imagesets
		mDebugRTTStaticImage->setProperty("Image", "");
		for (ImageSetList::iterator isIt = mDebugRTTImageSets.begin();
			isIt != mDebugRTTImageSets.end(); ++isIt)
		{
			CEGUI::ImagesetManager::getSingleton().destroyImageset(*isIt);
		}
		mDebugRTTImageSets.clear();
		Ogre::set<Ogre::String>::type uniqueTextureNames;
		// Add an entry for each render texture for all active compositors
		Ogre::Viewport* vp = mMain->getRenderWindow()->getViewport(0);
		Ogre::CompositorChain* chain = Ogre::CompositorManager::getSingleton().getCompositorChain(vp);
		Ogre::CompositorChain::InstanceIterator it = chain->getCompositors();
		while (it.hasMoreElements())
		{
			Ogre::CompositorInstance* inst = it.getNext();
			if (inst->getEnabled())
			{
				Ogre::CompositionTechnique::TextureDefinitionIterator texIt =
					inst->getTechnique()->getTextureDefinitionIterator();
				while (texIt.hasMoreElements())
				{
					Ogre::CompositionTechnique::TextureDefinition* texDef = texIt.getNext();

					// Get instance name of texture (NB only index 0 if MRTs for now)
					const Ogre::String& instName = inst->getTextureInstanceName(texDef->name, 0);
					// Create CEGUI texture from name of OGRE texture
					CEGUI::Texture* tex = mMain->getGuiRenderer()->createTexture(instName.c_str());
					// Create imageset
					// Note that if we use shared textures in compositor, the same texture name
					// will occur more than once, so we have to cater for this
					if (uniqueTextureNames.find(instName) == uniqueTextureNames.end())
					{
						CEGUI::Imageset* imgSet =
							CEGUI::ImagesetManager::getSingleton().createImageset(
								instName.c_str(), tex);
						mDebugRTTImageSets.push_back(imgSet);
						imgSet->defineImage((CEGUI::utf8*)"RttImage",
							CEGUI::Point(0.0f, 0.0f),
							CEGUI::Size(tex->getWidth(), tex->getHeight()),
							CEGUI::Point(0.0f,0.0f));


						CEGUI::ListboxTextItem *item = new CEGUI::ListboxTextItem(texDef->name.c_str(), 0, imgSet);
						item->setSelectionBrushImage("TaharezLook", "ListboxSelectionBrush");
						item->setSelectionColours(CEGUI::colour(0,0,1));
						mDebugRTTListbox->addItem(item);

						uniqueTextureNames.insert(instName);
					}

				}

			}

		}



	}
bool gkCompositorManager::setCompositorChain(gkCompositorOp op, const gkString& compositorName, gkViewport *viewport)
{
	GK_ASSERT(viewport && viewport->getViewport());

	bool found = false;

	Ogre::Viewport *vp = viewport->getViewport(); 

	int width = vp->getActualWidth(), height = vp->getActualHeight();

	Ogre::CompositorChain *chain = Ogre::CompositorManager::getSingleton().getCompositorChain(vp); assert(chain);
	for (size_t i = 0; i < chain->getNumCompositors(); i++) 
	{
		Ogre::CompositorInstance *ci = chain->getCompositor(i); assert(ci);
		bool match = (compositorName == ci->getCompositor()->getName());
		
		if (op == GK_COMPOSITOR_OP_REPLACE) 
			ci->setEnabled(match);
		else if 
			(op == GK_COMPOSITOR_OP_RESET) ci->setEnabled(false);
		else if 
			(match) ci->setEnabled(op == GK_COMPOSITOR_OP_ADD);
		
		if (!found && match) found = true;
	}

	if (op == GK_COMPOSITOR_OP_DEL || op == GK_COMPOSITOR_OP_RESET) 
		return true;

	if (!compositorName.empty() && !found) //create new compositor
	{ 
		if (compositorName == GK_COMPOSITOR_HEAT_VISION && !m_heatVisionInited) 
			m_heatVisionInited = gkOgreCompositorHelper::createHeatVisionCompositor();
		else if (compositorName == GK_COMPOSITOR_MOTION_BLUR && !m_motionBlurInited)
			m_motionBlurInited = gkOgreCompositorHelper::createMotionBlurCompositor();

		Ogre::CompositorManager& compMgr = Ogre::CompositorManager::getSingleton();

		Ogre::CompositorInstance* instance = compMgr.addCompositor(vp, compositorName, 0);
		if (instance) 
		{
			if (compositorName == GK_COMPOSITOR_HALFTONE && !m_halftonInited) 
				m_halftonInited = gkOgreCompositorHelper::createHalftoneTexture();
			else if (compositorName == GK_COMPOSITOR_DITHER && !m_ditherInited) 
				m_ditherInited = gkOgreCompositorHelper::createDitherTexture(width, height);			

			instance->setEnabled(true);

			gkPrintf("[COMP] add new compositor: %s", compositorName.c_str());

			return true;
		} 
		else 
		{
			gkPrintf("[COMP] %s - FAILED. check compositor name.", compositorName.c_str());
			return false;
		}
	}

	return false;
}