1 | #include "OgreSceneCameraDepthRenderingRun.h"
|
---|
2 | #include "OgreTechniqueGroup.h"
|
---|
3 |
|
---|
4 |
|
---|
5 | OgreSceneCameraDepthRenderingRun::OgreSceneCameraDepthRenderingRun(OgreSharedRuns* sharedRuns,
|
---|
6 | String name,
|
---|
7 | Viewport* playerView
|
---|
8 | )
|
---|
9 | :SceneCameraDepthRenderingRun()
|
---|
10 | , OgreRenderingRun(1, 1)
|
---|
11 | , RenderingRun(1, 1)
|
---|
12 | {
|
---|
13 | this->sharedRuns = sharedRuns;
|
---|
14 | this->name = name;
|
---|
15 | this->playerView = playerView;
|
---|
16 |
|
---|
17 | createDepthMap();
|
---|
18 | }
|
---|
19 |
|
---|
20 | void OgreSceneCameraDepthRenderingRun::createDepthMap()
|
---|
21 | {
|
---|
22 | int width = playerView->getActualWidth();
|
---|
23 | int height = playerView->getActualHeight();
|
---|
24 | TexturePtr texPtr = Ogre::TextureManager::getSingleton().createManual(name,
|
---|
25 | "default",
|
---|
26 | TEX_TYPE_2D,
|
---|
27 | width,
|
---|
28 | height,
|
---|
29 | 0,
|
---|
30 | 0,
|
---|
31 | PF_FLOAT16_RGBA,
|
---|
32 | TU_RENDERTARGET);
|
---|
33 | depthTexture = texPtr.getPointer();
|
---|
34 | playerCamera = playerView->getCamera();
|
---|
35 | //add viewport to rendertarget
|
---|
36 | HardwarePixelBuffer* hpb = (depthTexture->getBuffer()).getPointer();
|
---|
37 | RenderTarget* rt = hpb->getRenderTarget();
|
---|
38 | Viewport* v = rt->addViewport(playerCamera);
|
---|
39 | v->setOverlaysEnabled(false);
|
---|
40 | v->setSkiesEnabled(false);
|
---|
41 | rt->setAutoUpdated(false);
|
---|
42 | }
|
---|
43 |
|
---|
44 | bool OgreSceneCameraDepthRenderingRun::renderableQueued (Renderable *rend, uint8 groupID, ushort priority, Technique **ppTech)
|
---|
45 | {
|
---|
46 | if((*ppTech)->isTransparent())
|
---|
47 | return false;
|
---|
48 |
|
---|
49 | String materialToSet = String("GTP/Basic/CameraDepth");
|
---|
50 | OgreTechniqueGroup* TG = (OgreTechniqueGroup*) rend->getRenderTechniqueGroup();
|
---|
51 | if(TG)
|
---|
52 | {
|
---|
53 | String triggeredMaterial = TG->getMaterialNameForTrigger("ILLUM_TRIGGER_CAMERADEPTH");
|
---|
54 | if(triggeredMaterial != "")//a trigger is associated
|
---|
55 | materialToSet = triggeredMaterial;
|
---|
56 | }
|
---|
57 |
|
---|
58 | Technique* techn = ((Material*)MaterialManager::getSingleton().getByName( materialToSet ).getPointer())->getTechnique(0);
|
---|
59 | *ppTech = techn;
|
---|
60 | return true;
|
---|
61 | }
|
---|
62 |
|
---|
63 | void OgreSceneCameraDepthRenderingRun::updateFrame(unsigned long frameNum)
|
---|
64 | {
|
---|
65 |
|
---|
66 | //setMaterialForVisibles(String("GTP/Basic/CameraDepth"), playerCamera, false, true, "ILLUM_TRIGGER_CAMERADEPTH");
|
---|
67 | RenderQueue* rq = Root::getSingleton()._getCurrentSceneManager()->getRenderQueue();
|
---|
68 | rq->setRenderableListener(this);
|
---|
69 |
|
---|
70 | RenderTarget* rt = depthTexture->getBuffer().getPointer()->getRenderTarget();
|
---|
71 |
|
---|
72 | float farPlane = rt->getViewport(0)->getCamera()->getFarClipDistance();
|
---|
73 | //ColourValue backColor(1,1,1,1);
|
---|
74 | ColourValue backColor(0,0,0,0);
|
---|
75 | //ColourValue backColor(farPlane,farPlane,farPlane,1);
|
---|
76 | rt->getViewport(0)->setBackgroundColour(backColor);
|
---|
77 |
|
---|
78 |
|
---|
79 | sharedRuns->getRoot()->hide();
|
---|
80 |
|
---|
81 | rt->update();
|
---|
82 |
|
---|
83 | //rt->writeContentsToFile("cameraDepth.bmp");
|
---|
84 |
|
---|
85 | //restoreMaterials();
|
---|
86 |
|
---|
87 | sharedRuns->getRoot()->restoreVisibility();
|
---|
88 | rq->setRenderableListener(0);
|
---|
89 | }
|
---|
90 |
|
---|
91 | void OgreSceneCameraDepthRenderingRun::freeAllResources()
|
---|
92 | {
|
---|
93 | this->depthTexture = 0;
|
---|
94 | TextureManager::getSingleton().remove(name);
|
---|
95 | } |
---|