#include "OgreSceneCameraDepthRenderingRun.h" #include "OgreTechniqueGroup.h" OgreSceneCameraDepthRenderingRun::OgreSceneCameraDepthRenderingRun(OgreSharedRuns* sharedRuns, String name, Viewport* playerView ) :SceneCameraDepthRenderingRun() , OgreRenderingRun(1, 1) , RenderingRun(1, 1) { this->sharedRuns = sharedRuns; this->name = name; this->playerView = playerView; createDepthMap(); } void OgreSceneCameraDepthRenderingRun::createDepthMap() { int width = playerView->getActualWidth(); int height = playerView->getActualHeight(); TexturePtr texPtr = Ogre::TextureManager::getSingleton().createManual(name, "default", TEX_TYPE_2D, width, height, 0, 0, PF_FLOAT16_RGBA, TU_RENDERTARGET); depthTexture = texPtr.getPointer(); playerCamera = playerView->getCamera(); //add viewport to rendertarget HardwarePixelBuffer* hpb = (depthTexture->getBuffer()).getPointer(); RenderTarget* rt = hpb->getRenderTarget(); Viewport* v = rt->addViewport(playerCamera); v->setOverlaysEnabled(false); v->setSkiesEnabled(false); rt->setAutoUpdated(false); } bool OgreSceneCameraDepthRenderingRun::renderableQueued (Renderable *rend, uint8 groupID, ushort priority, Technique **ppTech) { if((*ppTech)->isTransparent()) return false; String materialToSet = String("GTP/Basic/CameraDepth"); OgreTechniqueGroup* TG = (OgreTechniqueGroup*) rend->getRenderTechniqueGroup(); if(TG) { String triggeredMaterial = TG->getMaterialNameForTrigger("ILLUM_TRIGGER_CAMERADEPTH"); if(triggeredMaterial != "")//a trigger is associated materialToSet = triggeredMaterial; } Technique* techn = ((Material*)MaterialManager::getSingleton().getByName( materialToSet ).getPointer())->getTechnique(0); *ppTech = techn; return true; } void OgreSceneCameraDepthRenderingRun::updateFrame(unsigned long frameNum) { //setMaterialForVisibles(String("GTP/Basic/CameraDepth"), playerCamera, false, true, "ILLUM_TRIGGER_CAMERADEPTH"); RenderQueue* rq = Root::getSingleton()._getCurrentSceneManager()->getRenderQueue(); rq->setRenderableListener(this); RenderTarget* rt = depthTexture->getBuffer().getPointer()->getRenderTarget(); float farPlane = rt->getViewport(0)->getCamera()->getFarClipDistance(); //ColourValue backColor(1,1,1,1); ColourValue backColor(0,0,0,0); //ColourValue backColor(farPlane,farPlane,farPlane,1); rt->getViewport(0)->setBackgroundColour(backColor); sharedRuns->getRoot()->hide(); rt->update(); //rt->writeContentsToFile("cameraDepth.bmp"); //restoreMaterials(); sharedRuns->getRoot()->restoreVisibility(); rq->setRenderableListener(0); } void OgreSceneCameraDepthRenderingRun::freeAllResources() { this->depthTexture = 0; TextureManager::getSingleton().remove(name); }