Changeset 2375 for GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src
- Timestamp:
- 05/15/07 11:46:00 (18 years ago)
- Location:
- GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/OgreRenderingRun.cpp
r2366 r2375 13 13 String materialName; 14 14 String triggerName; 15 std::map<Renderable*, String>* visibleObjects; 15 std::map<Renderable*, String>* materialRestoreMap; 16 std::set<Renderable*>* visibleObjects; 16 17 public: 17 18 18 MaterialSetVisitor(String& materialName, std::map<Renderable*, String>* visibleObjects, String trigger = "") 19 MaterialSetVisitor(String& materialName, 20 std::map<Renderable*, String>* materialRestoreMap, 21 std::set<Renderable*>* visibleObjects, 22 String trigger = "") 19 23 { 20 24 this->materialName = materialName; 25 this->materialRestoreMap = materialRestoreMap; 21 26 this->visibleObjects = visibleObjects; 22 27 triggerName = trigger; … … 29 34 if( visibleObjects->count(rend) == 0) 30 35 { 31 (*visibleObjects)[rend] = rend->getMaterial().getPointer()->getName();32 String materialToSet = materialName; 33 if( triggerName != "")//we have a trigger here36 visibleObjects->insert(rend); 37 38 if( materialRestoreMap->count(rend) == 0) 34 39 { 35 OgreTechniqueGroup* tg = (OgreTechniqueGroup*)rend->getRenderTechniqueGroup(); 36 if(tg) 40 (*materialRestoreMap)[rend] = rend->getMaterial().getPointer()->getName(); 41 42 String materialToSet = materialName; 43 if(triggerName != "")//we have a trigger here 37 44 { 38 String triggeredMaterial = tg->getMaterialNameForTrigger(triggerName); 45 OgreTechniqueGroup* tg = (OgreTechniqueGroup*)rend->getRenderTechniqueGroup(); 46 if(tg) 47 { 48 String triggeredMaterial = tg->getMaterialNameForTrigger(triggerName); 49 if(triggeredMaterial != "")//a trigger is associated 50 materialToSet = triggeredMaterial; 51 } 52 } 53 rend->setMaterialName(materialToSet); 54 } 55 } 56 } 57 bool visit(const Pass* p){return true;} 58 void visit(const RenderablePass* rp) 59 { 60 Renderable* rend = rp->renderable; 61 if( visibleObjects->count(rend) == 0) 62 { 63 visibleObjects->insert(rend); 64 65 if( materialRestoreMap->count(rend) == 0) 66 { 67 (*materialRestoreMap)[rend] = rend->getMaterial().getPointer()->getName(); 68 String materialToSet = materialName; 69 if(triggerName != "")//we have a trigger here 70 { 71 String triggeredMaterial = 72 ((OgreTechniqueGroup*)rend->getRenderTechniqueGroup()) 73 ->getMaterialNameForTrigger(triggerName); 39 74 if(triggeredMaterial != "")//a trigger is associated 40 75 materialToSet = triggeredMaterial; 76 } 77 rend->setMaterialName(materialToSet); 78 } 79 } 80 } 81 82 }; 83 84 class RenderQueueFill 85 { 86 public: 87 88 inline void Fill( RenderQueue* rq, //the queue to add the renderables to 89 bool shadowcastersonly, 90 std::list<Renderable*>* renderables = 0, //if not null add only these materials 91 String materialName = "", //material to set, if "" leave original 92 std::map<Renderable*, String>* visibleObjects = 0, //map to restore materials later 93 String trigger = "") //trigger 94 { 95 if(renderables == 0) 96 { 97 SceneManager *sm = Root::getSingleton()._getCurrentSceneManager(); 98 SceneManager::MovableObjectIterator it = sm->getMovableObjectIterator("Entity"); 99 while(it.hasMoreElements()) 100 { 101 MovableObject* o = it.getNext(); 102 Entity* e = (Entity*) o; 103 if( (!shadowcastersonly || e->getCastShadows()) && e->isVisible()) 104 { 105 for (int i = 0; i < e->getNumSubEntities(); i++) 106 { 107 SubEntity* sube = e->getSubEntity(i); 108 109 if(materialName != "") 110 { 111 String materialToSet = materialName; 112 113 if(trigger != "") 114 { 115 String triggeredMaterial = 116 ((OgreTechniqueGroup*)sube->getRenderTechniqueGroup()) 117 ->getMaterialNameForTrigger(trigger); 118 if(triggeredMaterial != "")//a trigger is associated 119 materialToSet = triggeredMaterial; 120 } 121 122 if(visibleObjects->count(sube) == 0) 123 (*visibleObjects)[sube] = 124 sube->getMaterial().getPointer()->getName(); 125 sube->setMaterialName(materialToSet); 126 } 127 rq->addRenderable(sube); 128 } 41 129 } 42 } 43 rend->setMaterialName(materialToSet); 130 } 44 131 } 45 132 } 46 bool visit(const Pass* p){return true;}47 void visit(const RenderablePass* rp)48 {49 Renderable* rend = rp->renderable;50 51 if( visibleObjects->count(rend) == 0)52 {53 (*visibleObjects)[rend] = rend->getMaterial().getPointer()->getName();54 String materialToSet = materialName;55 if(triggerName != "")//we have a trigger here56 {57 String triggeredMaterial =58 ((OgreTechniqueGroup*)rend->getRenderTechniqueGroup())59 ->getMaterialNameForTrigger(triggerName);60 if(triggeredMaterial != "")//a trigger is associated61 materialToSet = triggeredMaterial;62 }63 rend->setMaterialName(materialToSet);64 }65 }66 67 133 }; 68 134 … … 154 220 RenderQueue::QueueGroupIterator queueIt = rq->_getQueueGroupIterator(); 155 221 156 while (queueIt.hasMoreElements()) 222 visibleObjects.clear(); 223 MaterialSetVisitor visitor(materialName, &materialRestoreMap, &visibleObjects, triggerName); 224 225 while (queueIt.hasMoreElements()) 157 226 { 158 227 RenderQueueGroup* pGroup = queueIt.getNext(); … … 165 234 const QueuedRenderableCollection& solids = pPriorityGrp->getSolidsBasic(); 166 235 const QueuedRenderableCollection& transparents = pPriorityGrp->getTransparents(); 167 MaterialSetVisitor visitor(materialName, &visibleObjects, triggerName);168 236 solids.acceptVisitor(&visitor, QueuedRenderableCollection::OM_PASS_GROUP); 169 237 if(!solidsonly) … … 175 243 rq->clear(); 176 244 177 std:: map<Renderable*, String>::iterator it = visibleObjects.begin();178 std:: map<Renderable*, String>::iterator itend = visibleObjects.end();245 std::set<Renderable*>::iterator it = visibleObjects.begin(); 246 std::set<Renderable*>::iterator itend = visibleObjects.end(); 179 247 180 248 while(it != itend) 181 249 { 182 rq->addRenderable((*it) .first);250 rq->addRenderable((*it)); 183 251 it++; 184 252 } … … 201 269 } 202 270 203 //sm->_findVisibleObjectsOC(cam, cam->getViewport(), false, false, shadowcastersonly);204 271 sm->_findVisibleObjects(cam, shadowcastersonly); 205 272 … … 207 274 } 208 275 276 void OgreRenderingRun::setMaterialForRenderables(String& materialName, bool shadowcastersonly, String triggerName) 277 { 278 SceneManager* sm = Ogre::Root::getSingleton()._getCurrentSceneManager(); 279 sm->setFindVisibleObjects(false); 280 281 RenderQueueFill RQF; 282 RenderQueue* rq = Root::getSingleton()._getCurrentSceneManager()->getRenderQueue(); 283 rq->clear(); 284 visibleObjects.clear(); 285 RQF.Fill(rq, shadowcastersonly, 0, materialName, &materialRestoreMap, triggerName); 286 } 287 209 288 void OgreRenderingRun::restoreMaterials() 210 289 { 211 290 SceneManager* sm = Ogre::Root::getSingleton()._getCurrentSceneManager(); 212 291 213 std::map<Renderable*, String>::iterator it = visibleObjects.begin();214 std::map<Renderable*, String>::iterator itend = visibleObjects.end();292 std::map<Renderable*, String>::iterator it = materialRestoreMap.begin(); 293 std::map<Renderable*, String>::iterator itend = materialRestoreMap.end(); 215 294 216 295 while(it != itend) … … 220 299 } 221 300 222 visibleObjects.clear();301 materialRestoreMap.clear(); 223 302 224 303 sm->setFindVisibleObjects(true); … … 246 325 sm->getRenderQueue()->clear(); 247 326 sm->getRenderQueue()->addRenderable(fullScreenQuadEntity->getSubEntity(0)); 327 bool lastFindVisible = sm->getFindVisibleObjects(); 248 328 sm->setFindVisibleObjects(false); 249 329 target->update(); 250 sm->setFindVisibleObjects( true);330 sm->setFindVisibleObjects(lastFindVisible); 251 331 } 252 332 … … 329 409 sm->getRenderQueue()->clear(); 330 410 sm->getRenderQueue()->addRenderable(fullscreenGrid->getSubEntity(0)); 411 bool lastFindVisible = sm->getFindVisibleObjects(); 331 412 sm->setFindVisibleObjects(false); 332 413 rt->update(); 333 sm->setFindVisibleObjects( true);414 sm->setFindVisibleObjects(lastFindVisible); 334 415 335 416 } … … 373 454 sm->getRenderQueue()->clear(); 374 455 sm->getRenderQueue()->addRenderable(pixelSprites); 456 bool lastFindVisible = sm->getFindVisibleObjects(); 375 457 sm->setFindVisibleObjects(false); 376 458 rt->update(); 377 sm->setFindVisibleObjects( true);378 379 } 380 459 sm->setFindVisibleObjects(lastFindVisible); 460 461 } 462 -
GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderingRuns/OgreDepthShadowMapRenderingRun.cpp
r2366 r2375 84 84 //updateDepthCubeFace(currentFace); 85 85 //currentFace = (currentFace+1)%6; 86 87 88 //Timer* t = Root::getSingleton().getTimer(); 89 //unsigned long start = t->getMicroseconds(); 90 //setMaterialForRenderables(materialName, true); 91 //unsigned long end = t->getMicroseconds(); 92 //double elapsed = (double) (end - start) / 1000.0; 93 //LogManager::getSingleton().logMessage(String("MaterialSetTime: ") + name + " : " + StringConverter::toString(Real(elapsed)) + " ms"); 94 //visibleObjects.clear(); 86 95 87 96 for(int i = 0; i < 6 ; i++) 88 97 updateDepthCubeFace(i); 98 99 //start = t->getMicroseconds(); 100 101 restoreMaterials(); 102 103 //end = t->getMicroseconds(); 104 //elapsed = (double) (end - start) / 1000000.0; 105 //LogManager::getSingleton().logMessage(String("MaterialRestoreTime: ") + name + " : " + StringConverter::toString(Real(elapsed)) + " ms"); 89 106 } 90 107 else … … 95 112 96 113 void OgreDepthShadowMapRenderingRun::updateDepthCubeFace(int facenum) 97 { 114 { 115 Vector3 lightpos = light->getDerivedPosition(); 98 116 String triggerName = "ILLUM_TRIGGER_SM_POINT"; 99 100 Vector3 lightpos = light->getDerivedPosition(); 101 117 102 118 RenderTarget* rt = depthMapTexture->getBuffer(facenum, 0).getPointer()->getRenderTarget(); 103 119 Camera* cam = rt->getViewport(0)->getCamera(); 104 cam->setPosition(lightpos);105 120 cam->setFarClipDistance(lightFarPlane); 106 121 cam->setPosition(lightpos); 122 123 107 124 setMaterialForVisibles(materialName, cam, true, false, triggerName); 125 108 126 rt->update(); 109 restoreMaterials(); 110 127 128 // restoreMaterials(); 129 111 130 //rt->writeContentsToFile("shadowmap_" + StringConverter::toString(facenum) + ".dds"); 112 131 … … 120 139 121 140 //rt->writeContentsToFile("shadowmap_blurred_" + StringConverter::toString(facenum) + ".dds"); 122 } 123 141 } 124 142 } 125 143
Note: See TracChangeset
for help on using the changeset viewer.