1 | #include "OgreFireRenderTechnique.h"
|
---|
2 | #include "OgreTechniqueGroup.h"
|
---|
3 | #include "OgreIlluminationManager.h"
|
---|
4 | #include "OgreSceneCameraDepthRenderingRun.h"
|
---|
5 |
|
---|
6 | int FireRenderTarget::targetsize = 2;
|
---|
7 |
|
---|
8 | RenderTarget* colortexture;
|
---|
9 | RenderTarget* heattexture;
|
---|
10 |
|
---|
11 | FireRenderTarget::FireRenderTarget()
|
---|
12 | {
|
---|
13 | int width = OgreIlluminationManager::getSingleton().getMainViewport()->getActualWidth()
|
---|
14 | / targetsize;
|
---|
15 | int height = OgreIlluminationManager::getSingleton().getMainViewport()->getActualHeight()
|
---|
16 | / targetsize;
|
---|
17 |
|
---|
18 | renderTarget = Root::getSingleton().getRenderSystem()->
|
---|
19 | createMultiRenderTarget("ILLUM_FIRE_TEXTURE");
|
---|
20 | MultiRenderTarget* mrt = (MultiRenderTarget*) renderTarget;
|
---|
21 | {
|
---|
22 | TexturePtr texPtr = Ogre::TextureManager::getSingleton().createManual("ILLUM_FIRE_COLOR_TEXTURE",
|
---|
23 | "default",
|
---|
24 | TEX_TYPE_2D,
|
---|
25 | width,
|
---|
26 | height,
|
---|
27 | 0,
|
---|
28 | 0,
|
---|
29 | PF_FLOAT16_RGBA,
|
---|
30 | TU_RENDERTARGET);
|
---|
31 | Texture* texture = texPtr.getPointer();
|
---|
32 | //add viewport to rendertarget
|
---|
33 | HardwarePixelBuffer* hpb = (texture->getBuffer()).getPointer();
|
---|
34 | RenderTarget* rt = hpb->getRenderTarget();
|
---|
35 |
|
---|
36 | colortexture = rt;
|
---|
37 | RenderTexture* colorTex = (RenderTexture*) rt;
|
---|
38 | mrt->bindSurface(0, colorTex);
|
---|
39 | }
|
---|
40 |
|
---|
41 | {
|
---|
42 | TexturePtr texPtr = Ogre::TextureManager::getSingleton().createManual("ILLUM_FIRE_HEAT_TEXTURE",
|
---|
43 | "default",
|
---|
44 | TEX_TYPE_2D,
|
---|
45 | width,
|
---|
46 | height,
|
---|
47 | 0,
|
---|
48 | 0,
|
---|
49 | PF_FLOAT16_RGBA,
|
---|
50 | TU_RENDERTARGET);
|
---|
51 | Texture* texture = texPtr.getPointer();
|
---|
52 | //add viewport to rendertarget
|
---|
53 | HardwarePixelBuffer* hpb = (texture->getBuffer()).getPointer();
|
---|
54 | RenderTarget* rt = hpb->getRenderTarget();
|
---|
55 |
|
---|
56 | heattexture = rt;
|
---|
57 | RenderTexture* heatTex = (RenderTexture*) rt;
|
---|
58 | mrt->bindSurface(1, heatTex);
|
---|
59 |
|
---|
60 |
|
---|
61 | }
|
---|
62 | Viewport* v = mrt->addViewport(OgreIlluminationManager::getSingleton().getMainCamera());
|
---|
63 | v->setOverlaysEnabled(false);
|
---|
64 | mrt->setAutoUpdated(false);
|
---|
65 |
|
---|
66 | SceneManager* sm = Root::getSingleton()._getCurrentSceneManager();
|
---|
67 | sm->getRenderQueue()->clear();
|
---|
68 | sm->setFindVisibleObjects(false);
|
---|
69 | mrt->update();
|
---|
70 | sm->setFindVisibleObjects(true);
|
---|
71 | }
|
---|
72 |
|
---|
73 | FireRenderTarget::~FireRenderTarget()
|
---|
74 | {
|
---|
75 | TextureManager::getSingleton().remove("ILLUM_FIRE_COLOR_TEXTURE");
|
---|
76 | TextureManager::getSingleton().remove("ILLUM_FIRE_HEAT_TEXTURE");
|
---|
77 | }
|
---|
78 |
|
---|
79 | OgreFireRenderTechnique::OgreFireRenderTechnique( unsigned char depthTexID,
|
---|
80 | Pass* pass,
|
---|
81 | OgreRenderable* parentRenderable,
|
---|
82 | OgreTechniqueGroup* parentTechniqueGroup)
|
---|
83 | :RenderTechnique( parentRenderable, parentTechniqueGroup),
|
---|
84 | OgreRenderTechnique(pass, parentRenderable, parentTechniqueGroup)
|
---|
85 | {
|
---|
86 | this->depthTexID = depthTexID;
|
---|
87 | OgreIlluminationManager::getSingleton().createGlobalRun(ILLUMRUN_SCENE_CAMERA_DEPTH);
|
---|
88 |
|
---|
89 |
|
---|
90 | OgreSceneCameraDepthRenderingRun* run = (OgreSceneCameraDepthRenderingRun*)
|
---|
91 | OgreIlluminationManager::getSingleton().getGlobalRun(ILLUMRUN_SCENE_CAMERA_DEPTH)->asOgreRenderingRun();
|
---|
92 |
|
---|
93 | pass->getTextureUnitState(depthTexID)->setTextureName(run->getDepthTextureName());
|
---|
94 |
|
---|
95 | if(OgreIlluminationManager::getSingleton().
|
---|
96 | getGlobalTarget(ILLUM_GLOBAL_TARGET_FIREPARTICLES) == 0)
|
---|
97 | {
|
---|
98 | FireRenderTarget* frt = new FireRenderTarget();
|
---|
99 | OgreIlluminationManager::getSingleton().
|
---|
100 | addGlobalTarget(ILLUM_GLOBAL_TARGET_FIREPARTICLES, frt);
|
---|
101 | }
|
---|
102 |
|
---|
103 | FireRenderTarget* frt = (FireRenderTarget*) OgreIlluminationManager::getSingleton().
|
---|
104 | getGlobalTarget(ILLUM_GLOBAL_TARGET_FIREPARTICLES);
|
---|
105 | frt->renderTarget->addListener(this);
|
---|
106 | OgreIlluminationManager::getSingleton().addUpdateListener(this);
|
---|
107 | Root::getSingleton().addFrameListener(this);
|
---|
108 | }
|
---|
109 |
|
---|
110 | void OgreFireRenderTechnique::preRenderTargetUpdate (const RenderTargetEvent &evt)
|
---|
111 | {
|
---|
112 | parentOgreRenderable->setVisible(lastVisibility);
|
---|
113 | }
|
---|
114 | void OgreFireRenderTechnique::postRenderTargetUpdate (const RenderTargetEvent &evt)
|
---|
115 | {
|
---|
116 | parentOgreRenderable->setVisible(false);
|
---|
117 | }
|
---|
118 |
|
---|
119 | bool OgreFireRenderTechnique::frameEnded (const FrameEvent &evt)
|
---|
120 | {
|
---|
121 | parentOgreRenderable->setVisible(lastVisibility);
|
---|
122 |
|
---|
123 | return true;
|
---|
124 | }
|
---|
125 | void OgreFireRenderTechnique::preAllUpdates()
|
---|
126 | {
|
---|
127 | lastVisibility = parentOgreRenderable->isVisible();
|
---|
128 | parentOgreRenderable->setVisible(false);
|
---|
129 | }
|
---|
130 |
|
---|
131 |
|
---|
132 | OgreFireRenderTechnique::~OgreFireRenderTechnique()
|
---|
133 | {
|
---|
134 |
|
---|
135 | }
|
---|
136 |
|
---|
137 | void OgreFireRenderTechnique::update(unsigned long frameNum)
|
---|
138 | {
|
---|
139 | OgreIlluminationManager::getSingleton().updateGlobalRun(ILLUMRUN_SCENE_CAMERA_DEPTH, frameNum);
|
---|
140 |
|
---|
141 | ///render the fire to a target
|
---|
142 | FireRenderTarget* frt = (FireRenderTarget*) OgreIlluminationManager::getSingleton().
|
---|
143 | getGlobalTarget(ILLUM_GLOBAL_TARGET_FIREPARTICLES);
|
---|
144 |
|
---|
145 | SceneManager* sm = Root::getSingleton()._getCurrentSceneManager();
|
---|
146 | RenderQueue* rq = sm->getRenderQueue();
|
---|
147 | rq->clear();
|
---|
148 | rq->addRenderable(parentOgreRenderable->getRenderable());
|
---|
149 | sm->setFindVisibleObjects(false);
|
---|
150 |
|
---|
151 | frt->renderTarget->update();
|
---|
152 |
|
---|
153 | sm->setFindVisibleObjects(true);
|
---|
154 |
|
---|
155 | //colortexture->writeContentsToFile("firecolor.tga");
|
---|
156 | //heattexture->writeContentsToFile("fireheat.tga");
|
---|
157 |
|
---|
158 | }
|
---|
159 |
|
---|
160 | namespace FireParsers
|
---|
161 | {
|
---|
162 | ///Technique parsers
|
---|
163 | void parseDepthTexID(String& params, RenderTechniqueFactory* factory)
|
---|
164 | {
|
---|
165 | OgreFireRenderTechniqueFactory* f = (OgreFireRenderTechniqueFactory*) factory;
|
---|
166 | f->depthTexID = StringConverter::parseUnsignedInt(params);
|
---|
167 | }
|
---|
168 | }
|
---|
169 |
|
---|
170 | OgreFireRenderTechniqueFactory::OgreFireRenderTechniqueFactory()
|
---|
171 | {
|
---|
172 | typeName = "Fire";
|
---|
173 |
|
---|
174 | using namespace FireParsers;
|
---|
175 |
|
---|
176 | //register parsers
|
---|
177 | this->attributeParsers.insert(AttribParserList::value_type("texture_unit_id", (ILLUM_ATTRIBUTE_PARSER) parseDepthTexID));
|
---|
178 | }
|
---|
179 |
|
---|
180 | OgreRenderTechnique* OgreFireRenderTechniqueFactory::createInstance(
|
---|
181 | IllumTechniqueParams* params,
|
---|
182 | Pass* pass,
|
---|
183 | OgreRenderable* parentRenderable,
|
---|
184 | OgreTechniqueGroup* parentTechniqueGroup)
|
---|
185 | {
|
---|
186 | //reset parameters
|
---|
187 | depthTexID = 1;
|
---|
188 |
|
---|
189 | parseParams(params);
|
---|
190 |
|
---|
191 | OgreFireRenderTechnique* result = new OgreFireRenderTechnique(
|
---|
192 | depthTexID,
|
---|
193 | pass,
|
---|
194 | parentRenderable,
|
---|
195 | parentTechniqueGroup);
|
---|
196 | return result;
|
---|
197 | }
|
---|
198 |
|
---|
199 |
|
---|
200 |
|
---|