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