Changeset 2455 for GTP/trunk/Lib
- Timestamp:
- 06/14/07 17:24:08 (18 years ago)
- Location:
- GTP/trunk/Lib/Vis/OnlineCullingCHC
- Files:
-
- 1 deleted
- 26 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreOctreeHierarchyInterface.h
r2332 r2455 64 64 65 65 void PullUpLastVisited(GtpVisibility::HierarchyNode *node, const int frameId) const; 66 void DetermineVisibilityRatio(GtpVisibility::HierarchyNode *node) const;67 float GetNodeVisibilityRatio(GtpVisibility::HierarchyNode *node) const;66 67 GtpVisibility::HierarchyNode *GetParent(GtpVisibility::HierarchyNode *node); 68 68 69 GtpVisibility::HierarchyNode *GetParent(GtpVisibility::HierarchyNode *node); 69 70 71 /** Returns #frames this node is assumed to be visible. 72 */ 73 int GetNodeAssumedVisible(GtpVisibility::HierarchyNode *node); 74 75 /** Sets #frames this node is assumed to be visible. 76 */ 77 void SetNodeAssumedVisible(GtpVisibility::HierarchyNode *node, int assumedVisible); 78 79 /** Decreases #frames this node is assumed to be visible. 80 */ 81 void DecNodeAssumedVisible(GtpVisibility::HierarchyNode *node); 82 83 void RenderGeometryBounds(GtpVisibility::HierarchyNode *node); 70 84 71 85 … … 77 91 */ 78 92 AxisAlignedBox *GetBoundingBox(GtpVisibility::HierarchyNode *node); 93 79 94 /** Returns squared distance of center of box with respect to the camera . 80 95 @param cam current camera -
GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgrePlatformHierarchyInterface.h
r2332 r2455 26 26 { 27 27 public: 28 28 29 /** Construction taking the current scene manager and the 29 30 current rendersystem as argument … … 33 34 PlatformHierarchyInterface(SceneManager *sm, RenderSystem *rsys); 34 35 ~PlatformHierarchyInterface(); 35 36 36 /** Returns next available occlusion query or creates new one. 37 37 @return the next occlusion query … … 76 76 /** Issue a occlusion query for this node. 77 77 @param node the current hierarchy node 78 @param wasVisible if the node was visible in the last frame 78 @param gives a parameters that decideds on the type of occlusion query. 79 79 80 @returns occlusion query for this node 80 81 */ 81 82 GtpVisibility::OcclusionQuery *IssueNodeOcclusionQuery( 82 GtpVisibility::HierarchyNode *node, const bool wasVisible);83 GtpVisibility::HierarchyNode *node, const bool testGeometry = false); 83 84 84 85 /** Issue a occlusion query for this mesh. … … 87 88 */ 88 89 GtpVisibility::OcclusionQuery *IssueMeshOcclusionQuery(GtpVisibility::Mesh *mesh); 89 90 90 /** If true, the interface finds and renders only objects which are marked as shadow casters. 91 91 @remark This is important for the shadow texture pass … … 95 95 */ 96 96 bool GetOnlyShadowCasters(); 97 /** see set98 */99 bool GetTestGeometryForVisibleLeaves();100 97 /** see set 101 98 */ 102 99 SceneManager *GetSceneManager(); 103 104 100 /** see set 105 101 */ 106 102 RenderSystem *GetRenderSystem(); 107 108 103 /** true if bounding box query is currently active. 109 104 */ 110 105 bool IsBoundingBoxQuery(); 111 106 /** Issues occlusion queries for a patch. 107 */ 112 108 GtpVisibility::OcclusionQuery *IssuePatchOcclusionQuery(GtpVisibility::Patch *patch); 113 114 109 /** Deletes all occlusion queries. 115 110 */ … … 126 121 127 122 void PullUpLastVisited(GtpVisibility::HierarchyNode *node, const int frameId) const {} 128 void DetermineVisibilityRatio(GtpVisibility::HierarchyNode *node) const {}129 123 130 float GetNodeVisibilityRatio(GtpVisibility::HierarchyNode *node) const { return 1.0f;}124 GtpVisibility::HierarchyNode *GetParent(GtpVisibility::HierarchyNode *node) { return NULL; } 131 125 132 GtpVisibility::HierarchyNode *GetParent(GtpVisibility::HierarchyNode *node) { return NULL;} 126 /** Returns #frames this node is assumed to be visible. 127 */ 128 virtual int GetNodeAssumedVisible(GtpVisibility::HierarchyNode *node) { return 0; }; 129 /** Sets #frames this node is assumed to be visible. 130 */ 131 virtual void SetNodeAssumedVisible(GtpVisibility::HierarchyNode *node, int assumedVisible) {}; 132 /** Decreases #frames this node is assumed to be visible. 133 */ 134 virtual void DecNodeAssumedVisible(GtpVisibility::HierarchyNode *node) {}; 135 /** Test tigher geometry bounds instead of hierarchy node. 136 */ 137 void SetTestGeometryBounds(bool testGeometryForLeaves); 138 /** See get 139 */ 140 int GetTestGeometryBounds(); 133 141 134 142 … … 138 146 */ 139 147 void RenderGeometry(GtpVisibility::Mesh *geom); 140 141 148 /** Renders the given patch 142 149 */ 143 150 void RenderPatch(GtpVisibility::Patch *patch); 144 145 151 /** Materials for visualizing frustum and query culled nodes. 146 152 */ 147 153 void CreateNodeVizMaterials(); 148 149 154 /** Returns pointer to current renderable bounding box geometry. 150 155 */ 151 156 SolidBoundingBox *GetSolidBoundingBox(); 152 153 /** A pass that prepares an occlusion query.154 @remark disables depth write, colour write, lighting,155 vertex and fragment program.*/156 //void SetOcclusionPass();157 158 157 /** Renders given bounding box. 159 158 @param box the bounding box of the scene node to be rendered 160 159 */ 161 160 void RenderBoundingBox(AxisAlignedBox *box); 161 /** Renders bounding boxes of the geometry. 162 @param node the node to be rendered 163 */ 164 virtual void RenderGeometryBounds(GtpVisibility::HierarchyNode *node) {}; 165 166 167 ///////////////////// 162 168 163 169 /** Renderable of an aabb. … … 179 185 int mLeavePassesInQueue; 180 186 bool mIsBoundingBoxQuery; 187 188 bool mTestGeometryBounds; 181 189 }; 182 190 -
GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreBiHierarchyInterface.cpp
r2348 r2455 84 84 // reuse box if node is the same 85 85 // only create renderable bounding box for new node 86 if (node != m SavedNode)86 if (node != mOldNode) 87 87 { 88 m SavedNode = node;88 mOldNode = node; 89 89 mBox = BIHNODEPTR_CAST(node)->_getWorldAABB(); 90 90 } -
GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreBiHierarchySceneManager.cpp
r2402 r2455 1429 1429 d << "Depth pass: " << StringConverter::toString(mUseDepthPass) << ", " 1430 1430 << "Delay transparents: " << StringConverter::toString(mDelayRenderTransparents) << ", " 1431 << "Use optimization: " << StringConverter::toString(mHierarchyInterface->GetTestGeometryForVisibleLeaves()) << ", "1431 //<< "Use optimization: " << StringConverter::toString(mHierarchyInterface->GetTestGeometryForVisibleLeaves()) << ", " 1432 1432 << "Algorithm type: " << mVisibilityManager->GetCullingManagerType() << ", " 1433 1433 << "Hierarchy nodes: " << (mBiHierarchy ? mBiHierarchy->getTreeStats().mNumNodes : 0) << ", " -
GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreKdTreeHierarchyInterface.cpp
r2280 r2455 84 84 // reuse box if node is the same 85 85 // only create renderable bounding box for new node 86 if (node != m SavedNode)86 if (node != mOldNode) 87 87 { 88 m SavedNode = node;88 mOldNode = node; 89 89 mBox = KDNODEPTR_CAST(node)->_getWorldAABB(); 90 90 } -
GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreKdTreeSceneManager.cpp
r2130 r2455 1419 1419 d << "Depth pass: " << StringConverter::toString(mUseDepthPass) << ", " 1420 1420 << "Delay transparents: " << StringConverter::toString(mDelayRenderTransparents) << ", " 1421 << "Use optimization: " << StringConverter::toString(mHierarchyInterface->GetTestGeometryForVisibleLeaves()) << ", "1421 //<< "Use optimization: " << StringConverter::toString(mHierarchyInterface->GetTestGeometryForVisibleLeaves()) << ", " 1422 1422 << "Algorithm type: " << mVisibilityManager->GetCullingManagerType() << ", " 1423 1423 << "Hierarchy nodes: " << (mKdTree ? mKdTree->getTreeStats().mNumNodes : 0) << ", " -
GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionCullingSceneManager.cpp
r2402 r2455 311 311 } 312 312 313 ///////////// 313 314 val = config.getSetting("OnlineCullingAlgorithm"); 314 315 … … 357 358 358 359 ///////////// 359 // terrain options 360 val = config.getSetting("TestGeometryForVisibleLeaves"); 361 362 if (!val.empty()) 363 { 364 if (val == "yes") 365 mVisibilityManager->SetTestGeometryForVisibleLeaves(true); 366 else 367 mVisibilityManager->SetTestGeometryForVisibleLeaves(false); 368 } 369 370 ///////////// 371 val = config.getSetting("TestGeometryBounds"); 372 373 if (!val.empty()) 374 { 375 if (val == "yes") 376 mHierarchyInterface->SetTestGeometryBounds(true); 377 else 378 mHierarchyInterface->SetTestGeometryBounds(false); 379 } 380 381 ///////////// 382 val = config.getSetting("AssumedVisibleFrames"); 383 384 if (!val.empty()) 385 { 386 mVisibilityManager->SetAssumedVisibilityForChc(atoi(val.c_str())); 387 } 388 389 390 ///////////// 391 val = config.getSetting("RandomUpdateCandidates"); 392 393 if (!val.empty()) 394 { 395 mVisibilityManager->SetRandomUpdateCandidatesForRuc(atoi(val.c_str())); 396 } 397 398 399 ///////////// 400 // output 360 401 361 402 if (mUseDepthPass) … … 395 436 else 396 437 LogManager::getSingleton().logMessage("not flushing queue after some frames"); 438 439 if (mVisibilityManager->GetTestGeometryForVisibleLeaves()) 440 LogManager::getSingleton().logMessage("test geometry for visible leaves"); 441 else 442 LogManager::getSingleton().logMessage("not testing geometry for visible leaves"); 443 444 if (mHierarchyInterface->GetTestGeometryBounds()) 445 LogManager::getSingleton().logMessage("test geometry bounds instead of bounding box"); 446 else 447 LogManager::getSingleton().logMessage("not testing geometry bounds instead of bounding box"); 448 449 450 ///////////// 451 // terrain options 397 452 398 453 if (!mShowTerrain) … … 1263 1318 d << "Depth pass: " << StringConverter::toString(mUseDepthPass) << ", " 1264 1319 << "Delay transparents: " << StringConverter::toString(mDelayRenderTransparents) << ", " 1265 << "Use optimization: " << StringConverter::toString(mHierarchyInterface->GetTestGeometryForVisibleLeaves()) << ", "1320 // << "Use optimization: " << StringConverter::toString(mHierarchyInterface->GetTestGeometryForVisibleLeaves()) << ", " 1266 1321 << "Algorithm type: " << mVisibilityManager->GetCullingManagerType() << ", " 1267 1322 << "Hierarchy nodes: " << mNumOctants << ", " … … 1686 1741 LogManager::getSingleton().logMessage("error: should not come here"); 1687 1742 // question: if no view cell, set everything visible? 1688 //SetObjectsVisible(true);1689 1743 SetObjectsVisible(false); 1690 1744 return; … … 1693 1747 //////////// 1694 1748 //-- set PVS of view cell to visible 1695 1696 //std::stringstream d; d << "appying new view cell pvs: " << vc->GetPvs().GetSize();1697 //LogManager::getSingleton().logMessage(d.str());1698 1749 1699 1750 GtpVisibilityPreprocessor::ObjectPvsIterator pit = vc->GetPvs().GetIterator(); … … 1717 1768 const GtpVisibilityPreprocessor::Vector3 viewPoint = 1718 1769 OgreTypeConverter::ConvertFromOgre(cam->getDerivedPosition()); 1719 1720 //std::stringstream d; d << "vp: " << viewPoint;1721 //LogManager::getSingleton().logMessage(d.str());1722 1770 1723 1771 GtpVisibilityPreprocessor::ViewCell *newElementary = … … 2173 2221 } 2174 2222 2175 // Prepare render queue for receiving new objects2176 //prepareRenderQueue();2177 2178 2223 mDestRenderSystem->_beginGeometryCount(); 2179 2224 // Begin the frame … … 2281 2326 /////////////////////// 2282 2327 //-- put items in render queue 2283 //////////2284 2328 2285 2329 getRenderQueue()->clear(); 2286 2330 2287 //////////////////////2288 //-- apply queries on geometry level2289 2290 2331 if (!nodeVisibility) 2291 2332 { 2333 ////////////////// 2334 //-- apply queries on geometry level 2335 2292 2336 MeshInfoContainer::iterator geomIt, geomIt_end = visibleGeometry.end(); 2293 2337 … … 2384 2428 if (camera->isWindowSet()) 2385 2429 { 2386 const std::vector<Plane>& planeList = 2387 camera->getWindowPlanes(); 2388 for (ushort i = 0; i < 4; ++ i)2430 const std::vector<Plane>& planeList = camera->getWindowPlanes(); 2431 2432 for (ushort i = 0; i < 4; ++ i) 2389 2433 { 2390 2434 mDestRenderSystem->enableClipPlane(i, true); … … 2421 2465 2422 2466 RenderHierarchicalCulling(fillQueue); 2423 // _renderVisibleObjects();2424 2467 2425 2468 // End frame … … 2529 2572 2530 2573 if (mQueryMode == 2) 2531 {2532 2574 approximateVisibility = true; 2533 }2534 2575 } 2535 2576 else … … 2542 2583 new OcclusionQueriesQueryManager(mHierarchyInterface, 2543 2584 cam->getViewport(), 2544 //mCurrentViewport,2545 2585 queryModes, 2546 2586 itemBufferMode); -
GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOctreeHierarchyInterface.cpp
r2360 r2455 3 3 #include <OgreLogManager.h> 4 4 #include <OgreStringConverter.h> 5 #include <OgreOctreeNode.h> 5 6 6 7 … … 187 188 } 188 189 //----------------------------------------------------------------------- 189 void OctreeHierarchyInterface::DetermineVisibilityRatio(GtpVisibility::HierarchyNode *node) const190 {191 #if 0192 Octree *octant = static_cast<Octree *>(node);193 194 // node not visited in this frame => no change195 if (octant->lastVisited() != mFrameId)196 return;197 198 // leaf node: terminate recursion199 if (IsLeaf(node))200 {201 octant->setNumLeaves(1);202 octant->setNumVisibleLeaves(octant->isOctreeVisible() ? 1 : 0);203 return;204 }205 206 int numVisibleLeaves = 0;207 int numLeaves = 0;208 209 Octree *nextChild;210 211 for (int i = 0; i < 8; ++ i)212 {213 int x = (i & 4) / 4;214 int y = (i & 2) / 2;215 int z = i & 1;216 217 nextChild = octant->mChildren[x][y][z];218 219 if (!nextChild)220 continue;221 222 // recursive traversal223 DetermineVisibilityRatio(nextChild);224 225 // this leaf is not fully visible226 numLeaves += nextChild->getNumLeaves();227 numVisibleLeaves += nextChild->getNumVisibleLeaves();228 }229 230 octant->setNumLeaves(numLeaves);231 octant->setNumVisibleLeaves(numVisibleLeaves);232 #endif233 }234 //-----------------------------------------------------------------------235 190 void OctreeHierarchyInterface::RenderNode(GtpVisibility::HierarchyNode *node) 236 191 { … … 290 245 } 291 246 //----------------------------------------------------------------------- 292 float OctreeHierarchyInterface::GetNodeVisibilityRatio(GtpVisibility::HierarchyNode *node) const293 {294 #if 0295 return static_cast<Octree *>(node)->getVisibilityRatio();296 #else297 return 1.0f;298 #endif299 }300 //-----------------------------------------------------------------------301 247 unsigned int OctreeHierarchyInterface::LastVisited(GtpVisibility::HierarchyNode *node) const 302 248 { … … 312 258 // reuse box if node is the same 313 259 // only create renderable bounding box for new node 314 if (node != m SavedNode)315 { 316 m SavedNode = node;260 if (node != mOldNode) 261 { 262 mOldNode = node; 317 263 //static_cast<Octree *>(node)->_getCullBounds(&mBox); 318 264 mBox = static_cast<Octree *>(node)->_getWorldAABB(); … … 374 320 375 321 for (int z = 0; z < 2; ++ z) 376 {377 322 for (int y = 0; y < 2; ++ y) 378 {379 323 for (int x = 0; x < 2; ++ x) 380 {381 324 if ((child = octree->mChildren[x][y][z]) != NULL) 382 {383 325 tStack.push(child); 384 }385 }386 }387 }388 326 } 389 327 } … … 394 332 { 395 333 Octree *octree = static_cast<Octree *>(node); 396 397 334 return octree->getParent(); 398 335 } 336 //----------------------------------------------------------------------- 337 int OctreeHierarchyInterface::GetNodeAssumedVisible(GtpVisibility::HierarchyNode *node) 338 { 339 Octree *octree = static_cast<Octree *>(node); 340 return octree->getAssumedVisible(); 341 } 342 //----------------------------------------------------------------------- 343 void OctreeHierarchyInterface::SetNodeAssumedVisible(GtpVisibility::HierarchyNode *node, int assumedVisible) 344 { 345 Octree *octree = static_cast<Octree *>(node); 346 octree->setAssumedVisible(assumedVisible); 347 } 348 //----------------------------------------------------------------------- 349 void OctreeHierarchyInterface::DecNodeAssumedVisible(GtpVisibility::HierarchyNode *node) 350 { 351 Octree *octree = static_cast<Octree *>(node); 352 octree->decAssumedVisible(); 353 } 354 //----------------------------------------------------------------------- 355 void OctreeHierarchyInterface::RenderGeometryBounds(GtpVisibility::HierarchyNode *node) 356 { 357 Octree *octree = static_cast<Octree *>(node); 358 359 NodeList::iterator it, it_end = octree->mNodes.end(); 360 361 for (it = octree->mNodes.begin(); it != it_end; ++ it) 362 { 363 RenderBoundingBox(&(*it)->_getWorldAABB()); 364 } 365 } 366 399 367 400 368 } // namespace Ogre -
GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgrePlatformHierarchyInterface.cpp
r2318 r2455 99 99 mRenderSystem->_setWorldMatrix(Ogre::Matrix4::IDENTITY); 100 100 mSceneManager->useRenderableViewProjModeWrapper(solidBox); 101 // HACK! (mySetPass should be setPass)101 102 102 // set no depth write, no color, no lighting material 103 103 mSceneManager->setPassWrapper(solidBox->getTechnique()->getPass(0)); 104 //mSceneManager->_setPass(solidBox->getTechnique()->getPass(0));105 //SetOcclusionPass();106 107 104 solidBox->SetupBoundingBoxVertices(*box); 108 105 109 106 solidBox->getRenderOperation(ro); 110 107 ro.srcRenderable = solidBox; 108 111 109 //std::stringstream d; 112 110 //d << "vt2: " << ro.vertexData; … … 132 130 { 133 131 mOcclusionQueries.push_back(new PlatformOcclusionQuery(mRenderSystem)); 134 135 /*std::stringstream d;136 d << "resizing queries: " << (int)mOcclusionQueries.size() << std::endl;137 LogManager::getSingleton().logMessage(d.str());*/138 132 } 139 133 … … 147 141 GtpVisibility::HierarchyInterface::InitTraversal(); 148 142 149 m SavedNode = NULL;143 mOldNode = NULL; 150 144 mLeavePassesInQueue = leavePassesInQueue; 151 145 … … 181 175 GtpVisibility::OcclusionQuery *PlatformHierarchyInterface::IssueNodeOcclusionQuery( 182 176 GtpVisibility::HierarchyNode *node, 183 const bool wasVisible)177 const bool testGeometry) 184 178 { 185 179 // get next available test id … … 189 183 query->BeginQuery(); 190 184 191 // if node is leaf and was visible => will be rendered anyway. 192 // In this case we can also test with the real geometry. 193 // If camera for culling is different from camera for rendering or only solids 194 // will be rendered => cannot optimize 195 if (mTestGeometryForVisibleLeaves && (mCamera == mCullCamera) && wasVisible && IsLeaf(node)) 196 { 185 if (testGeometry && IsLeaf(node)) 186 { 187 // if node is a leaf and was visible => will be rendered anyway. 188 // In this case we can also test with the real geometry. 197 189 RenderNode(node); 198 190 } 199 else 200 { 201 // this information is used e.g., by the scene graph, because the bounding box 202 // must be treated differently to the scene geometry during rendering 203 mIsBoundingBoxQuery = true; 204 RenderBoundingBox(GetBoundingBox(node)); 205 206 mIsBoundingBoxQuery = false; 191 else 192 { 193 if (mTestGeometryBounds && IsLeaf(node)) 194 { 195 mIsBoundingBoxQuery = true; 196 // we can also test the tighter bounds of the geometry instead of the hierarchy nodes. 197 RenderGeometryBounds(node); 198 mIsBoundingBoxQuery = false; 199 } 200 else 201 { 202 // this information is used e.g., by the scene graph, because the bounding box 203 // must be treated differently to the scene geometry during rendering 204 mIsBoundingBoxQuery = true; 205 RenderBoundingBox(GetBoundingBox(node)); 206 mIsBoundingBoxQuery = false; 207 } 207 208 } 208 209 … … 236 237 //////// 237 238 //-- the actual query test 238 239 239 query->BeginQuery(); 240 240 241 RenderGeometry(mesh); 242 241 243 query->EndQuery(); 242 244 … … 244 246 } 245 247 //----------------------------------------------------------------------- 246 /*void PlatformHierarchyInterface::SetOcclusionPass()247 {248 // disable vertex and fragment program249 mRenderSystem->unbindGpuProgram(GPT_VERTEX_PROGRAM);250 mRenderSystem->unbindGpuProgram(GPT_FRAGMENT_PROGRAM);251 252 // disable lighting253 mRenderSystem->setLightingEnabled(false);254 255 // Disable remaining texture units256 mRenderSystem->_disableTextureUnitsFrom(0);257 258 //--Set up non-texture related material settings259 260 // Depth buffer settings261 mRenderSystem->_setDepthBufferParams(true, false, CMPF_LESS_EQUAL);262 // Set colour write mode off263 mRenderSystem->_setColourBufferWriteEnabled(false, false, false, false);264 }*/265 //-----------------------------------------------------------------------266 248 SolidBoundingBox *PlatformHierarchyInterface::GetSolidBoundingBox() 267 249 { 268 250 if (!mSolidBoundingBox) 269 {270 251 mSolidBoundingBox = new SolidBoundingBox; 271 //LogManager::getSingleton().logMessage("solid box created");272 }273 252 274 253 return mSolidBoundingBox; … … 285 264 } 286 265 //----------------------------------------------------------------------- 287 bool PlatformHierarchyInterface::GetTestGeometryForVisibleLeaves()288 {289 return mTestGeometryForVisibleLeaves;290 }291 //-----------------------------------------------------------------------292 266 bool PlatformHierarchyInterface::IsBoundingBoxQuery() 293 267 { … … 314 288 return mRenderSystem; 315 289 } 290 //----------------------------------------------------------------------- 291 void PlatformHierarchyInterface::SetTestGeometryBounds(bool testGeometryBounds) 292 { 293 mTestGeometryBounds = testGeometryBounds; 294 } 295 //----------------------------------------------------------------------- 296 int PlatformHierarchyInterface::GetTestGeometryBounds() 297 { 298 return mTestGeometryBounds; 299 } 316 300 317 301 } // namespace Ogre -
GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgrePlatformQueryManager.cpp
r2280 r2455 12 12 namespace Ogre { 13 13 14 //----------------------------------------------------------------------- 15 /* 16 PlatformQueryManager::PlatformQueryManager(PlatformHierarchyInterface *hierarchyInterface, 17 Viewport *vp, 18 int queryModes): 19 //QueryManager(hierarchyInterface, queryModes), 20 QueryManager(queryModes), 21 mViewport(vp), 22 mWasInitialised(false), 23 mHierarchyInterface(hierarchyInterface) 24 { 25 }*/ 26 //----------------------------------------------------------------------- 27 /*bool PlatformQueryManager::ShootRay(const Ray &ray, 28 std::vector<Mesh *> *visibleMeshes, 29 bool isGlobalLine) 30 { 31 // run OGRE ray shooting query 32 return false; 33 }*/ 14 34 15 //----------------------------------------------------------------------- 35 16 void PlatformQueryManager::ComputeFromPointVisibility( … … 41 22 const bool approximateVisibility) 42 23 { 43 SceneManager *sm = 44 static_cast<PlatformHierarchyInterface *> 24 SceneManager *sm = static_cast<PlatformHierarchyInterface *> 45 25 (mHierarchyInterface)->GetSceneManager(); 46 26 … … 95 75 relativeVisibility, 96 76 approximateVisibility); 97 //mViewport->getTarget()->update(); for(int j=0; j<10000000; j++) printf("wait");98 77 99 78 // permute directions … … 176 155 uchar *buf = mViewport->getTarget()->getBufferContents(dimx, dimy); 177 156 178 //std::stringstream d; d << "dimx: " << dimx << ", dimy: " << dimy; LogManager::getSingleton().logMessage(d.str());179 180 157 // loop through frame buffer and collect visible pixels 181 158 for (int idx = 0; idx < dimy * dimx * 3; idx += 3) … … 185 162 id += buf[idx + 1] << 8; 186 163 id += buf[idx + 2]; 187 188 //std::stringstream d; d << "myid: " << (int)buf[idx] << " " << (int)buf[idx + 1] << " " << (int)buf[idx + 2]; LogManager::getSingleton().logMessage(d.str());189 164 190 165 // if valid id <= add visibility (id values start at 1) -
GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreSceneContentGenerator.cpp
r2280 r2455 12 12 namespace Ogre { 13 13 14 15 14 16 /*************************************************************/ 15 17 /* SceneContentGenerator implementation */ … … 169 171 &mScale.x, &mScale.y, &mScale.z); 170 172 171 GenerateSceneObject(position, orientation, objName); 172 173 //std::stringstream d; d << StringConverter::toString(position) << " " << StringConverter::toString(orientation); 174 //LogManager::getSingleton().logMessage(d.str()); 175 } 173 GenerateSceneObject(position, orientation, objName); 174 } 175 176 176 ifstr.close(); 177 177 -
GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreSceneNodeHierarchyInterface.cpp
r2280 r2455 121 121 { 122 122 // only create renderable bounding box for new node 123 if (node != m SavedNode)123 if (node != mOldNode) 124 124 { 125 m SavedNode = node;125 mOldNode = node; 126 126 mBox = static_cast<SceneNode *>(node)->_getWorldAABB(); 127 127 } … … 151 151 { 152 152 Entity *ent = static_cast<Entity *>(movable); 153 //std::stringstream d; d << "ent " << ent->getName();154 //LogManager::getSingleton().logMessage(d.str());155 153 geometryList->push_back(ent); 156 154 } -
GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreSolidBoundingBox.cpp
r2184 r2455 71 71 /// Upload the index data to the card 72 72 ibuf->writeData(0, ibuf->getSizeInBytes(), faces, true); 73 //mRenderOp.useSharedVertices = true;74 73 mRenderOp.indexData->indexBuffer = ibuf; 75 74 // set material with no lighting, no color, no depth write 76 75 SetOcclusionQueryMaterial(); 77 //setMaterial("BaseWhiteNoLighting");78 79 /* std::stringstream d;80 d << "vtx: " << mRenderOp.vertexData;81 LogManager::getSingleton().logMessage(d.str());82 */83 84 76 } 85 77 //----------------------------------------------------------------------- -
GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreVisibilityOptionsManager.cpp
r2171 r2455 24 24 return true; 25 25 } 26 26 27 if (key == "Threshold") 27 28 { … … 36 37 if (key == "TestGeometryForVisibleLeaves") 37 38 { 38 m HierarchyInterface->TestGeometryForVisibleLeaves(*static_cast<const bool *>(val));39 mVisibilityManager->SetTestGeometryForVisibleLeaves(*static_cast<const bool *>(val)); 39 40 return true; 40 41 } … … 75 76 return true; 76 77 } 78 if (key == "TestGeometryForVisibleLeaves") 79 { 80 * static_cast<bool *>(val) = 81 mVisibilityManager->GetTestGeometryForVisibleLeaves(); 82 return true; 83 } 84 if (key == "AssumedVisibility") 85 { 86 * static_cast<unsigned int *>(val) = 87 mVisibilityManager->GetAssumedVisibilityForChc(); 88 return true; 89 } 90 if (key == "TestGeometryForVisibleLeaves") 91 { 92 * static_cast<unsigned int *>(val) = 93 mVisibilityManager->GetRandomUpdateCandidatesForRuc(); 94 return true; 95 } 77 96 78 97 return false; -
GTP/trunk/Lib/Vis/OnlineCullingCHC/include/CoherentHierarchicalCullingManager.h
r2332 r2455 21 21 22 22 void RenderScene(); 23 23 24 /** Sets assumed visibility (i.e., an estimation for 24 25 how many frames the visibility is considered to be valid). … … 27 28 if 0, the visibility is tested deterministically for each frame. 28 29 */ 29 void SetAssumedVisibility(const unsigned int assumedVisibility); 30 void SetAssumedVisibility(const unsigned int assumedVisibility); 31 /** This is an optimization when issuing the occlusion test. 32 The test is done with actual geometry rather than the bounding 33 box of leave nodes previously marked as visible. 34 35 @param testGeometry if this optimization should be used 36 @remark this option is only useful for the coherent hierarchical culling algorithm 37 */ 38 void SetTestGeometryForVisibleLeaves(const bool testGeometry); 39 /** See TestGeometryForVisibleLeaves 40 */ 41 bool GetTestGeometryForVisibleLeaves(); 42 30 43 31 44 protected: … … 47 60 bool NodeInvalid(HierarchyNode *node) const; 48 61 62 void AssignAssumedVisibility(GtpVisibility::HierarchyNode *node); 63 64 65 ////////////////////// 66 49 67 /** number of steps the visibility is assumed to be valid. 50 68 */ 51 69 unsigned int mAssumedVisibility; 52 70 53 /** Threshold for rand function to return positive result with respect to 54 mAssumedVisibility. 55 */ 56 int mThreshold; 71 bool mTestGeometryForVisibleLeaves; 57 72 }; 58 73 -
GTP/trunk/Lib/Vis/OnlineCullingCHC/include/CoherentHierarchicalCullingManager2.h
r2360 r2455 9 9 { 10 10 11 /** Renders the scene with the coherent hierarchical culling algorithm. 11 /** Renders the scene with the coherent hierarchical culling algorithm with 12 some additional features 12 13 */ 13 class CoherentHierarchicalCullingManager2 14 class CoherentHierarchicalCullingManager2: public CullingManager 14 15 { 15 16 public: 16 17 CoherentHierarchicalCullingManager2(); 18 17 19 /** Constructor taking the assumed visibility into account, i.e., the estimation 18 20 for how many frames the current visibility is considered to be valid … … 20 22 CoherentHierarchicalCullingManager2(const unsigned int assumedVisibility); 21 23 24 /** The main render routine. 25 */ 22 26 void RenderScene(); 27 23 28 /** Sets assumed visibility (i.e., an estimation for 24 29 how many frames the visibility is considered to be valid). … … 30 35 31 36 protected: 37 32 38 /** Decides if node is considered to be visible depeding on the 33 39 assumed visibility factor. … … 35 41 */ 36 42 bool DecideVisible(HierarchyNode *node) const; 37 38 43 39 44 /** Skip query for this node. -
GTP/trunk/Lib/Vis/OnlineCullingCHC/include/HierarchyInterface.h
r2332 r2455 2 2 #define _GtpVisibilityHierarchyInterface_H__ 3 3 4 4 5 #include "DistanceQueue.h" 5 //#include "VisibilityMesh.h"6 6 #include <stack> 7 7 8 8 9 namespace GtpVisibility { … … 52 53 /** Issue a occlusion query for this node. 53 54 @param node the current hierarchy node 54 @param wasVisible if the node was visible in the last frame: based 55 on this the method can decide on the way of querying 55 @param testGeometry (if geometry should be tested instead of the bb). 56 56 @returns occlusion query for this node 57 57 */ 58 58 virtual OcclusionQuery *IssueNodeOcclusionQuery(HierarchyNode *node, 59 const bool wasVisible= false) = 0;59 const bool testGeometry = false) = 0; 60 60 /** Returns distance of the node to the view plane. 61 61 @param node the hierarchy node … … 119 119 */ 120 120 HierarchyNode *GetHierarchyRoot() const; 121 122 /** This is an optimization when issuing the occlusion test.123 The test is done with actual geometry rather than the bounding124 box of leave nodes previously marked as visible.125 126 @param testGeometry if this optimization should be used127 @remark this option is only useful for the coherent hierarchical culling algorithm128 */129 void TestGeometryForVisibleLeaves(bool testGeometry);130 131 121 /** Sets the scene root and initialises this hierarchy interface for a traversal. 132 122 @remark also resets the statistics evaluated in the last traversal … … 142 132 */ 143 133 DistanceQueue *GetQueue(); 144 145 134 /** Checks if the node is visible from the current view frustum. 146 135 @param node the current node 147 136 */ 148 137 bool CheckFrustumVisible(HierarchyNode *node); 149 150 138 /** Returns number of traversed nodes. 151 139 */ … … 154 142 */ 155 143 unsigned int GetNumRenderedNodes(); 156 157 144 /** Returns vector of visible hierarchy nodes from previous render. 158 145 */ 159 146 std::vector<HierarchyNode *> *GetVisibleNodes(); 160 147 /** Pulls up the last visited information of this node. 148 */ 161 149 virtual void PullUpLastVisited(HierarchyNode *node, const int frameId) const = 0; 162 virtual void DetermineVisibilityRatio(HierarchyNode *node) const = 0; 163 virtual float GetNodeVisibilityRatio(HierarchyNode *node) const = 0; 164 150 /** Returns parent node. 151 */ 165 152 virtual HierarchyNode *GetParent(HierarchyNode *node) = 0; 153 /** Returns #frames this node is assumed to be visible. 154 */ 155 virtual int GetNodeAssumedVisible(HierarchyNode *node) = 0; 156 /** Sets #frames this node is assumed to be visible. 157 */ 158 virtual void SetNodeAssumedVisible(HierarchyNode *node, int assumedVisible) = 0; 159 /** Decreases #frames this node is assumed to be visible. 160 */ 161 virtual void DecNodeAssumedVisible(HierarchyNode *node) = 0; 166 162 167 163 protected: 168 164 169 170 /// chc optimization for testing geometry of leaves instead of bounding box171 bool mTestGeometryForVisibleLeaves;172 165 /// the current frame number 173 166 unsigned int mFrameId; 167 174 168 /// index of the lcurrent occlusion query in the array of queries 175 169 /// NOTE: should rather be iterator … … 186 180 187 181 /// buffer for a node pointer 188 HierarchyNode *m SavedNode;182 HierarchyNode *mOldNode; 189 183 190 184 /// list of rendered hierarchy nodes (e.g., useful for exact visibility queries) 191 185 std::vector<HierarchyNode *> mVisibleNodes; 192 186 }; 187 193 188 } // namespace GtpVisibility 194 189 -
GTP/trunk/Lib/Vis/OnlineCullingCHC/include/RandomUpdateCullingManager.h
r2259 r2455 14 14 { 15 15 public: 16 16 17 RandomUpdateCullingManager(); 17 /** Constructor taking the assumed visibility into account, i.e., the estimation 18 for how many frames the current visibility is considered to be valid18 19 /** Constructor taking the #random candidates tested per subtree into account. 19 20 */ 20 RandomUpdateCullingManager(const unsigned int assumedVisibility);21 RandomUpdateCullingManager(const unsigned int randomCandidates); 21 22 22 23 void RenderScene(); 23 /** Sets assumed visibility (i.e., an estimation for 24 how many frames the visibility is considered to be valid). 25 @param assumedVisibility indicates for how many frames the 26 same visibility is be assumed. 27 if 0, the visibility is tested deterministically for each frame. 24 25 /** Sets #random candidates tested per subtree. 28 26 */ 29 void SetAssumedVisibility(const unsigned int assumedVisibility); 27 void SetRandomCandidates(const unsigned int randomCandidates); 28 29 /** This is an optimization when issuing the occlusion test. 30 The test is done with actual geometry rather than the bounding 31 box of leave nodes previously marked as visible. 32 33 @param testGeometry if this optimization should be used 34 @remark this option is only useful for the coherent hierarchical culling algorithm 35 */ 36 void SetTestGeometryForVisibleLeaves(const bool testGeometry); 37 /** See TestGeometryForVisibleLeaves 38 */ 39 bool GetTestGeometryForVisibleLeaves(); 30 40 31 41 protected: 32 33 /** Decides if node is considered to be visible depeding on the34 assumed visibility factor.35 @returns if node is considered to be visible36 */37 bool DecideVisible(HierarchyNode *node) const;38 42 39 43 /** Skip query for this node. … … 41 45 void SkipQuery(HierarchyNode *node) const; 42 46 43 /** number of steps the visibility is assumed to be valid.44 */45 unsigned int mAssumedVisibility;46 47 47 /** Threshold for rand function to return positive result 48 with respect to mAssumedVisibility. 49 */ 50 int mThreshold; 48 //////////// 51 49 52 int mRandomCandidates; 50 /// number of candidates that are tested per subtree 51 unsigned int mRandomCandidates; 52 53 bool mTestGeometryForVisibleLeaves; 54 53 55 }; 54 56 -
GTP/trunk/Lib/Vis/OnlineCullingCHC/include/VisibilityManager.h
r2280 r2455 58 58 */ 59 59 void SetAssumedVisibilityForChc(unsigned int assumedVisibility); 60 60 /** Random candidates per subtree for random update manager. 61 @note these options should rather be given by general parameter system using void * 62 and strings. 63 */ 64 void SetRandomUpdateCandidatesForRuc(unsigned int randomCandidatesForRuc); 65 /** See get 66 */ 67 unsigned int GetAssumedVisibilityForChc(); 68 /* See get 69 */ 70 unsigned int GetRandomUpdateCandidatesForRuc(); 61 71 /** Sets pointer to a query manager. 62 72 */ … … 66 76 QueryManager *GetQueryManager(); 67 77 78 void SetTestGeometryForVisibleLeaves(bool testGeometryForLeaves); 79 bool GetTestGeometryForVisibleLeaves(); 80 81 /** Returns the visibility environment. 82 */ 68 83 VisibilityEnvironment *GetVisibilityEnvironment(); 69 84 … … 73 88 CullingManager *mCullingManager; 74 89 QueryManager *mQueryManager; 90 75 91 PreprocessingManager *mPreprocessingManager; 76 92 VisibilityEnvironment *mVisibilityEnvironment; … … 79 95 unsigned int mVisibilityThreshold; 80 96 unsigned int mAssumedVisibilityForChc; 97 unsigned int mRandomCandidatesForRuc; 98 99 bool mTestGeometryForVisibleLeaves; 81 100 }; 101 82 102 } // namespace GtpVisibility 83 103 -
GTP/trunk/Lib/Vis/OnlineCullingCHC/scripts/terrainCulling.cfg
r2360 r2455 52 52 ResetMaterialForQueries=no 53 53 54 55 # Occlusion query is issued by rendering geometry itself instead of the bounding box 56 # because have to render geometry for previously visible leaves anyway 57 58 TestGeometryForVisibleLeaves=no 59 60 61 # For CHC: frames a node is assumed to stay visible 62 63 AssumedVisibleFrames=10 64 65 66 # only for random update manager: the #random candidates that 67 # are tested per visible subtree 68 69 RandomUpdateCandidates=2 70 71 # true if we want to tests the bounds of the geometry 72 # instead of the boudning box of the hierarchy node 73 74 TestGeometryBounds=no 54 75 55 76 -
GTP/trunk/Lib/Vis/OnlineCullingCHC/src/CoherentHierarchicalCullingManager.cpp
r2452 r2455 3 3 4 4 #include <time.h> 5 #include <sstream> 6 5 7 6 8 namespace GtpVisibility { 7 9 8 //----------------------------------------------------------------------- 9 CoherentHierarchicalCullingManager::CoherentHierarchicalCullingManager() 10 { 11 SetAssumedVisibility(0); 12 // initialise random generator in case we use assumed visibility 13 //srand(time(NULL)); 10 11 static int batchSize = 5; 12 13 //----------------------------------------------------------------------- 14 CoherentHierarchicalCullingManager::CoherentHierarchicalCullingManager(): 15 mAssumedVisibility(0) 16 { 14 17 } 15 18 //----------------------------------------------------------------------- 16 19 CoherentHierarchicalCullingManager::CoherentHierarchicalCullingManager( 17 const unsigned int assumedVisibility) 18 { 19 SetAssumedVisibility(assumedVisibility); 20 // initialise random generator in case we use assumed visibility 21 //srand(time(NULL)); 20 const unsigned int assumedVisibility): 21 mAssumedVisibility(assumedVisibility) 22 { 23 } 24 //----------------------------------------------------------------------- 25 void CoherentHierarchicalCullingManager::AssignAssumedVisibility(GtpVisibility::HierarchyNode *node) 26 { 27 if (!mHierarchyInterface->IsNodeVisible(node)) 28 // previously invisible nodes: give random offset just for the first test after 29 // becoming visible to avoid that all nodes are tested in the same frame 30 mHierarchyInterface->SetNodeAssumedVisible(node, rand() * mAssumedVisibility / RAND_MAX); 31 else 32 mHierarchyInterface->SetNodeAssumedVisible(node, mAssumedVisibility); 22 33 } 23 34 //----------------------------------------------------------------------- … … 35 46 ////////// 36 47 //-- only wait for result if there are no nodes to process 48 37 49 while (!queryQueue.empty() && 38 50 (NodeInvalid(queryQueue.front().first) || … … 43 55 queryQueue.pop(); 44 56 57 // "invalid nodes" happen for hierarchies that have geometry 58 // not neccessarily in the leaves: 45 59 // parent was tested invisible => remove children from queue 46 if (NodeInvalid(node)) 47 { 48 //CullingLogManager::GetSingleton()->LogMessage("skipping this node"); 60 61 if (1 && NodeInvalid(node)) 49 62 continue; 50 } 63 51 64 // tested visible 52 65 if (visiblePixels > mVisibilityThreshold) 53 66 { 54 // in case geometry is in interior node: ensure that we only traverse once 67 // assing the #frames the node is assumed to stay visible 68 AssignAssumedVisibility(node); 69 70 // for previously visible interior node which contains geometry: 71 // ensure that we did not already traverse this node 72 // (which means that the visibility flag is set) 55 73 if (!mHierarchyInterface->IsNodeVisible(node)) 56 {57 74 mHierarchyInterface->TraverseNode(node); 58 }59 75 60 76 mHierarchyInterface->PullUpVisibility(node); … … 65 81 66 82 ++ mNumQueryCulledNodes; 67 83 68 84 if (mVisualizeCulledNodes) 69 {70 85 mHierarchyInterface->VisualizeCulledNode(node, QUERY_CULLED); 71 }72 86 } 73 87 … … 76 90 } 77 91 92 //////////////// 78 93 //-- PART 2: hierarchical traversal 94 79 95 if (!mHierarchyInterface->GetQueue()->empty()) 80 96 { … … 83 99 84 100 // parent was tested invisible => remove children from queue 85 if (NodeInvalid(node)) 86 { 87 //CullingLogManager::GetSingleton()->LogMessage("skipping this node"); 101 if (1 && NodeInvalid(node)) 88 102 continue; 89 }90 103 91 104 bool intersects = false; … … 96 109 97 110 if (mVisualizeCulledNodes) 98 {99 111 mHierarchyInterface->VisualizeCulledNode(node, FRUSTUM_CULLED); 100 }101 112 } 102 113 //-- if node intersects near plane, skip query because wrong results possible … … 112 123 113 124 // if we assume node to be visible in this frame => skip query 114 const bool skipQuery = wasVisible && 115 (mAssumedVisibility > 0) && 125 const bool skipQuery = wasVisible && 116 126 DecideVisible(node) && 117 127 mHierarchyInterface->HasGeometry(node); … … 127 137 bool issueQuery = !wasVisible || mHierarchyInterface->HasGeometry(node); 128 138 129 // reset node's visibility classification130 // set visible if geometry in node so we only traverse once139 // set node's visibility classification 140 // we identify previously visible / invisible nodes in the query queue 131 141 mHierarchyInterface->SetNodeVisible(node, wasVisible && issueQuery); 132 142 133 // skip testing previously visible nodes without geometry134 143 if (issueQuery) 135 144 { 136 145 ++ mNumQueriesIssued; 137 146 147 const bool testGeometry = wasVisible && mHierarchyInterface->IsLeaf(node) && mTestGeometryForVisibleLeaves; 148 138 149 queryQueue.push(QueryPair(node, mHierarchyInterface-> 139 IssueNodeOcclusionQuery(node, wasVisible)));150 IssueNodeOcclusionQuery(node, testGeometry))); 140 151 } 141 152 else 142 153 { 143 // update node's visited flag 154 // skip testing previously visible nodes without geometry 155 // just update node's visited flag 144 156 mHierarchyInterface->SetLastVisited(node, mHierarchyInterface->GetFrameId()); 145 157 } … … 158 170 { 159 171 mAssumedVisibility = assumedVisibility; 160 161 if (!mAssumedVisibility)162 {163 mThreshold = 0;164 }165 else166 {167 mThreshold = RAND_MAX - RAND_MAX / mAssumedVisibility;168 // fix visibility169 if (mAssumedVisibility > 100)170 mThreshold = RAND_MAX;171 }172 173 172 } 174 173 //----------------------------------------------------------------------- 175 174 inline bool CoherentHierarchicalCullingManager::DecideVisible(HierarchyNode *node) const 176 175 { 177 return rand() < mThreshold; 176 mHierarchyInterface->DecNodeAssumedVisible(node); 177 //std::stringstream d; d << "node visible: " << mHierarchyInterface->GetNodeAssumedVisible(node); 178 //CullingLogManager::GetSingleton()->LogMessage(d.str()); 179 return mHierarchyInterface->GetNodeAssumedVisible(node) > 0; 178 180 } 179 181 //----------------------------------------------------------------------- … … 196 198 !mHierarchyInterface->IsNodeVisible(parent); 197 199 } 198 } // namespace GtpVisibility 200 //----------------------------------------------------------------------- 201 void CoherentHierarchicalCullingManager::SetTestGeometryForVisibleLeaves(const bool testGeometry) 202 { 203 mTestGeometryForVisibleLeaves = testGeometry; 204 } 205 //----------------------------------------------------------------------- 206 bool CoherentHierarchicalCullingManager::GetTestGeometryForVisibleLeaves() 207 { 208 return mTestGeometryForVisibleLeaves; 209 } 210 211 } -
GTP/trunk/Lib/Vis/OnlineCullingCHC/src/GtpVisibility.vcproj
r2360 r2455 259 259 </File> 260 260 <File 261 RelativePath=".\CoherentHierarchicalCullingManager2.cpp">262 </File>263 <File264 261 RelativePath=".\CullingLogManager.cpp"> 265 262 </File> -
GTP/trunk/Lib/Vis/OnlineCullingCHC/src/HierarchyInterface.cpp
r2306 r2455 10 10 mNumTraversedNodes(0), 11 11 mHierarchyRoot(NULL), 12 mSavedNode(NULL), 13 mCurrentTestIdx(0), 14 mTestGeometryForVisibleLeaves(false) 12 mOldNode(NULL), 13 mCurrentTestIdx(0) 15 14 { 16 15 mDistanceQueue = new DistanceQueue(GtDistance<HierarchyNode *>(this)); … … 72 71 } 73 72 //----------------------------------------------------------------------- 74 void HierarchyInterface::TestGeometryForVisibleLeaves(bool testGeometry)75 {76 mTestGeometryForVisibleLeaves = testGeometry;77 }78 //-----------------------------------------------------------------------79 73 std::vector<HierarchyNode *> *HierarchyInterface::GetVisibleNodes() 80 74 { -
GTP/trunk/Lib/Vis/OnlineCullingCHC/src/RandomUpdateCullingManager.cpp
r2332 r2455 13 13 14 14 const static int R_CANDIDATES = 1; 15 //----------------------------------------------------------------------- 16 RandomUpdateCullingManager::RandomUpdateCullingManager() 17 { 18 SetAssumedVisibility(0); 19 // initialise random generator in case we use assumed visibility 20 //srand(time(NULL)); 21 22 mRandomCandidates = R_CANDIDATES; 23 } 24 //----------------------------------------------------------------------- 25 RandomUpdateCullingManager::RandomUpdateCullingManager( 26 const unsigned int assumedVisibility) 27 { 28 SetAssumedVisibility(assumedVisibility); 29 // initialise random generator in case we use assumed visibility 30 //srand(time(NULL)); 31 32 mRandomCandidates = R_CANDIDATES; 15 16 //----------------------------------------------------------------------- 17 RandomUpdateCullingManager::RandomUpdateCullingManager(): mRandomCandidates(R_CANDIDATES) 18 { 19 } 20 //----------------------------------------------------------------------- 21 RandomUpdateCullingManager::RandomUpdateCullingManager(const unsigned int randomCandidates) 22 { 23 mRandomCandidates = std::max(randomCandidates, (unsigned int)1); 24 } 25 //----------------------------------------------------------------------- 26 void RandomUpdateCullingManager::SetRandomCandidates(const unsigned int randomCandidates) 27 { 28 mRandomCandidates = std::max(randomCandidates, (unsigned int)1); 33 29 } 34 30 //----------------------------------------------------------------------- … … 105 101 else 106 102 { 107 103 // fully visible subtree => render all in one bathc 108 104 if (mHierarchyInterface->IsNodeFullyVisible(node)) 109 105 { 110 #if 1 111 // node fully visible => test only random leaves 112 for (int i = 0; i < mRandomCandidates; ++ i) 113 { 114 HierarchyNode *randomLeaf = mHierarchyInterface->GetRandomLeaf(node); 115 116 if (!randomLeaf) 117 continue; 118 119 mHierarchyInterface->SetNodeVisible(randomLeaf, false); 120 121 // update node's visited flag 122 mHierarchyInterface->PullUpLastVisited(randomLeaf, mHierarchyInterface->GetFrameId()); 123 124 queryQueue.push(QueryPair(randomLeaf, 125 mHierarchyInterface->IssueNodeOcclusionQuery(node))); 126 } 127 #else 128 // test all leaves for visibility changes 106 // use different algorithm for finding random candidates 129 107 HierarchyNodeContainer mynodes; 130 108 mHierarchyInterface->CollectLeaves(node, mynodes); 131 109 110 const int p = mRandomCandidates * RAND_MAX / (int)mynodes.size(); 111 132 112 HierarchyNodeContainer::const_iterator nit, nit_end = mynodes.end(); 133 113 114 int nodesTested = 0; 134 115 for (nit = mynodes.begin(); nit != nit_end; ++ nit) 135 116 { 136 117 HierarchyNode *leaf = *nit; 118 119 if (rand() > p) 120 continue; 121 122 ++ nodesTested; 123 137 124 mHierarchyInterface->SetNodeVisible(leaf, false); 138 125 … … 140 127 mHierarchyInterface->PullUpLastVisited(leaf, mHierarchyInterface->GetFrameId()); 141 128 142 queryQueue.push(QueryPair(leaf, 143 mHierarchyInterface->IssueNodeOcclusionQuery(node))); 129 const bool testGeometry =mTestGeometryForVisibleLeaves; 130 131 mHierarchyInterface->IssueNodeOcclusionQuery(node, mTestGeometryForVisibleLeaves); 144 132 } 145 #endif 133 134 //std::stringstream d; d << "rc: " << mRandomCandidates << " tested: " << nodesTested << " of " << (int)mynodes.size(); 135 //CullingLogManager::GetSingleton()->LogMessage(d.str()); 136 146 137 mHierarchyInterface->RenderNodeRecursive(node); 147 148 138 continue; 149 139 } … … 153 143 (mHierarchyInterface->LastVisited(node) == mHierarchyInterface->GetFrameId() - 1); 154 144 155 156 145 // if we assume node to be visible in this frame => skip query 157 const bool skipQuery = wasVisible && (mAssumedVisibility > 0) && 158 DecideVisible(node) && mHierarchyInterface->HasGeometry(node); 146 const bool skipQuery = false;//wasVisible && mHierarchyInterface->HasGeometry(node); 159 147 160 148 if (skipQuery) … … 181 169 ++ mNumQueriesIssued; 182 170 171 const bool testGeometry = wasVisible && mHierarchyInterface->IsLeaf(node) && mTestGeometryForVisibleLeaves; 172 183 173 queryQueue.push(QueryPair(node, mHierarchyInterface-> 184 IssueNodeOcclusionQuery(node, wasVisible)));174 IssueNodeOcclusionQuery(node, testGeometry))); 185 175 } 186 176 … … 196 186 // update the fully visible classifications 197 187 mHierarchyInterface->DetermineFullVisibility(mHierarchyInterface->GetHierarchyRoot()); 198 //mHierarchyInterface->DetermineVisibilityRatio(mHierarchyInterface->GetHierarchyRoot());199 }200 //-----------------------------------------------------------------------201 void RandomUpdateCullingManager::SetAssumedVisibility(const unsigned int assumedVisibility)202 {203 mAssumedVisibility = assumedVisibility;204 205 mThreshold = 0;206 207 if (mAssumedVisibility > 0)208 {209 mThreshold = RAND_MAX - RAND_MAX / mAssumedVisibility;210 if (mAssumedVisibility > 100) // no random decicion211 mThreshold = RAND_MAX;212 }213 214 }215 //-----------------------------------------------------------------------216 inline bool RandomUpdateCullingManager::DecideVisible(HierarchyNode *node) const217 {218 return rand() < mThreshold;219 188 } 220 189 //----------------------------------------------------------------------- … … 227 196 mHierarchyInterface->TraverseNode(node); 228 197 } 198 //----------------------------------------------------------------------- 199 void RandomUpdateCullingManager::SetTestGeometryForVisibleLeaves(const bool testGeometry) 200 { 201 mTestGeometryForVisibleLeaves = testGeometry; 202 } 203 //----------------------------------------------------------------------- 204 bool RandomUpdateCullingManager::GetTestGeometryForVisibleLeaves() 205 { 206 return mTestGeometryForVisibleLeaves; 207 } 229 208 230 209 } // namespace GtpVisibility -
GTP/trunk/Lib/Vis/OnlineCullingCHC/src/StopAndWaitCullingManager.cpp
r2292 r2455 45 45 { 46 46 ++ mNumQueriesIssued; 47 48 47 unsigned int visiblePixels = 0; 49 50 mHierarchyInterface->IssueNodeOcclusionQuery(node)->GetQueryResult(visiblePixels, true);48 const bool waitForResult = true; 49 mHierarchyInterface->IssueNodeOcclusionQuery(node)->GetQueryResult(visiblePixels, waitForResult); 51 50 52 51 // node visible -
GTP/trunk/Lib/Vis/OnlineCullingCHC/src/VisibilityManager.cpp
r2289 r2455 45 45 // delete old culling manager 46 46 if (mCullingManager) 47 {48 47 delete mCullingManager; 49 }50 48 51 49 mCullingManagerType = ocmType; … … 54 52 { 55 53 case VisibilityEnvironment::COHERENT_HIERARCHICAL_CULLING: 56 mCullingManager = new CoherentHierarchicalCullingManager(mAssumedVisibilityForChc); 54 { 55 CoherentHierarchicalCullingManager *chcm = new CoherentHierarchicalCullingManager(mAssumedVisibilityForChc); 56 chcm->SetTestGeometryForVisibleLeaves(mTestGeometryForVisibleLeaves); 57 mCullingManager = chcm; 58 } 57 59 break; 58 59 60 case VisibilityEnvironment::FRUSTUM_CULLING: 60 61 mCullingManager = new FrustumCullingManager(); 61 62 break; 62 63 63 case VisibilityEnvironment::RANDOM_UPDATE_CULLING: 64 mCullingManager = new RandomUpdateCullingManager(); 64 { 65 RandomUpdateCullingManager *rum = new RandomUpdateCullingManager(mRandomCandidatesForRuc); 66 rum->SetTestGeometryForVisibleLeaves(mTestGeometryForVisibleLeaves); 67 mCullingManager = rum; 68 } 65 69 break; 66 67 70 case VisibilityEnvironment::STOP_AND_WAIT_CULLING: 68 71 mCullingManager = new StopAndWaitCullingManager(); 69 //mCullingManager = new RandomUpdateCullingManager();70 72 break; 71 72 73 default: 73 74 mCullingManager = new CoherentHierarchicalCullingManager(mAssumedVisibilityForChc); 74 75 break; 75 76 76 } 77 77 78 78 ///////// 79 79 //-- set threshold 80 80 81 mCullingManager->SetVisibilityThreshold(mVisibilityThreshold); 81 82 } … … 113 114 } 114 115 //----------------------------------------------------------------------- 115 void VisibilityManager::SetAssumedVisibilityForChc(unsigned int assumedVisibility) 116 116 void VisibilityManager::SetAssumedVisibilityForChc(unsigned int assumedVisibility) 117 117 { 118 118 mAssumedVisibilityForChc = assumedVisibility; 119 119 120 // in case we currently use chc 121 if (VisibilityManager::GetCullingManagerType() == 122 VisibilityEnvironment::COHERENT_HIERARCHICAL_CULLING) 120 if (mCullingManagerType == VisibilityEnvironment::COHERENT_HIERARCHICAL_CULLING) 123 121 { 124 122 static_cast<CoherentHierarchicalCullingManager *>(mCullingManager)-> 125 SetAssumedVisibility(assumedVisibility); 123 SetAssumedVisibility(mAssumedVisibilityForChc); 124 } 125 } 126 //----------------------------------------------------------------------- 127 void VisibilityManager::SetRandomUpdateCandidatesForRuc(unsigned int randomCandidates) 128 { 129 mRandomCandidatesForRuc = randomCandidates; 130 131 if (mCullingManagerType == VisibilityEnvironment::RANDOM_UPDATE_CULLING) 132 { 133 static_cast<RandomUpdateCullingManager *>(mCullingManager)-> 134 SetRandomCandidates(mRandomCandidatesForRuc); 126 135 } 127 136 } … … 131 140 return mVisibilityEnvironment; 132 141 } 142 //----------------------------------------------------------------------- 143 unsigned int VisibilityManager::GetAssumedVisibilityForChc() 144 { 145 return mAssumedVisibilityForChc; 146 } 147 //----------------------------------------------------------------------- 148 unsigned int VisibilityManager::GetRandomUpdateCandidatesForRuc() 149 { 150 return mRandomCandidatesForRuc; 151 } 152 //----------------------------------------------------------------------- 153 void VisibilityManager::SetTestGeometryForVisibleLeaves(bool testGeometryForVisibleLeaves) 154 { 155 mTestGeometryForVisibleLeaves = testGeometryForVisibleLeaves; 156 157 if (mCullingManagerType == VisibilityEnvironment::COHERENT_HIERARCHICAL_CULLING) 158 { 159 static_cast<CoherentHierarchicalCullingManager *>(mCullingManager)-> 160 SetTestGeometryForVisibleLeaves(mTestGeometryForVisibleLeaves); 161 } 162 else if (mCullingManagerType == VisibilityEnvironment::RANDOM_UPDATE_CULLING) 163 { 164 static_cast<RandomUpdateCullingManager *>(mCullingManager)-> 165 SetTestGeometryForVisibleLeaves(mTestGeometryForVisibleLeaves); 166 } 167 } 168 //----------------------------------------------------------------------- 169 bool VisibilityManager::GetTestGeometryForVisibleLeaves() 170 { 171 return mTestGeometryForVisibleLeaves; 172 } 133 173 134 174 } // namespace GtpVisibility
Note: See TracChangeset
for help on using the changeset viewer.