Changeset 159 for trunk/VUT/Ogre/src
- Timestamp:
- 07/06/05 17:52:44 (19 years ago)
- Location:
- trunk/VUT/Ogre/src
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/Ogre/src/OgreItemBufferQueryManager.cpp
r158 r159 3 3 #include <OgreStringConverter.h> 4 4 #include <vector> 5 5 #include <OgreSubEntity.h> 6 6 7 7 namespace Ogre { 8 8 //----------------------------------------------------------------------- 9 ItemBufferQueryManager::ItemBufferQueryManager(PlatformHierarchyInterface *hierarchyInterface, Viewport *vp): 10 PlatformQueryManager(hierarchyInterface, vp) 9 ItemBufferQueryManager::ItemBufferQueryManager(PlatformHierarchyInterface *hierarchyInterface, Viewport *vp, 10 const bool renderPatches): 11 PlatformQueryManager(hierarchyInterface, vp), mRenderPatchesForItemBuffer(renderPatches) 11 12 { 12 13 } … … 21 22 InfoContainer<GtpVisibility::NodeInfo> *visibleNodes, 22 23 InfoContainer<GtpVisibility::MeshInfo> *visibleGeometry, 24 InfoContainer<GtpVisibility::PatchInfo> *visiblePatches, 23 25 bool relativeVisibility) 24 26 { 25 27 // initialise item buffer (if not already initialised) 26 InitItemBuffer(visibleNodes, visibleGeometry );28 InitItemBuffer(visibleNodes, visibleGeometry, visiblePatches); 27 29 28 30 // we need access to the scene manager and the rendersystem … … 32 34 SceneManager *sm = pfHierarchyInterface->GetSceneManager(); 33 35 34 // --- -Render scene with item buffer (i.e., objects with their id as color codes)36 // --- Render scene with item buffer (i.e., objects with their id as color codes) 35 37 36 38 // const_cast allowed because camera is not changed in renderScene … … 61 63 uchar *buf = mViewport->getTarget()->getBufferContents(dimx, dimy); 62 64 65 int n = mRenderPatchesForItemBuffer ? (int)visiblePatches->size() : (int)visibleGeometry->size(); 63 66 64 67 // loop through frame buffer & collect visible pixels … … 71 74 72 75 // if valid id <= add visibility (id values start at 1 73 if ((id > 0) && (id < (int)visibleGeometry->size()))76 if ((id > 0) && (id < n)) 74 77 { 75 ((*visibleGeometry)[id]).AddVisibility(1, 1); 78 if (mRenderPatchesForItemBuffer) 79 { 80 ((*visiblePatches)[id]).AddVisibility(1, 1); 81 } 82 else 83 { 84 ((*visibleGeometry)[id]).AddVisibility(1, 1); 85 } 76 86 } 77 87 } … … 93 103 } 94 104 //----------------------------------------------------------------------- 95 void ItemBufferQueryManager::InitItemBuffer(InfoContainer<GtpVisibility::NodeInfo> *visibleNodes, 96 InfoContainer<GtpVisibility::MeshInfo> *visibleGeometry) 105 void ItemBufferQueryManager::InitItemBuffer( 106 InfoContainer<GtpVisibility::NodeInfo> *visibleNodes, 107 InfoContainer<GtpVisibility::MeshInfo> *visibleGeometry, 108 InfoContainer<GtpVisibility::PatchInfo> *visiblePatches) 97 109 { 98 110 if (mWasInitialised) … … 109 121 visibleGeometry->clear(); 110 122 visibleNodes->clear(); 123 visiblePatches->clear(); 111 124 125 int id = 0; 126 127 /* We can either use patches or meshes. If patches are used, an unique id must 128 be given each patch. Otherwise the same id must be given to all patches belonging 129 to the same mesh. 130 */ 112 131 while (it.hasMoreElements()) 113 132 { 114 visibleGeometry->push_back(GtpVisibility::MeshInfo(it.getNext(), 0, 0)); 133 Entity *ent = it.getNext(); 134 135 for (int i = 0; i < (int)ent->getNumSubEntities(); ++i) 136 { 137 SubEntity *subEnt = ent->getSubEntity(i); 138 139 if (mRenderPatchesForItemBuffer) 140 { 141 ++ id; 142 visiblePatches->push_back(GtpVisibility::PatchInfo(subEnt, 0, 0)); 143 } 144 145 subEnt->setId(id); 146 } 147 148 if (!mRenderPatchesForItemBuffer) 149 { 150 visibleGeometry->push_back(GtpVisibility::MeshInfo(ent, 0, 0)); 151 ++ id; 152 } 115 153 } 116 154 } 117 155 156 /* 157 //----------------------------------------------------------------------- 158 Entity* VisibilityOctreeSceneManager::createEntity(const String& entityName, 159 const String& meshName) 160 { 161 Entity *ent = SceneManager::createEntity(entityName, meshName); 162 163 for (int i = 0; i < (int)ent->getNumSubEntities(); ++i) 164 { 165 ent->getSubEntity(i)->setId(mCurrentEntityId); 166 } 167 168 // increase counter of entity id values 169 ++ mCurrentEntityId; 170 171 return ent; 172 } 173 */ 118 174 } // namespace Ogre -
trunk/VUT/Ogre/src/OgreOcclusionQueriesQueryManager.cpp
r155 r159 21 21 InfoContainer<GtpVisibility::NodeInfo> *visibleNodes, 22 22 InfoContainer<GtpVisibility::MeshInfo> *visibleGeometry, 23 InfoContainer<GtpVisibility::PatchInfo> *visiblePatches, 23 24 bool relativeVisibility) 24 25 { … … 188 189 InfoContainer<GtpVisibility::NodeInfo> *visibleNodes, 189 190 InfoContainer<GtpVisibility::MeshInfo> *visibleGeometry, 191 InfoContainer<GtpVisibility::PatchInfo> *visiblePatches, 190 192 bool relativeVisibility) 191 193 { 192 PlatformQueryManager::ComputeFromPointVisibility(point, visibleNodes, visibleGeometry, relativeVisibility); 194 PlatformQueryManager::ComputeFromPointVisibility(point, visibleNodes, 195 visibleGeometry, visiblePatches, relativeVisibility); 193 196 194 197 // --- remove duplicates (duplicates occur if an object is on the edge of the viewport) -
trunk/VUT/Ogre/src/OgreOctreeHierarchyInterface.cpp
r158 r159 26 26 } 27 27 28 // if not all subtrees are empty 29 //if (octree->numNodes() > (int)octree->mNodes.size()) 28 //if (octree->numNodes() > (int)octree->mNodes.size()) // if not all subtrees are empty 30 29 if (!IsLeaf(node)) 31 30 { -
trunk/VUT/Ogre/src/OgrePlatformHierarchyInterface.cpp
r158 r159 200 200 } 201 201 //----------------------------------------------------------------------- 202 GtpVisibility::OcclusionQuery *PlatformHierarchyInterface::IssueOcclusionQuery(GtpVisibility::Mesh *mesh) 202 GtpVisibility::OcclusionQuery *PlatformHierarchyInterface::IssueOcclusionQuery( 203 GtpVisibility::Mesh *mesh) 203 204 { 204 205 // get next available test id -
trunk/VUT/Ogre/src/OgrePlatformQueryManager.cpp
r156 r159 23 23 InfoContainer<GtpVisibility::NodeInfo> *visibleNodes, 24 24 InfoContainer<GtpVisibility::MeshInfo> *visibleGeometry, 25 InfoContainer<GtpVisibility::PatchInfo> *visiblePatches, 25 26 bool relativeVisibility) 26 27 { 27 SceneManager *sm = dynamic_cast<PlatformHierarchyInterface *>(mHierarchyInterface)->GetSceneManager(); 28 SceneManager *sm = dynamic_cast<PlatformHierarchyInterface *> 29 (mHierarchyInterface)->GetSceneManager(); 30 31 // create a camera for the point query 28 32 Camera *cam = sm->createCamera("PointQueryCam"); 29 33 … … 61 65 } 62 66 63 ComputeCameraVisibility(*cam, visibleNodes, visibleGeometry, relativeVisibility);67 ComputeCameraVisibility(*cam, visibleNodes, visibleGeometry, visiblePatches, relativeVisibility); 64 68 65 mViewport->getTarget()->update(); for(int j=0; j<10000000; j++) printf("wait");69 //mViewport->getTarget()->update(); for(int j=0; j<10000000; j++) printf("wait"); 66 70 67 71 // permute directions -
trunk/VUT/Ogre/src/OgreSceneContentGenerator.cpp
r130 r159 65 65 { 66 66 char name[25]; 67 67 68 sprintf(name, "%s Entity%d", objName.c_str(), GetObjectCount()); 68 69 -
trunk/VUT/Ogre/src/OgreVisibilityOctreeSceneManager.cpp
r156 r159 7 7 #include <OgreLogManager.h> 8 8 #include <OgreStringConverter.h> 9 #include <OgreEntity.h> 10 #include <OgreSubEntity.h> 9 11 10 12 … … 16 18 : 17 19 mVisibilityManager(visManager), 18 mRenderDepthPass(false),19 20 mShowVisualization(false), 20 21 mRenderNodesForViz(false), 21 22 mRenderNodesContentForViz(false), 22 23 mVisualizeCulledNodes(false), 24 mLeavePassesInQueue(0), 23 25 mDelayRenderTransparents(true), 24 mUseDepthPass(true), 25 mSkipTransparents(false) 26 mUseDepthPass(false), 27 mRenderDepthPass(false), 28 mUseItemBuffer(false), 29 //mUseItemBuffer(true), 30 mRenderItemBuffer(false), 31 mCurrentEntityId(1), 32 mEnableDepthWrite(true), 33 mSkipTransparents(false), 34 mSavedShadowTechnique(SHADOWTYPE_NONE), 35 mRenderTransparentsForItemBuffer(false), 36 mExecuteVertexProgramForAllPasses(false) 26 37 { 27 38 mHierarchyInterface = new OctreeHierarchyInterface(this, mDestRenderSystem); … … 31 42 //mShowBoxes = true; 32 43 33 // TODO: find reasonable value for max depth44 // TODO: set maxdepth to reasonable value 34 45 mMaxDepth = 50; 35 46 } … … 65 76 } 66 77 //----------------------------------------------------------------------- 67 Pass *VisibilityOctreeSceneManager::setPass(Pass* pass) 68 { 69 // setting vertex program is not efficient 70 Pass *usedPass = ((mRenderDepthPass && pass->getDepthWriteEnabled() && 71 !pass->hasVertexProgram()) ? mDepthPass : pass); 72 73 /* 74 // set depth fill pass only if depth write enabled 75 Pass *usedPass = (mRenderDepthPass && pass->getDepthWriteEnabled() ? mDepthPass : pass); 76 77 if (mRenderDepthPass && pass->hasVertexProgram()) 78 void VisibilityOctreeSceneManager::InitItemBufferPass() 79 { 80 MaterialPtr itemBufferMat = MaterialManager::getSingleton(). 81 getByName("Visibility/ItemBufferPass"); 82 83 if (itemBufferMat.isNull()) 78 84 { 79 // set vertex program of current pass to depth pass 80 mDepthPass->setVertexProgram(pass->getVertexProgramName()); 81 82 if (mDepthPass->hasVertexProgram()) 83 { 84 const GpuProgramPtr& prg = mDepthPass->getVertexProgram(); 85 // Load this program if not done already 86 if (!prg->isLoaded()) 87 prg->load(); 88 // Copy params 89 mDepthPass->setVertexProgramParameters(pass->getVertexProgramParameters()); 90 } 91 else if (mDepthPass->hasVertexProgram()) 92 { 93 mDepthPass->setVertexProgram(""); 94 } 95 }*/ 96 97 SceneManager::setPass(usedPass); 98 99 return usedPass; 85 // Init 86 itemBufferMat = MaterialManager::getSingleton().create("Visibility/ItemBufferPass", 87 ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); 88 89 mItemBufferPass = itemBufferMat->getTechnique(0)->getPass(0); 90 mItemBufferPass->setColourWriteEnabled(true); 91 mItemBufferPass->setDepthWriteEnabled(true); 92 mItemBufferPass->setLightingEnabled(true); 93 //mItemBufferPass->setLightingEnabled(false); 94 } 95 else 96 { 97 mItemBufferPass = itemBufferMat->getTechnique(0)->getPass(0); 98 } 99 //mItemBufferPass->setAmbient(1, 1, 0); 100 100 } 101 101 //----------------------------------------------------------------------- … … 131 131 if (mRenderNodesForViz) 132 132 { 133 getRenderQueue()->addRenderable(*it); 133 if (((*it)->numAttachedObjects() > 0) && ((*it)->numChildren() == 0) 134 && (*it)->getAttachedObject(0)->getMovableType() == "Entity") 135 getRenderQueue()->addRenderable((*it)); 136 134 137 // addbounding boxes instead of node itself 135 138 //(*it)->_addBoundingBoxToQueue(getRenderQueue()); … … 141 144 } 142 145 } 143 146 } 147 //----------------------------------------------------------------------- 148 Pass *VisibilityOctreeSceneManager::setPass(Pass* pass) 149 { 150 // set depth fill pass if we currently do not make an aabb occlusion query 151 Pass *usedPass = (mRenderDepthPass && !mHierarchyInterface->IsBoundingBoxQuery() ? 152 mDepthPass : pass); 153 154 IlluminationRenderStage savedStage = mIlluminationStage; 155 156 // set illumination stage to NONE so no shadow material is used 157 // for depth pass or for occlusion query 158 if (mRenderDepthPass || mHierarchyInterface->IsBoundingBoxQuery()) 159 { 160 mIlluminationStage = IRS_NONE; 161 } 162 163 //-- set vertex program of current pass in order to set correct depth 164 if (mRenderDepthPass && mExecuteVertexProgramForAllPasses && pass->hasVertexProgram()) 165 { 166 // add vertex program of current pass to depth pass 167 mDepthPass->setVertexProgram(pass->getVertexProgramName()); 168 169 if (mDepthPass->hasVertexProgram()) 170 { 171 const GpuProgramPtr& prg = mDepthPass->getVertexProgram(); 172 // Load this program if not done already 173 if (!prg->isLoaded()) 174 prg->load(); 175 // Copy params 176 mDepthPass->setVertexProgramParameters(pass->getVertexProgramParameters()); 177 } 178 } 179 else if (mDepthPass->hasVertexProgram()) 180 { 181 mDepthPass->setVertexProgram(""); 182 } 183 184 // store depth write flag to reset later 185 bool IsDepthWrite = usedPass->getDepthWriteEnabled(); 186 187 // global option which enables / disables depth writes 188 if (!mEnableDepthWrite) 189 { 190 usedPass->setDepthWriteEnabled(false); 191 } 192 //else if (mIsItemBufferPass) {usedPass = mItemBufferPass;} 193 194 Pass *result = SceneManager::setPass(usedPass); 195 196 // reset depth write 197 if (!mEnableDepthWrite) 198 { 199 usedPass->setDepthWriteEnabled(IsDepthWrite); 200 } 201 202 // reset illumination stage 203 mIlluminationStage = savedStage; 204 205 return result; 144 206 } 145 207 //----------------------------------------------------------------------- … … 153 215 else 154 216 { 155 mVisible.clear(); 156 mBoxes.clear(); 157 158 // if there is no depth pass => 159 // we interleave identification and rendering of objects 160 // in _renderVisibibleObjects 161 217 // for hierarchical culling, we interleave identification 218 // and rendering of objects in _renderVisibibleObjects 219 220 // for the shadow pass we use only standard rendering 221 // because of low occlusion 222 if (mShadowTechnique == SHADOWTYPE_TEXTURE_MODULATIVE && 223 mIlluminationStage == IRS_RENDER_TO_TEXTURE) 224 { 225 OctreeSceneManager::_findVisibleObjects(cam, onlyShadowCasters); 226 } 162 227 // only shadow casters will be rendered in shadow texture pass 163 mHierarchyInterface->SetOnlyShadowCasters(onlyShadowCasters); 164 } 228 // mHierarchyInterface->SetOnlyShadowCasters(onlyShadowCasters); 229 } 230 231 232 // -- delete lists stored for visualization 233 mVisible.clear(); 234 mBoxes.clear(); 165 235 } 166 236 //----------------------------------------------------------------------- 167 237 void VisibilityOctreeSceneManager::_renderVisibleObjects() 168 238 { 169 // create material for depth pass 170 InitDepthPass(); 171 172 // visualization: apply standard rendering 173 if (mShowVisualization) 239 // save ambient light to reset later 240 ColourValue savedAmbient = mAmbientLight; 241 242 //-- apply standard rendering for some modes (e.g., visualization, shadow pass) 243 244 if (mShowVisualization || 245 (mShadowTechnique == SHADOWTYPE_TEXTURE_MODULATIVE && 246 mIlluminationStage == IRS_RENDER_TO_TEXTURE)) 247 { 248 IlluminationRenderStage savedStage = mIlluminationStage; 249 250 if (mShowVisualization) 251 { 252 // disable illumination stage to prevent rendering shadows 253 mIlluminationStage = IRS_NONE; 254 } 255 256 // standard rendering for shadow maps because of performance 257 OctreeSceneManager::_renderVisibleObjects(); 258 259 mIlluminationStage = savedStage; 260 } 261 else //-- the hierarchical culling algorithm 174 262 { 263 // don't render backgrounds for item buffer 264 if (mUseItemBuffer) 265 { 266 clearSpecialCaseRenderQueues(); 267 getRenderQueue()->clear(); 268 } 269 270 //-- hierarchical culling 271 // the objects of different layers (e.g., background, scene, 272 // overlay) must be identified and rendered one after another 273 274 //-- render all early skies 275 clearSpecialCaseRenderQueues(); 276 addSpecialCaseRenderQueue(RENDER_QUEUE_BACKGROUND); 277 addSpecialCaseRenderQueue(RENDER_QUEUE_SKIES_EARLY); 278 setSpecialCaseRenderQueueMode(SceneManager::SCRQM_INCLUDE); 279 175 280 OctreeSceneManager::_renderVisibleObjects(); 176 return;177 }178 179 //-- hierarchical culling180 // the objects of different layers (e.g., background, scene,181 // overlay) must be identified and rendered one after another182 183 bool leaveTransparentsInQueue = mDelayRenderTransparents && !mUseDepthPass;184 185 // -- initialise interface for rendering traversal of the hierarchy186 mHierarchyInterface->SetHierarchyRoot(mOctree);187 188 // possible two cameras (one for culling, one for rendering)189 mHierarchyInterface->InitTraversal(mCameraInProgress,190 mCullCamera ? getCamera("CullCamera") : NULL,191 leaveTransparentsInQueue);192 193 194 // reset culling manager stats195 mVisibilityManager->GetCullingManager()->InitFrame(mVisualizeCulledNodes);196 197 mSkipTransparents = false;198 199 //-- render background, in case there is one200 clearSpecialCaseRenderQueues();201 addSpecialCaseRenderQueue(RENDER_QUEUE_BACKGROUND);202 addSpecialCaseRenderQueue(RENDER_QUEUE_SKIES_EARLY);203 setSpecialCaseRenderQueueMode(SceneManager::SCRQM_INCLUDE);204 205 SceneManager::_renderVisibleObjects();206 281 207 282 208 283 #ifdef GTP_VISIBILITY_MODIFIED_OGRE 209 _deleteRenderedQueueGroups(); 284 // delete previously rendered content 285 _deleteRenderedQueueGroups(); 210 286 #endif 211 287 212 //-- render visible objects (i.e., all but overlay) 213 clearSpecialCaseRenderQueues(); 214 addSpecialCaseRenderQueue(RENDER_QUEUE_SKIES_LATE); 215 addSpecialCaseRenderQueue(RENDER_QUEUE_OVERLAY); 216 setSpecialCaseRenderQueueMode(SceneManager::SCRQM_EXCLUDE); 217 218 // transparents are skipped from hierarchical rendering 219 // => they need sorting, thus we render them afterwards 220 mSkipTransparents = mDelayRenderTransparents; 221 222 // set state for depth pass 223 mRenderDepthPass = mUseDepthPass; 224 225 /** 226 * the hierarchical culling algorithm 227 * for depth pass: will just find objects and update depth buffer 228 * for delayed rendering: will render all but transparents 229 **/ 230 231 mVisibilityManager->ApplyVisibilityCulling(); 232 233 //-- now we can savely render all remaining objects, e.g., transparents, overlay 234 mSkipTransparents = false; 235 236 clearSpecialCaseRenderQueues(); 237 SceneManager::_renderVisibleObjects(); 238 239 // for depth pass: add visible nodes found with the visibility culling 240 if (mUseDepthPass) 241 { 242 for (NodeList::iterator it = mVisible.begin(); it != mVisible.end(); ++it) 243 { 244 (*it)->_addToRenderQueue(mCameraInProgress, getRenderQueue(), false); 245 } 288 //-- prepare queue for visible objects (i.e., all but overlay and skies late) 289 clearSpecialCaseRenderQueues(); 290 addSpecialCaseRenderQueue(RENDER_QUEUE_SKIES_LATE); 291 addSpecialCaseRenderQueue(RENDER_QUEUE_OVERLAY); 292 setSpecialCaseRenderQueueMode(SceneManager::SCRQM_EXCLUDE); 293 294 295 // set all necessary parameters for 296 // hierarchical visibility culling and rendering 297 InitVisibilityCulling(mCameraInProgress); 298 299 /** 300 * the hierarchical culling algorithm 301 * for depth pass: we just find objects and update depth buffer 302 * for "delayed" rendering: we render some passes afterwards 303 * e.g., transparents, because they need front-to-back sorting 304 **/ 305 306 mVisibilityManager->ApplyVisibilityCulling(); 307 308 // delete remaining renderables from queue (all not in mLeavePassesInQueue) 309 #ifdef GTP_VISIBILITY_MODIFIED_OGRE 310 _deleteRenderedQueueGroups(mLeavePassesInQueue); 311 #endif 312 313 //-- reset parameters 246 314 mRenderDepthPass = false; 247 } 248 mSkipTransparents = false; 249 250 //-- now we can render all remaining queue objects 251 // for depth pass: all 252 // for delayed rendering: transparents, overlay 253 clearSpecialCaseRenderQueues(); 254 OctreeSceneManager::_renderVisibleObjects(); 255 256 WriteLog(); // write out stats 257 } 315 mRenderItemBuffer = false; 316 mSkipTransparents = false; 317 mLeavePassesInQueue = 0; 318 mShadowTechnique = mSavedShadowTechnique; 319 320 321 // add visible nodes found by the visibility culling algorithm 322 if (mUseDepthPass) 323 { 324 for (NodeList::iterator it = mVisible.begin(); it != mVisible.end(); ++it) 325 { 326 (*it)->_addToRenderQueue(mCameraInProgress, getRenderQueue(), false); 327 } 328 } 329 330 //-- we render all remaining queue objects 331 // used for depth pass, transparents, overlay 332 clearSpecialCaseRenderQueues(); 333 OctreeSceneManager::_renderVisibleObjects(); 334 335 } // hierarchical culling 336 337 // reset ambient light 338 setAmbientLight(savedAmbient); 339 340 getRenderQueue()->clear(); // finally clear render queue 341 //WriteLog(); // write out stats 342 } 343 258 344 //----------------------------------------------------------------------- 259 345 void VisibilityOctreeSceneManager::_updateSceneGraph(Camera* cam) … … 312 398 return true; 313 399 } 400 401 if (key == "DepthWrite") 402 { 403 mEnableDepthWrite = (*static_cast<const bool *>(val)); 404 return true; 405 } 406 if (key == "UseItemBuffer") 407 { 408 mUseItemBuffer = (*static_cast<const bool *>(val)); 409 return true; 410 } 411 if (key == "ExecuteVertexProgramForAllPasses") 412 { 413 mExecuteVertexProgramForAllPasses = (*static_cast<const bool *>(val)); 414 return true; 415 } 416 if (key == "RenderTransparentsForItemBuffer") 417 { 418 mRenderTransparentsForItemBuffer = (*static_cast<const bool *>(val)); 419 return true; 420 } 421 314 422 return VisibilityOptionsManager(mVisibilityManager, mHierarchyInterface). 315 423 setOption(key, val) || OctreeSceneManager::setOption(key, val); … … 372 480 } 373 481 //----------------------------------------------------------------------- 374 void VisibilityOctreeSceneManager::renderObjects(const RenderPriorityGroup::TransparentRenderablePassList& objs, 482 void VisibilityOctreeSceneManager::renderObjects( 483 const RenderPriorityGroup::TransparentRenderablePassList& objs, 375 484 bool doLightIteration, const LightList* manualLightList) 376 485 { 486 // for correct rendering, transparents must be rendered after hierarchical culling 377 487 if (!mSkipTransparents) 378 488 { … … 380 490 } 381 491 } 382 492 //----------------------------------------------------------------------- 493 bool VisibilityOctreeSceneManager::validatePassForRendering(Pass* pass) 494 { 495 // skip all but first pass if we are doing the depth pass 496 if ((mRenderDepthPass || mRenderItemBuffer) && pass->getIndex() > 0) 497 { 498 return false; 499 } 500 return SceneManager::validatePassForRendering(pass); 501 } 502 //----------------------------------------------------------------------- 503 void VisibilityOctreeSceneManager::renderQueueGroupObjects(RenderQueueGroup* pGroup) 504 { 505 if (!mRenderItemBuffer) 506 { 507 OctreeSceneManager::renderQueueGroupObjects(pGroup); 508 return; 509 } 510 511 // --- item buffer 512 513 // Iterate through priorities 514 RenderQueueGroup::PriorityMapIterator groupIt = pGroup->getIterator(); 515 516 while (groupIt.hasMoreElements()) 517 { 518 RenderItemBuffer(groupIt.getNext()); 519 } 520 } 521 //----------------------------------------------------------------------- 522 void VisibilityOctreeSceneManager::RenderItemBuffer(RenderPriorityGroup* pGroup) 523 { 524 // Do solids 525 RenderPriorityGroup::SolidRenderablePassMap solidObjs = pGroup->_getSolidPasses(); 526 527 // ----- SOLIDS LOOP ----- 528 RenderPriorityGroup::SolidRenderablePassMap::const_iterator ipass, ipassend; 529 ipassend = solidObjs.end(); 530 531 for (ipass = solidObjs.begin(); ipass != ipassend; ++ipass) 532 { 533 // Fast bypass if this group is now empty 534 if (ipass->second->empty()) 535 continue; 536 537 // Render only first pass 538 if (ipass->first->getIndex() > 0) 539 continue; 540 541 RenderPriorityGroup::RenderableList* rendList = ipass->second; 542 543 RenderPriorityGroup::RenderableList::const_iterator irend, irendend; 544 irendend = rendList->end(); 545 546 for (irend = rendList->begin(); irend != irendend; ++irend) 547 { 548 std::stringstream d; d << "itembuffer, pass name: " << 549 ipass->first->getParent()->getParent()->getName(); 550 551 LogManager::getSingleton().logMessage(d.str()); 552 553 RenderSingleObjectForItemBuffer(*irend, ipass->first); 554 } 555 } 556 557 // -- TRANSPARENT LOOP: must be handled differently 558 559 // transparents are treated either as solids or completely discarded 560 if (mRenderTransparentsForItemBuffer) 561 { 562 RenderPriorityGroup::TransparentRenderablePassList transpObjs = 563 pGroup->_getTransparentPasses(); 564 RenderPriorityGroup::TransparentRenderablePassList::const_iterator 565 itrans, itransend; 566 567 itransend = transpObjs.end(); 568 for (itrans = transpObjs.begin(); itrans != itransend; ++itrans) 569 { 570 // like for solids, render only first pass 571 if (itrans->pass->getIndex() == 0) 572 { 573 RenderSingleObjectForItemBuffer(itrans->renderable, itrans->pass); 574 } 575 } 576 } 577 } 578 //----------------------------------------------------------------------- 579 void VisibilityOctreeSceneManager::RenderSingleObjectForItemBuffer(Renderable *rend, Pass *pass) 580 { 581 static LightList nullLightList; 582 583 int col[4]; 584 585 // -- create color code out of object id 586 col[0] = (rend->getId() >> 16) & 255; 587 col[1] = (rend->getId() >> 8) & 255; 588 col[2] = rend->getId() & 255; 589 // col[3] = 255; 590 591 //mDestRenderSystem->setColour(col[0], col[1], col[2], col[3]); 592 593 mItemBufferPass->setAmbient(ColourValue(col[0] / 255.0f, 594 col[1] / 255.0f, 595 col[2] / 255.0f, 1)); 596 597 // set vertex program of current pass 598 if (mExecuteVertexProgramForAllPasses && pass->hasVertexProgram()) 599 { 600 mItemBufferPass->setVertexProgram(pass->getVertexProgramName()); 601 602 if (mItemBufferPass->hasVertexProgram()) 603 { 604 const GpuProgramPtr& prg = mItemBufferPass->getVertexProgram(); 605 // Load this program if not done already 606 if (!prg->isLoaded()) 607 prg->load(); 608 // Copy params 609 mItemBufferPass->setVertexProgramParameters(pass->getVertexProgramParameters()); 610 } 611 } 612 else if (mItemBufferPass->hasVertexProgram()) 613 { 614 mItemBufferPass->setVertexProgram(""); 615 } 616 617 Pass *usedPass = setPass(mItemBufferPass); 618 619 620 // Render a single object, this will set up auto params if required 621 renderSingleObject(rend, usedPass, false, &nullLightList); 622 } 623 //----------------------------------------------------------------------- 624 GtpVisibility::VisibilityManager *VisibilityOctreeSceneManager::GetVisibilityManager() 625 { 626 return mVisibilityManager; 627 } 628 //----------------------------------------------------------------------- 629 void VisibilityOctreeSceneManager::InitVisibilityCulling(Camera *cam) 630 { 631 InitDepthPass(); // create material for depth pass 632 InitItemBufferPass(); // create material for item buffer pass 633 634 // reset culling manager stats 635 mVisibilityManager->GetCullingManager()->InitFrame(mVisualizeCulledNodes); 636 637 // save shadow technique. It will be reset after hierarchical culling 638 mSavedShadowTechnique = mShadowTechnique; 639 640 // render standard solids without shadows during hierarchical culling pass 641 if ((mShadowTechnique == SHADOWTYPE_STENCIL_ADDITIVE) || 642 (mShadowTechnique == SHADOWTYPE_STENCIL_MODULATIVE)) 643 { 644 mShadowTechnique = SHADOWTYPE_NONE; 645 } 646 647 // set depth pass flag before rendering 648 mRenderDepthPass = mUseDepthPass; 649 650 // item buffer needs full ambient lighting to use item colors as unique id 651 if (mUseItemBuffer) 652 { 653 mRenderItemBuffer = true; 654 setAmbientLight(ColourValue(1,1,1,1)); 655 } 656 657 658 // set passes which are stored in render queue 659 // for rendering AFTER hierarchical culling, i.e., passes which need 660 // a special rendering order 661 662 mLeavePassesInQueue = 0; 663 664 if (!mUseDepthPass || !mUseItemBuffer) 665 { 666 if (mShadowTechnique == SHADOWTYPE_STENCIL_ADDITIVE) 667 { 668 // TODO: remove this pass because it should be processed during hierarchical culling 669 mLeavePassesInQueue |= RenderPriorityGroup::SOLID_PASSES_NOSHADOW; 670 671 mLeavePassesInQueue |= RenderPriorityGroup::SOLID_PASSES_DECAL; 672 mLeavePassesInQueue |= RenderPriorityGroup::SOLID_PASSES_DIFFUSE_SPECULAR; 673 mLeavePassesInQueue |= RenderPriorityGroup::TRANSPARENT_PASSES; 674 675 // just render ambient passes 676 mIlluminationStage = IRS_AMBIENT; 677 } 678 679 if (mShadowTechnique == SHADOWTYPE_STENCIL_MODULATIVE) 680 { 681 mLeavePassesInQueue |= RenderPriorityGroup::SOLID_PASSES_NOSHADOW; 682 mLeavePassesInQueue |= RenderPriorityGroup::TRANSPARENT_PASSES; 683 } 684 685 // transparents should be rendered after hierarchical culling to 686 // provide front-to-back ordering 687 if (mDelayRenderTransparents) 688 { 689 mLeavePassesInQueue |= RenderPriorityGroup::TRANSPARENT_PASSES; 690 } 691 } 692 693 // skip rendering transparents in the hierarchical culling 694 // (because they will be rendered afterwards) 695 mSkipTransparents = mUseDepthPass || 696 (mLeavePassesInQueue & RenderPriorityGroup::TRANSPARENT_PASSES); 697 698 // -- initialise interface for rendering traversal of the hierarchy 699 mHierarchyInterface->SetHierarchyRoot(mOctree); 700 701 // possible two cameras (one for culling, one for rendering) 702 mHierarchyInterface->InitTraversal(mCameraInProgress, 703 mCullCamera ? getCamera("CullCamera") : NULL, 704 mLeavePassesInQueue); 705 706 //std::stringstream d; d << "leave passes in queue: " << mLeavePassesInQueue;LogManager::getSingleton().logMessage(d.str()); 707 } 708 //----------------------------------------------------------------------- 709 OctreeHierarchyInterface *VisibilityOctreeSceneManager::GetHierarchyInterface() 710 { 711 return mHierarchyInterface; 712 } 713 //----------------------------------------------------------------------- 714 /*void VisibilityOctreeSceneManager::renderBasicQueueGroupObjects(RenderQueueGroup* pGroup) 715 { 716 // Basic render loop: Iterate through priorities 717 RenderQueueGroup::PriorityMapIterator groupIt = pGroup->getIterator(); 718 719 while (groupIt.hasMoreElements()) 720 { 721 RenderPriorityGroup* pPriorityGrp = groupIt.getNext(); 722 723 // Sort the queue first 724 pPriorityGrp->sort(mCameraInProgress); 725 726 // Do solids 727 // TODO: render other solid passes for shadows 728 renderObjects(pPriorityGrp->_getSolidPassesNoShadows(), true); 729 730 // do solid passes no shadows if addititive stencil shadows 731 if (mSavedShadowTechnique == SHADOWTYPE_STENCIL_ADDITIVE) 732 renderObjects(pPriorityGrp->_getSolidPassesNoShadows(), true); 733 734 // Do transparents 735 renderObjects(pPriorityGrp->_getTransparentPasses(), true); 736 737 738 }// for each priority 739 } 740 */ 741 //----------------------------------------------------------------------- 742 /* 743 Entity* VisibilityTerrainSceneManager::createEntity(const String& entityName, 744 const String& meshName) 745 { 746 Entity *ent = SceneManager::createEntity(entityName, meshName); 747 748 for (int i = 0; i < (int)ent->getNumSubEntities(); ++i) 749 { 750 ent->getSubEntity(i)->setId(mCurrentEntityId); 751 } 752 753 // increase counter of entity id values 754 ++ mCurrentEntityId; 755 756 return ent; 757 }*/ 383 758 } // namespace Ogre -
trunk/VUT/Ogre/src/OgreVisibilityTerrainSceneManager.cpp
r158 r159 31 31 mEnableDepthWrite(true), 32 32 mSkipTransparents(false), 33 mSavedShadowTechnique(SHADOWTYPE_NONE) 33 mSavedShadowTechnique(SHADOWTYPE_NONE), 34 mRenderTransparentsForItemBuffer(false), 35 mExecuteVertexProgramForAllPasses(false) 34 36 { 35 37 mHierarchyInterface = new OctreeHierarchyInterface(this, mDestRenderSystem); … … 37 39 //mDisplayNodes = true; 38 40 //mShowBoundingBoxes = true; 41 //mShowBoxes = true; 42 //mShowBoxes = true; 39 43 40 44 // TODO: set maxdepth to reasonable value … … 48 52 if (depthMat.isNull()) 49 53 { 50 // Init51 54 depthMat = MaterialManager::getSingleton().create( 52 55 "Visibility/DepthPass", 53 56 ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); 57 54 58 mDepthPass = depthMat->getTechnique(0)->getPass(0); 55 59 mDepthPass->setColourWriteEnabled(false); … … 60 64 { 61 65 mDepthPass = depthMat->getTechnique(0)->getPass(0); 66 } 67 } 68 //----------------------------------------------------------------------- 69 VisibilityTerrainSceneManager::~VisibilityTerrainSceneManager() 70 { 71 if (mHierarchyInterface) 72 { 73 delete mHierarchyInterface; 74 mHierarchyInterface = NULL; 62 75 } 63 76 } … … 85 98 } 86 99 //mItemBufferPass->setAmbient(1, 1, 0); 87 }88 //-----------------------------------------------------------------------89 VisibilityTerrainSceneManager::~VisibilityTerrainSceneManager()90 {91 if (mHierarchyInterface)92 {93 delete mHierarchyInterface;94 mHierarchyInterface = NULL;95 }96 100 } 97 101 //----------------------------------------------------------------------- … … 160 164 } 161 165 162 if (mRenderDepthPass) 163 { 164 // --- set vertex program of current pass so z-buffer is updated correctly 165 if (pass->hasVertexProgram()) 166 { 167 mDepthPass->setVertexProgram(pass->getVertexProgramName()); 168 169 if (mDepthPass->hasVertexProgram()) 170 { 171 const GpuProgramPtr& prg = mDepthPass->getVertexProgram(); 172 // Load this program if not done already 173 if (!prg->isLoaded()) 174 prg->load(); 175 // Copy params 176 mDepthPass->setVertexProgramParameters(pass->getVertexProgramParameters()); 177 } 178 } 179 else if (mDepthPass->hasVertexProgram()) 180 { 181 mDepthPass->setVertexProgram(""); 182 } 183 } 166 // --- set vertex program of current pass in order to set correct depth 167 if (mExecuteVertexProgramForAllPasses && mRenderDepthPass && pass->hasVertexProgram()) 168 { 169 // add vertex program of current pass to depth pass 170 mDepthPass->setVertexProgram(pass->getVertexProgramName()); 171 172 if (mDepthPass->hasVertexProgram()) 173 { 174 const GpuProgramPtr& prg = mDepthPass->getVertexProgram(); 175 // Load this program if not done already 176 if (!prg->isLoaded()) 177 prg->load(); 178 // Copy params 179 mDepthPass->setVertexProgramParameters(pass->getVertexProgramParameters()); 180 } 181 } 182 else if (mDepthPass->hasVertexProgram()) 183 { 184 mDepthPass->setVertexProgram(""); 185 } 186 184 187 185 188 bool IsDepthWrite = usedPass->getDepthWriteEnabled(); … … 228 231 // mHierarchyInterface->SetOnlyShadowCasters(onlyShadowCasters); 229 232 } 230 //TerrainSceneManager::_findVisibleObjects(cam, onlyShadowCasters);233 231 234 232 235 // -- delete lists stored for visualization … … 240 243 ColourValue savedAmbient = mAmbientLight; 241 244 242 // --- apply standard rendering for some cases (e.g., visualization, shadow pass)245 //-- apply standard rendering for some modes (e.g., visualization, shadow pass) 243 246 244 247 if (mShowVisualization || … … 257 260 mIlluminationStage = savedStage; 258 261 } 259 else // 262 else //-- the hierarchical culling algorithm 260 263 { 261 264 // don't render backgrounds for item buffer … … 266 269 } 267 270 271 //-- hierarchical culling 268 272 // the objects of different layers (e.g., background, scene, 269 273 // overlay) must be identified and rendered one after another … … 279 283 280 284 #ifdef GTP_VISIBILITY_MODIFIED_OGRE 281 // delete previously rendered conten bt285 // delete previously rendered content 282 286 _deleteRenderedQueueGroups(); 283 287 #endif … … 296 300 /** 297 301 * the hierarchical culling algorithm 298 * if we use a depth pass: will just find objects and update depth buffer 299 * for "delayed" rendering: will render some passes afterwards, e.g., transparents 302 * for depth pass: we just find objects and update depth buffer 303 * for "delayed" rendering: we render some passes afterwards 304 * e.g., transparents, because they need front-to-back sorting 300 305 **/ 301 306 … … 325 330 326 331 //-- now we can render all remaining queue objects 327 // for depth pass, transparents, overlay332 // used for depth pass, transparents, overlay 328 333 clearSpecialCaseRenderQueues(); 329 334 TerrainSceneManager::_renderVisibleObjects(); 330 335 } 331 336 332 // set the new render level index afterwards => new level in the next frame 333 int levelIdx = TerrainRenderable::getCurrentRenderLevelIndex() + 1; 334 TerrainRenderable::setCurrentRenderLevelIndex(levelIdx); 335 337 // set the new render level index 338 TerrainRenderable::NextRenderLevelIndex(); 339 336 340 // reset ambient light 337 341 setAmbientLight(savedAmbient); 338 342 339 getRenderQueue()->clear(); 343 getRenderQueue()->clear(); // finally clear render queue 340 344 //WriteLog(); // write out stats 341 345 } … … 397 401 return true; 398 402 } 399 // notifiy that frame has ended so terrain render level can be reset for correct 400 // terrain rendering 401 if (key == "TerrainLevelIdx") 402 { 403 TerrainRenderable::setCurrentRenderLevelIndex((*static_cast<const int *>(val))); 404 return true; 405 } 403 406 404 if (key == "DepthWrite") 407 405 { … … 414 412 return true; 415 413 } 416 414 if (key == "ExecuteVertexProgramForAllPasses") 415 { 416 mExecuteVertexProgramForAllPasses = (*static_cast<const bool *>(val)); 417 return true; 418 } 419 if (key == "RenderTransparentsForItemBuffer") 420 { 421 mRenderTransparentsForItemBuffer = (*static_cast<const bool *>(val)); 422 return true; 423 } 424 417 425 return VisibilityOptionsManager(mVisibilityManager, mHierarchyInterface). 418 426 setOption(key, val) || TerrainSceneManager::setOption(key, val); … … 547 555 } 548 556 549 // ----- TRANSPARENT LOOP: must be handled differently 550 // TODO: HOW TO HANDLE OCCLUDED OBJECTS ???? 551 RenderPriorityGroup::TransparentRenderablePassList 552 transpObjs = pGroup->_getTransparentPasses(); 553 RenderPriorityGroup::TransparentRenderablePassList::const_iterator itrans, itransend; 554 555 itransend = transpObjs.end(); 556 for (itrans = transpObjs.begin(); itrans != itransend; ++itrans) 557 { 558 // like for solids, render only first pass 559 if (itrans->pass->getIndex() == 0) 560 { 561 RenderSingleObjectForItemBuffer(itrans->renderable, itrans->pass); 562 } 563 } 557 // -- TRANSPARENT LOOP: must be handled differently 558 559 // transparents are treated either as solids or completely discarded 560 if (mRenderTransparentsForItemBuffer) 561 { 562 RenderPriorityGroup::TransparentRenderablePassList transpObjs = 563 pGroup->_getTransparentPasses(); 564 RenderPriorityGroup::TransparentRenderablePassList::const_iterator 565 itrans, itransend; 566 567 itransend = transpObjs.end(); 568 for (itrans = transpObjs.begin(); itrans != itransend; ++itrans) 569 { 570 // like for solids, render only first pass 571 if (itrans->pass->getIndex() == 0) 572 { 573 RenderSingleObjectForItemBuffer(itrans->renderable, itrans->pass); 574 } 575 } 576 } 564 577 } 565 578 //----------------------------------------------------------------------- … … 583 596 584 597 // set vertex program of current pass 585 if ( pass->hasVertexProgram())598 if (mExecuteVertexProgramForAllPasses && pass->hasVertexProgram()) 586 599 { 587 600 mItemBufferPass->setVertexProgram(pass->getVertexProgramName()); … … 614 627 } 615 628 //----------------------------------------------------------------------- 616 Entity* VisibilityTerrainSceneManager::createEntity(const String& entityName,617 const String& meshName)618 {619 Entity *ent = SceneManager::createEntity(entityName, meshName);620 621 for (int i = 0; i < (int)ent->getNumSubEntities(); ++i)622 {623 ent->getSubEntity(i)->setId(mCurrentEntityId);624 }625 626 // increase counter of entity id values627 ++ mCurrentEntityId;628 629 return ent;630 }631 //-----------------------------------------------------------------------632 629 void VisibilityTerrainSceneManager::InitVisibilityCulling(Camera *cam) 633 630 { … … 644 641 if ((mShadowTechnique == SHADOWTYPE_STENCIL_ADDITIVE) || 645 642 (mShadowTechnique == SHADOWTYPE_STENCIL_MODULATIVE)) 646 { 647 643 { 648 644 mShadowTechnique = SHADOWTYPE_NONE; 649 645 } … … 660 656 661 657 662 // set passes which should be stored in render queue658 // set passes which are stored in render queue 663 659 // for rendering AFTER hierarchical culling, i.e., passes which need 664 660 // a special rendering order … … 715 711 } 716 712 //----------------------------------------------------------------------- 713 void VisibilityTerrainSceneManager::endFrame() 714 { 715 TerrainRenderable::ResetRenderLevelIndex(); 716 } 717 //----------------------------------------------------------------------- 717 718 /*void VisibilityTerrainSceneManager::renderBasicQueueGroupObjects(RenderQueueGroup* pGroup) 718 719 { … … 742 743 } 743 744 */ 745 //----------------------------------------------------------------------- 746 /* 747 Entity* VisibilityTerrainSceneManager::createEntity(const String& entityName, 748 const String& meshName) 749 { 750 Entity *ent = SceneManager::createEntity(entityName, meshName); 751 752 for (int i = 0; i < (int)ent->getNumSubEntities(); ++i) 753 { 754 ent->getSubEntity(i)->setId(mCurrentEntityId); 755 } 756 757 // increase counter of entity id values 758 ++ mCurrentEntityId; 759 760 return ent; 761 } 762 */ 744 763 } // namespace Ogre
Note: See TracChangeset
for help on using the changeset viewer.