1 | #include "OgreSceneCameraDepthRenderingRun.h"
|
---|
2 |
|
---|
3 |
|
---|
4 | OgreSceneCameraDepthRenderingRun::OgreSceneCameraDepthRenderingRun(OgreSharedRuns* sharedRuns,
|
---|
5 | String name,
|
---|
6 | Viewport* playerView
|
---|
7 | )
|
---|
8 | :SceneCameraDepthRenderingRun()
|
---|
9 | , OgreRenderingRun(1, 1)
|
---|
10 | , RenderingRun(1, 1)
|
---|
11 | {
|
---|
12 | this->sharedRuns = sharedRuns;
|
---|
13 | this->name = name;
|
---|
14 | this->playerView = playerView;
|
---|
15 |
|
---|
16 | createDepthMap();
|
---|
17 | }
|
---|
18 |
|
---|
19 | void OgreSceneCameraDepthRenderingRun::createDepthMap()
|
---|
20 | {
|
---|
21 | int width = playerView->getActualWidth();
|
---|
22 | int height = playerView->getActualHeight();
|
---|
23 | TexturePtr texPtr = Ogre::TextureManager::getSingleton().createManual(name,
|
---|
24 | "default",
|
---|
25 | TEX_TYPE_2D,
|
---|
26 | width,
|
---|
27 | height,
|
---|
28 | 0,
|
---|
29 | 0,
|
---|
30 | PF_FLOAT16_RGBA,
|
---|
31 | TU_RENDERTARGET);
|
---|
32 | depthTexture = texPtr.getPointer();
|
---|
33 | playerCamera = playerView->getCamera();
|
---|
34 | //add viewport to rendertarget
|
---|
35 | HardwarePixelBuffer* hpb = (depthTexture->getBuffer()).getPointer();
|
---|
36 | RenderTarget* rt = hpb->getRenderTarget();
|
---|
37 | Viewport* v = rt->addViewport(playerCamera);
|
---|
38 | v->setOverlaysEnabled(false);
|
---|
39 | rt->setAutoUpdated(false);
|
---|
40 | }
|
---|
41 |
|
---|
42 | void OgreSceneCameraDepthRenderingRun::updateFrame(unsigned long frameNum)
|
---|
43 | {
|
---|
44 |
|
---|
45 | setMaterialForVisibles(String("GameTools/SceneCameraDepthShader"), playerCamera, false, true);
|
---|
46 |
|
---|
47 | RenderTarget* rt = depthTexture->getBuffer().getPointer()->getRenderTarget();
|
---|
48 |
|
---|
49 | float farPlane = rt->getViewport(0)->getCamera()->getFarClipDistance();
|
---|
50 | //ColourValue backColor(1,1,1,1);
|
---|
51 | ColourValue backColor(0,0,0,0);
|
---|
52 | //ColourValue backColor(farPlane,farPlane,farPlane,1);
|
---|
53 | rt->getViewport(0)->setBackgroundColour(backColor);
|
---|
54 |
|
---|
55 |
|
---|
56 | sharedRuns->getRoot()->hide();
|
---|
57 |
|
---|
58 | rt->update();
|
---|
59 |
|
---|
60 | //rt->writeContentsToFile("cameraDepth.bmp");
|
---|
61 |
|
---|
62 | restoreMaterials();
|
---|
63 |
|
---|
64 | sharedRuns->getRoot()->restoreVisibility();
|
---|
65 | }
|
---|
66 |
|
---|