[124] | 1 | #include "Ogre.h"
|
---|
| 2 | #include "OgreEffectWrapper.h"
|
---|
| 3 | #include "ManagedOgreRenderTexturePass.h"
|
---|
| 4 | #include "FinalRenderingRun.h"
|
---|
| 5 | #include "illuminationmanager.h"
|
---|
| 6 |
|
---|
| 7 | void IlluminationManager::render(RenderTarget* rt, CubeMapFaces cf)
|
---|
| 8 | {
|
---|
| 9 | static std::vector<bool> entityVisibilityList;
|
---|
| 10 | static std::vector<bool> billboardVisibilityList;
|
---|
| 11 |
|
---|
| 12 | RenderSystem* renderSystem = Root::getSingleton().getRenderSystem();
|
---|
| 13 | SceneManager* sceneManager = Root::getSingleton().getSceneManager(ST_GENERIC);
|
---|
| 14 |
|
---|
| 15 | const ColourValue& backgroundColour = rt->getViewport(0)->getBackgroundColour();
|
---|
| 16 |
|
---|
| 17 | //save visibility (entities)
|
---|
| 18 | //set all invisible (entities)
|
---|
| 19 | {
|
---|
| 20 | SceneManager::EntityIterator ei = sceneManager->getEntityIterator();
|
---|
| 21 | while(ei.hasMoreElements())
|
---|
| 22 | {
|
---|
| 23 | Entity* entity = ei.getNext();
|
---|
| 24 | entityVisibilityList.push_back(entity->isVisible());
|
---|
| 25 | entity->setVisible(false);
|
---|
| 26 | }
|
---|
| 27 | }
|
---|
| 28 | //save visibility (billboardsets)
|
---|
| 29 | //set all invisible (billboardsets)
|
---|
| 30 | {
|
---|
| 31 | SceneManager::BillboardSetIterator bi = sceneManager->getBillboardSetIterator();
|
---|
| 32 | while(bi.hasMoreElements())
|
---|
| 33 | {
|
---|
| 34 | BillboardSet* billboard = bi.getNext();
|
---|
| 35 | billboardVisibilityList.push_back(billboard->isVisible());
|
---|
| 36 | billboard->setVisible(false);
|
---|
| 37 | }
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | //foreach entity prerender
|
---|
| 41 | if(performPreRenderStep)
|
---|
| 42 | {
|
---|
| 43 | SceneManager::EntityIterator ei = sceneManager->getEntityIterator();
|
---|
| 44 | while(ei.hasMoreElements())
|
---|
| 45 | {
|
---|
| 46 | UserDefinedObject* pudo = ei.getNext()->getUserObject();
|
---|
| 47 | OgreAssert(pudo && pudo->getTypeID() == MultipleUserDefinedObject::multipleUserDefinedObjectTypeId, "An entity does not contain a valid MultipleUserDefinedObject.");
|
---|
| 48 | pudo = ((MultipleUserDefinedObject*)pudo)->getUserObjectByType(EntityRenderingObject::entityRenderingObjectTypeId);
|
---|
| 49 | OgreAssert(pudo && pudo->getTypeID() == EntityRenderingObject::entityRenderingObjectTypeId, "An entity does not contain a valid EntityRenderingObject.");
|
---|
| 50 | EntityRenderingObject* eObject = (EntityRenderingObject*)pudo;
|
---|
| 51 | FinalRenderingRun* fRun = eObject->getFinalRenderingRun();
|
---|
| 52 |
|
---|
| 53 | fRun->setVisible(true);
|
---|
| 54 | fRun->preRender(rt, cf);
|
---|
| 55 | fRun->setVisible(false);
|
---|
| 56 | }
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | //foreach entity render
|
---|
| 60 | {
|
---|
| 61 | SceneManager::EntityIterator ei = sceneManager->getEntityIterator();
|
---|
| 62 | while(ei.hasMoreElements())
|
---|
| 63 | {
|
---|
| 64 | UserDefinedObject* pudo = ei.getNext()->getUserObject();
|
---|
| 65 | OgreAssert(pudo && pudo->getTypeID() == MultipleUserDefinedObject::multipleUserDefinedObjectTypeId, "An entity does contain a valid MultipleUserDefinedObject.");
|
---|
| 66 | pudo = ((MultipleUserDefinedObject*)pudo)->getUserObjectByType(EntityRenderingObject::entityRenderingObjectTypeId);
|
---|
| 67 | OgreAssert(pudo && pudo->getTypeID() == EntityRenderingObject::entityRenderingObjectTypeId, "An entity does contain a valid EntityRenderingObject.");
|
---|
| 68 | EntityRenderingObject* eObject = (EntityRenderingObject*)pudo;
|
---|
| 69 | FinalRenderingRun* fRun = eObject->getFinalRenderingRun();
|
---|
| 70 |
|
---|
| 71 | fRun->setVisible(true);
|
---|
| 72 | fRun->renderSingleEntity(rt, cf);
|
---|
| 73 | fRun->setVisible(false);
|
---|
| 74 | }
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | //foreach entity postrender
|
---|
| 78 | if(performPostRenderStep)
|
---|
| 79 | {
|
---|
| 80 | SceneManager::EntityIterator ei = sceneManager->getEntityIterator();
|
---|
| 81 | while(ei.hasMoreElements())
|
---|
| 82 | {
|
---|
| 83 | UserDefinedObject* pudo = ei.getNext()->getUserObject();
|
---|
| 84 | OgreAssert(pudo && pudo->getTypeID() == MultipleUserDefinedObject::multipleUserDefinedObjectTypeId, "An entity does contain a valid MultipleUserDefinedObject.");
|
---|
| 85 | pudo = ((MultipleUserDefinedObject*)pudo)->getUserObjectByType(EntityRenderingObject::entityRenderingObjectTypeId);
|
---|
| 86 | OgreAssert(pudo && pudo->getTypeID() == EntityRenderingObject::entityRenderingObjectTypeId, "An entity does contain a valid EntityRenderingObject.");
|
---|
| 87 | EntityRenderingObject* eObject = (EntityRenderingObject*)pudo;
|
---|
| 88 | FinalRenderingRun* fRun = eObject->getFinalRenderingRun();
|
---|
| 89 |
|
---|
| 90 | fRun->setVisible(true);
|
---|
| 91 | fRun->postRender(rt, cf);
|
---|
| 92 | fRun->setVisible(false);
|
---|
| 93 | }
|
---|
| 94 | }
|
---|
| 95 |
|
---|
| 96 | //foreach image based lighting directional light sample
|
---|
| 97 | if(performImageBasedLighting)
|
---|
| 98 | {
|
---|
| 99 | imageLightingSamplesRun.rewind();
|
---|
| 100 | while(imageLightingSamplesRun.renderNextDepthMaps())
|
---|
| 101 | {
|
---|
| 102 | //foreach entity postrender
|
---|
| 103 | {
|
---|
| 104 | SceneManager::EntityIterator ei = sceneManager->getEntityIterator();
|
---|
| 105 | while(ei.hasMoreElements())
|
---|
| 106 | {
|
---|
| 107 | UserDefinedObject* pudo = ei.getNext()->getUserObject();
|
---|
| 108 | OgreAssert(pudo && pudo->getTypeID() == MultipleUserDefinedObject::multipleUserDefinedObjectTypeId, "An entity does contain a valid MultipleUserDefinedObject.");
|
---|
| 109 | pudo = ((MultipleUserDefinedObject*)pudo)->getUserObjectByType(EntityRenderingObject::entityRenderingObjectTypeId);
|
---|
| 110 | OgreAssert(pudo && pudo->getTypeID() == EntityRenderingObject::entityRenderingObjectTypeId, "An entity does contain a valid EntityRenderingObject.");
|
---|
| 111 | EntityRenderingObject* eObject = (EntityRenderingObject*)pudo;
|
---|
| 112 | FinalRenderingRun* fRun = eObject->getFinalRenderingRun();
|
---|
| 113 |
|
---|
| 114 | fRun->setVisible(true);
|
---|
| 115 | fRun->postRender(rt, cf);
|
---|
| 116 | fRun->setVisible(false);
|
---|
| 117 | }
|
---|
| 118 | }
|
---|
| 119 | }
|
---|
| 120 | }
|
---|
| 121 |
|
---|
| 122 | //restore visibility (billboardsets)
|
---|
| 123 | {
|
---|
| 124 | unsigned int elementNumber = 0;
|
---|
| 125 | SceneManager::BillboardSetIterator bi = sceneManager->getBillboardSetIterator();
|
---|
| 126 | while(bi.hasMoreElements())
|
---|
| 127 | {
|
---|
| 128 | BillboardSet* billboard = bi.getNext();
|
---|
| 129 | billboard->setVisible(billboardVisibilityList.at(elementNumber++));
|
---|
| 130 | }
|
---|
| 131 | billboardVisibilityList.clear();
|
---|
| 132 | }
|
---|
| 133 |
|
---|
| 134 | //render billboardsets
|
---|
| 135 |
|
---|
| 136 |
|
---|
| 137 | //restore visibility (entities)
|
---|
| 138 | {
|
---|
| 139 | unsigned int elementNumber = 0;
|
---|
| 140 | SceneManager::EntityIterator ei = sceneManager->getEntityIterator();
|
---|
| 141 | while(ei.hasMoreElements())
|
---|
| 142 | {
|
---|
| 143 | Entity* entity = ei.getNext();
|
---|
| 144 | entity->setVisible(entityVisibilityList.at(elementNumber++));
|
---|
| 145 | }
|
---|
| 146 | entityVisibilityList.clear();
|
---|
| 147 | }
|
---|
| 148 | }
|
---|
| 149 |
|
---|
| 150 | void IlluminationManager::updateStaticLightData()
|
---|
| 151 | {
|
---|
| 152 | RenderSystem* renderSystem = Root::getSingleton().getRenderSystem();
|
---|
| 153 | SceneManager* sceneManager = Root::getSingleton().getSceneManager(ST_GENERIC);
|
---|
| 154 |
|
---|
| 155 |
|
---|
| 156 | SceneManager::LightIterator li = sceneManager->getLightIterator();
|
---|
| 157 | bool pointLightUpdated[32];
|
---|
| 158 | bool spotLightUpdated[32];
|
---|
| 159 | bool directionalLightUpdated[32];
|
---|
| 160 | for(unsigned int i=0; i<32; i++)
|
---|
| 161 | {
|
---|
| 162 | pointLightUpdated[i] = spotLightUpdated[i] = directionalLightUpdated[i] = false;
|
---|
| 163 | }
|
---|
| 164 | while(li.hasMoreElements())
|
---|
| 165 | {
|
---|
| 166 | Light* light = li.getNext();
|
---|
| 167 | if(light->getType() == Light::LT_POINT && computePointLightShadows)
|
---|
| 168 | {
|
---|
| 169 | bool newLight = true;
|
---|
| 170 | for(unsigned int il=0; il < nPointLights; il++)
|
---|
| 171 | {
|
---|
| 172 | if(pointLights[il]->ogreLight == light)
|
---|
| 173 | {
|
---|
| 174 | pointLights[il]->update();
|
---|
| 175 | pointLightUpdated[il] = true;
|
---|
| 176 | newLight = false;
|
---|
| 177 | break;
|
---|
| 178 | }
|
---|
| 179 | }
|
---|
| 180 | if(newLight)
|
---|
| 181 | {
|
---|
| 182 | OgreAssert(nPointLights < 32, "More than 32 lights!");
|
---|
| 183 | if(nPointLights < nAllocatedPointLights)
|
---|
| 184 | {
|
---|
| 185 | pointLights[nPointLights]->ogreLight = light;
|
---|
| 186 | pointLights[nPointLights]->preProcRun.setLight(light);
|
---|
| 187 | nPointLights++;
|
---|
| 188 | }
|
---|
| 189 | else
|
---|
| 190 | {
|
---|
| 191 | pointLights[nPointLights] = new PointLightPreProcData();
|
---|
| 192 | pointLights[nPointLights]->ogreLight = light;
|
---|
| 193 | pointLights[nPointLights]->preProcRun.setLight(light);
|
---|
| 194 | nPointLights++;
|
---|
| 195 | nAllocatedPointLights++;
|
---|
| 196 | }
|
---|
| 197 | }
|
---|
| 198 | }
|
---|
| 199 | else if(light->getType() == Light::LT_SPOTLIGHT && computeSpotLightShadows)
|
---|
| 200 | {
|
---|
| 201 | bool newLight = true;
|
---|
| 202 | for(unsigned int il=0; il < nSpotLights; il++)
|
---|
| 203 | {
|
---|
| 204 | if(spotLights[il]->ogreLight == light)
|
---|
| 205 | {
|
---|
| 206 | spotLights[il]->update();
|
---|
| 207 | spotLightUpdated[il] = true;
|
---|
| 208 | newLight = false;
|
---|
| 209 | break;
|
---|
| 210 | }
|
---|
| 211 | }
|
---|
| 212 | if(newLight)
|
---|
| 213 | {
|
---|
| 214 | OgreAssert(nSpotLights < 32, "More than 32 lights!");
|
---|
| 215 | if(nSpotLights < nAllocatedSpotLights)
|
---|
| 216 | {
|
---|
| 217 | spotLights[nSpotLights]->ogreLight = light;
|
---|
| 218 | spotLights[nSpotLights]->preProcRun.setLight(light);
|
---|
| 219 | nSpotLights++;
|
---|
| 220 | }
|
---|
| 221 | else
|
---|
| 222 | {
|
---|
| 223 | spotLights[nSpotLights] = new SpotLightPreProcData();
|
---|
| 224 | spotLights[nSpotLights]->ogreLight = light;
|
---|
| 225 | spotLights[nSpotLights]->preProcRun.setLight(light);
|
---|
| 226 | nSpotLights++;
|
---|
| 227 | nAllocatedSpotLights++;
|
---|
| 228 | }
|
---|
| 229 | }
|
---|
| 230 | }
|
---|
| 231 | else if(light->getType() == Light::LT_DIRECTIONAL && computeDirectionalLightShadows)
|
---|
| 232 | {
|
---|
| 233 | bool newLight = true;
|
---|
| 234 | for(unsigned int il=0; il < nDirectionalLights; il++)
|
---|
| 235 | {
|
---|
| 236 | if(directionalLights[il]->ogreLight == light)
|
---|
| 237 | {
|
---|
| 238 | directionalLights[il]->update();
|
---|
| 239 | directionalLightUpdated[il] = true;
|
---|
| 240 | newLight = false;
|
---|
| 241 | break;
|
---|
| 242 | }
|
---|
| 243 | }
|
---|
| 244 | if(newLight)
|
---|
| 245 | {
|
---|
| 246 | OgreAssert(nDirectionalLights < 32, "More than 32 lights!");
|
---|
| 247 | if(nDirectionalLights < nAllocatedDirectionalLights)
|
---|
| 248 | {
|
---|
| 249 | directionalLights[nDirectionalLights]->ogreLight = light;
|
---|
| 250 | directionalLights[nDirectionalLights]->preProcRun.setLight(light);
|
---|
| 251 | nDirectionalLights++;
|
---|
| 252 | }
|
---|
| 253 | else
|
---|
| 254 | {
|
---|
| 255 | directionalLights[nDirectionalLights] = new DirectionalLightPreProcData();
|
---|
| 256 | directionalLights[nDirectionalLights]->ogreLight = light;
|
---|
| 257 | directionalLights[nDirectionalLights]->preProcRun.setLight(light);
|
---|
| 258 | nDirectionalLights++;
|
---|
| 259 | nAllocatedDirectionalLights++;
|
---|
| 260 | }
|
---|
| 261 | }
|
---|
| 262 | }
|
---|
| 263 | }
|
---|
| 264 | //dump unused lights
|
---|
| 265 | }
|
---|
| 266 |
|
---|
| 267 | void IlluminationManager::update(unsigned long frameNumber, RenderTarget* rt, CubeMapFaces cf)
|
---|
| 268 | {
|
---|
| 269 | RenderSystem* renderSystem = Root::getSingleton().getRenderSystem();
|
---|
| 270 | SceneManager* sceneManager = Root::getSingleton().getSceneManager(ST_GENERIC);
|
---|
| 271 |
|
---|
| 272 |
|
---|
| 273 | //update static light data
|
---|
| 274 |
|
---|
| 275 |
|
---|
| 276 | //foreach entity render VRM
|
---|
| 277 | {
|
---|
| 278 | SceneManager::EntityIterator ei = sceneManager->getEntityIterator();
|
---|
| 279 | while(ei.hasMoreElements())
|
---|
| 280 | {
|
---|
| 281 | UserDefinedObject* pudo = ei.getNext()->getUserObject();
|
---|
| 282 | OgreAssert(pudo && pudo->getTypeID() == MultipleUserDefinedObject::multipleUserDefinedObjectTypeId, "An entity does contain a valid MultipleUserDefinedObject.");
|
---|
| 283 | pudo = ((MultipleUserDefinedObject*)pudo)->getUserObjectByType(EntityRenderingObject::entityRenderingObjectTypeId);
|
---|
| 284 | OgreAssert(pudo && pudo->getTypeID() == EntityRenderingObject::entityRenderingObjectTypeId, "An entity does contain a valid EntityRenderingObject.");
|
---|
| 285 | EntityRenderingObject* eObject = (EntityRenderingObject*)pudo;
|
---|
| 286 | FinalRenderingRun* fRun = eObject->getFinalRenderingRun();
|
---|
| 287 |
|
---|
| 288 | eObject->updateVRM(frameNumber);
|
---|
| 289 | }
|
---|
| 290 | }
|
---|
| 291 | //foreach entity render caustic map
|
---|
| 292 | {
|
---|
| 293 | SceneManager::EntityIterator ei = sceneManager->getEntityIterator();
|
---|
| 294 | while(ei.hasMoreElements())
|
---|
| 295 | {
|
---|
| 296 | UserDefinedObject* pudo = ei.getNext()->getUserObject();
|
---|
| 297 | OgreAssert(pudo && pudo->getTypeID() == MultipleUserDefinedObject::multipleUserDefinedObjectTypeId, "An entity does contain a valid MultipleUserDefinedObject.");
|
---|
| 298 | pudo = ((MultipleUserDefinedObject*)pudo)->getUserObjectByType(EntityRenderingObject::entityRenderingObjectTypeId);
|
---|
| 299 | OgreAssert(pudo && pudo->getTypeID() == EntityRenderingObject::entityRenderingObjectTypeId, "An entity does contain a valid EntityRenderingObject.");
|
---|
| 300 | EntityRenderingObject* eObject = (EntityRenderingObject*)pudo;
|
---|
| 301 | FinalRenderingRun* fRun = eObject->getFinalRenderingRun();
|
---|
| 302 |
|
---|
| 303 | eObject->updateCausticMap(frameNumber);
|
---|
| 304 | }
|
---|
| 305 | }
|
---|
| 306 |
|
---|
| 307 | //foreach entity render PRM
|
---|
| 308 | {
|
---|
| 309 | SceneManager::EntityIterator ei = sceneManager->getEntityIterator();
|
---|
| 310 | while(ei.hasMoreElements())
|
---|
| 311 | {
|
---|
| 312 | UserDefinedObject* pudo = ei.getNext()->getUserObject();
|
---|
| 313 | OgreAssert(pudo && pudo->getTypeID() == MultipleUserDefinedObject::multipleUserDefinedObjectTypeId, "An entity does contain a valid MultipleUserDefinedObject.");
|
---|
| 314 | pudo = ((MultipleUserDefinedObject*)pudo)->getUserObjectByType(EntityRenderingObject::entityRenderingObjectTypeId);
|
---|
| 315 | OgreAssert(pudo && pudo->getTypeID() == EntityRenderingObject::entityRenderingObjectTypeId, "An entity does contain a valid EntityRenderingObject.");
|
---|
| 316 | EntityRenderingObject* eObject = (EntityRenderingObject*)pudo;
|
---|
| 317 | FinalRenderingRun* fRun = eObject->getFinalRenderingRun();
|
---|
| 318 |
|
---|
| 319 | eObject->updatePRM(frameNumber);
|
---|
| 320 | }
|
---|
| 321 | }
|
---|
| 322 |
|
---|
| 323 | //foreach entity render environment map cubes
|
---|
| 324 | {
|
---|
| 325 | SceneManager::EntityIterator ei = sceneManager->getEntityIterator();
|
---|
| 326 | while(ei.hasMoreElements())
|
---|
| 327 | {
|
---|
| 328 | UserDefinedObject* pudo = ei.getNext()->getUserObject();
|
---|
| 329 | OgreAssert(pudo && pudo->getTypeID() == MultipleUserDefinedObject::multipleUserDefinedObjectTypeId, "An entity does contain a valid MultipleUserDefinedObject.");
|
---|
| 330 | pudo = ((MultipleUserDefinedObject*)pudo)->getUserObjectByType(EntityRenderingObject::entityRenderingObjectTypeId);
|
---|
| 331 | OgreAssert(pudo && pudo->getTypeID() == EntityRenderingObject::entityRenderingObjectTypeId, "An entity does contain a valid EntityRenderingObject.");
|
---|
| 332 | EntityRenderingObject* eObject = (EntityRenderingObject*)pudo;
|
---|
| 333 | FinalRenderingRun* fRun = eObject->getFinalRenderingRun();
|
---|
| 334 |
|
---|
| 335 | eObject->updateEnvironmentCubes(frameNumber);
|
---|
| 336 | }
|
---|
| 337 | }
|
---|
| 338 |
|
---|
| 339 | renderSystem->clearFrameBuffer(0, rt->getViewport(0)->getBackgroundColour());
|
---|
| 340 | render(rt, cf);
|
---|
| 341 | } |
---|