- Timestamp:
- 01/09/09 02:16:38 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling
- Files:
-
- 2 added
- 18 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj
r3258 r3259 160 160 > 161 161 <File 162 RelativePath=".\src\BvhExporter.cpp" 163 > 164 </File> 165 <File 166 RelativePath=".\src\BvhExporter.h" 167 > 168 </File> 169 <File 162 170 RelativePath=".\src\BvhLoader.cpp" 163 171 > -
GTP/trunk/App/Demos/Vis/FriendlyCulling/default.env
r3258 r3259 99 99 100 100 # use full resolution ssao (vs. half resoltion) 101 ssaoUseFullResolution= 1101 ssaoUseFullResolution=0 102 102 # ssao kernel radius 103 103 #ssaoKernelRadius=8e-1f … … 115 115 ## powerplant options 116 116 117 #filename=PowerPlantM 118 119 #keyForwardMotion=500.0f 120 #mouseMotion=3.0f 121 #visibilitySolution=power-plant-2c-xx-1000b-pgv2 122 #camPosition=-1320.57 -6306.34 3603 123 #camDirection=0.292156 0.9556 0.0383878 124 #viewCellsScaleFactor=0.05f 117 filename=PowerPlantM 118 keyForwardMotion=500.0f 119 mouseMotion=3.0f 120 visibilitySolution=power-plant-2c-xx-1000b-pgv2 121 camPosition=-1320.57 -6306.34 3603 122 camDirection=0.292156 0.9556 0.0383878 123 viewCellsScaleFactor=0.05f -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.cpp
r3245 r3259 327 327 328 328 329 int Bvh::CountNumNodes(BvhNode *node) const 330 { 331 int numNodes = 0; 332 333 stack<BvhNode *> tStack; 334 335 tStack.push(node); 336 337 while (!tStack.empty()) 338 { 339 BvhNode *node = tStack.top(); 340 tStack.pop(); 341 342 ++ numNodes; 343 344 if (!node->IsLeaf()) 345 { 346 BvhInterior *interior = static_cast<BvhInterior *>(node); 347 348 tStack.push(interior->mFront); 349 tStack.push(interior->mBack); 350 } 351 } 352 353 return numNodes; 354 } 355 356 329 357 void Bvh::CollectNodes(BvhNode *node, BvhNodeContainer &nodes) 330 358 { … … 770 798 static BvhNodeContainer nodes; 771 799 nodes.clear(); 772 //nodes.reserve(GetNumNodes()); 800 773 801 CollectNodes(mDynamicRoot, nodes); 774 802 … … 1528 1556 mDynamicRoot->mParent = mRoot; 1529 1557 } 1530 1531 1532 } 1558 1559 1560 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.h
r3243 r3259 30 30 friend class Bvh; 31 31 friend class BvhLoader; 32 friend class BvhExporter; 32 33 friend class mygreaterdistance; 33 34 … … 422 423 friend class Bvh; 423 424 friend class BvhLoader; 425 friend class BvhExporter; 424 426 425 427 public: … … 474 476 }; 475 477 478 476 479 typedef std::priority_queue<BvhNode *, std::vector<BvhNode *>, GtDistance> TraversalQueue; 477 480 … … 482 485 { 483 486 friend class BvhLoader; 487 friend class BvhExporter; 484 488 485 489 /** Bvh properties … … 524 528 */ 525 529 inline int GetNumNodes() const; 530 /** Counts the number of bvh nodes under this node 531 */ 532 int CountNumNodes(BvhNode *node) const; 526 533 /** Returns number of bvh leaves. 527 534 */ … … 557 564 */ 558 565 void CollectNodes(BvhNode *node, BvhNodeContainer &nodes, int depth); 566 /** Collect all child nodes. 567 */ 559 568 void CollectNodes(BvhNode *node, BvhNodeContainer &nodes); 560 569 /** Collect the "physical" leaves of the hierarchy … … 614 623 */ 615 624 void ResetNodeClassifications(); 616 /** Count triangles the node contains.625 /** Counts the number of triangles contained in this node. 617 626 */ 618 627 int CountTriangles(BvhNode *node) const; … … 654 663 //////////////////////////// 655 664 656 /** Returns stat s.665 /** Returns statistics. 657 666 */ 658 667 const BvhStats &GetBvhStats() const { return mBvhStats; } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/CHCPlusPlusTraverser.cpp
r3258 r3259 119 119 mDistanceQueue.pop(); 120 120 121 if (1 && !IsNodeGeometryVisible(node, 10)) 122 { 121 if (!IsNodeGeometryVisible(node, 10)) 122 { 123 node->SetLastVisitedFrame(mFrameId); 123 124 node->SetVisible(false); 125 126 mBvh->MakeParentsVisible(node); 127 124 128 continue; 125 129 } … … 148 152 149 153 // node was not recently tested => reset flag 150 if (node->GetLastVisitedFrame() != mFrameId - 1)154 if (node->GetLastVisitedFrame() != (mFrameId - 1)) 151 155 { 152 156 node->SetTimesTestedInvisible(0); … … 259 263 // node was already part of a mulitquery => avoid recursion 260 264 if (node->GetLastQueriedFrame() == mFrameId) 265 { 261 266 newPBatch = 0; 267 } 262 268 else 269 { 263 270 newPBatch *= mVisibilityPredictor.GetProbability(node); 271 } 264 272 265 273 if (query->GetNodes().empty()) … … 274 282 } 275 283 276 if (newBatchVal <= maxBatchVal) 277 break; 284 if (newBatchVal <= maxBatchVal) break; 278 285 279 286 iqueue.pop_back(); … … 304 311 305 312 while (!mIQueue.empty()) 313 { 306 314 mQueryQueue.push(GetNextMultiQuery(mIQueue)); 315 } 307 316 } 308 317 else … … 311 320 312 321 for (it = mIQueue.begin(); it != it_end; ++ it) 322 { 313 323 mQueryQueue.push(IssueOcclusionQuery(*it)); 324 } 314 325 315 326 mIQueue.clear(); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Geometry.cpp
r3154 r3259 218 218 219 219 220 } 220 Vector3 *Geometry::GetVertices(int &numVertices) const 221 { 222 numVertices = mNumVertices; 223 return mVertices; 224 } 225 226 227 Vector3 *Geometry::GetNormals(int &numNormals) const 228 { 229 numNormals = mNumVertices; 230 return mNormals; 231 } 232 233 234 Vector3 *Geometry::GetTangents(int &numTangents) const 235 { 236 numTangents = mHasTangents ? mNumVertices : 0;; 237 return mTangents; 238 } 239 240 241 Texcoord2 *Geometry::GetTexCoords(int &numTexCoords) const 242 { 243 numTexCoords = mHasTangents ? mNumVertices : 0;; 244 return mTexCoords; 245 } 246 247 248 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Geometry.h
r3126 r3259 18 18 { 19 19 friend class ResourceManager; 20 friend class EntityMerger;21 20 22 21 public: … … 30 29 Texcoord2 *texcoords, 31 30 int numVertices, 32 bool del Data,31 bool deleteData, 33 32 Vector3 *tangents); 34 33 /** Detructor destroying the opengl resources. … … 48 47 inline bool HasTexture() const { return mHasTexture; } 49 48 49 50 ////////////// 51 //-- these functions return the specified data 52 //-- only if deleteData has not been switched on in the consruction 53 54 Vector3 *GetVertices(int &numVertices) const; 55 56 Vector3 *GetNormals(int &numNormals) const; 57 58 Vector3 *GetTangents(int &numTangents) const; 59 60 Texcoord2 *GetTexCoords(int &numTexCoords) const; 61 50 62 51 63 protected: -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Pvs.cpp
r3242 r3259 1 1 #include "Pvs.h" 2 2 #include "Timer/PerfTimer.h" 3 #include "common.h"4 3 #include <iostream> 5 4 … … 8 7 { 9 8 10 void TestPvsPerformance() 11 { 12 // Pvs pvs(15000); 13 const int prange=10000; 14 Pvs pvs[prange+1]; 15 // test PVS performance 16 const int num = 100000000; 17 const int range = 50000; 18 PerfTimer timer; 19 timer.Entry(); 20 21 for (int i=0; i < num; i++) 22 { 23 int id = (int)Random(range); 24 int pid = (5*num)%prange; 25 pvs[pid].Insert(id, (float)i); 26 if (i%1000000 == 0) { 27 cout<<i/1000000<<" M"<<endl; 28 cout<<"size = "<<pvs[pid].GetSize()/(1000*1000)<<"M"<<endl; 29 // cout << "bucket_count: " << pvs.entries.bucket_count() << endl; 30 } 31 } 32 timer.Exit(); 9 void Pvs::Clear() 10 { 11 mEntries.clear(); 12 } 33 13 34 14 35 cout<<"Pvs insert speed = "<<num/float(1000*1000*timer.TotalTime())<< 36 "M entries/s\n"; 37 cout<<"Memory usage "<<pvs[0].GetMemoryUsage()<<" bytes"<<endl; 38 39 int counter = 0; 40 timer.Entry(); 41 PvsIterator it(pvs[0]); 42 for (; it.HasMoreEntries(); it.Next()) 43 { 44 ++ counter; 45 } 46 timer.Exit(); 47 48 cout<<"Pvs count = "<<counter<<endl; 49 cout<<"Pvs iteration speed = "<<pvs[0].GetSize()/float(1000*1000*timer.TotalTime())<< 50 "M entries/s\n"; 51 52 counter = 0; 53 timer.Entry(); 54 PvsTimeIterator tit(pvs[0], 400); 55 for (; tit.HasMoreEntries(); tit.Next()) { 56 counter++; 57 } 58 timer.Exit(); 59 cout<<"Pvs time count = "<<counter<<endl; 60 cout<<"Pvs iteration speed = "<<pvs[0].GetSize()/(1024*1024*timer.TotalTime())<< 61 "M entries/s\n"; 15 bool Pvs::Empty() const 16 { 17 return mEntries.empty(); 62 18 } 63 19 20 21 64 22 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Pvs.h
r3243 r3259 3 3 4 4 #include "common.h" 5 5 #include "Bvh.h" 6 6 7 7 namespace CHCDemoEngine 8 8 { 9 9 10 /** Template class representing the Potentially Visible Set (PVS) 11 mainly from a view cell, but also e.g., from objects. 10 class BvhNode; 11 class Bvh; 12 13 14 /** Class representing the Potentially Visible Set (PVS) from a view cell. 12 15 */ 13 16 class Pvs … … 16 19 public: 17 20 18 Pvs() {};21 //Pvs() {} 19 22 20 void Clear() { mEntries.clear(); }23 void Clear(); 21 24 22 bool Empty() const { return mEntries.empty(); }25 bool Empty() const; 23 26 24 SceneEntity *GetEntry(int i) const { return mEntries[i]; }27 void AddEntry(Bvh *bvh, BvhNode *node); 25 28 26 int Size() { return (int)mEntries.size(); }29 int GetSize() const; 27 30 28 void AddEntry(SceneEntity *ent) { mEntries.push_back(ent); } 31 inline SceneEntity *GetEntry(int i) const; 32 33 inline void AddEntry(SceneEntity *ent); 29 34 30 35 … … 35 40 }; 36 41 42 43 inline SceneEntity *Pvs::GetEntry(int i) const 44 { 45 return mEntries[i]; 46 } 47 48 49 inline void Pvs::AddEntry(SceneEntity *ent) 50 { 51 mEntries.push_back(ent); 52 } 53 54 55 inline int Pvs::GetSize() const 56 { 57 return (int)mEntries.size(); 58 } 59 60 61 inline void Pvs::AddEntry(Bvh *bvh, BvhNode *node) 62 { 63 int geometrySize; 64 SceneEntity **entities; 65 entities = bvh->GetGeometry(node, geometrySize); 66 67 for (int i = 0; i < geometrySize; ++ i) 68 { 69 AddEntry(entities[i]); 70 } 71 } 72 73 37 74 } 38 75 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/PvsCollectionRenderer.cpp
r3258 r3259 23 23 void PvsCollectionRenderer::Traverse() 24 24 { 25 mPIS.clear(); 26 25 27 //////////// 26 28 //-- part1: do frustum culling + pvs … … 49 51 } 50 52 53 int pisSize = (int)mPIS.size(); 54 55 51 56 //////////// 52 57 //-- part2: test the potentially invisible nodes … … 57 62 58 63 OcclusionQuery *query = mQueryHandler.RequestQuery(); 59 64 query->Reset(); 65 60 66 int querySize = 50; 61 67 … … 87 93 probablyVisibleNodes.clear(); 88 94 89 95 int qsize = (int)queries.size(); 96 int fqueries = 0; 97 90 98 // get query results: collect probably visible nodes 91 99 while (!queries.empty()) … … 98 106 if (visiblePixels > 0) 99 107 { 108 ++ fqueries; 109 100 110 BvhNodeContainer::const_iterator bit, bit_end = q->GetNodes().end(); 101 111 … … 109 119 } 110 120 121 //cout << "probably visible: " << fqueries << " of " << qsize << " (" << (int)probablyVisibleNodes.size() << " of " << pisSize << " nodes)" << endl; 122 123 111 124 112 125 ////////////// 113 126 //-- part4: test probably visible nodes individually, update pvs of current view cell 114 127 115 return; 116 //if (!mViewCell) return; 128 if (!mViewCell) return; 117 129 118 130 // query all nodes individually … … 122 134 { 123 135 BvhNode *n = *bit; 124 queries.push(IssueOcclusionQuery(n)); 136 137 // node intersects near plane => 138 // add immediately because testing the bb could fail 139 if (mBvh->IntersectsNearPlane(n)) 140 { 141 mViewCell->mPvs.AddEntry(mBvh, n); 142 } 143 else 144 { 145 queries.push(IssueOcclusionQuery(n)); 146 } 125 147 } 126 148 … … 132 154 133 155 const int visiblePixels = q->GetQueryResult(); 134 156 135 157 if (visiblePixels > 0) 136 158 { 137 // add node to pvs 138 int geometrySize; 139 SceneEntity **entities; 140 entities = mBvh->GetGeometry(q->GetFrontNode(), geometrySize); 141 142 for (int i = 0; i < geometrySize; ++ i) 143 { 144 mViewCell->mPvs.AddEntry(entities[i]); 145 } 159 mViewCell->mPvs.AddEntry(mBvh, q->GetFrontNode()); 146 160 } 147 161 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderTraverser.cpp
r3258 r3259 235 235 { 236 236 mUseTightBounds = useTightBounds; 237 //cout << "using tight bounds: " << useTightBounds << endl;238 237 } 239 238 … … 296 295 { 297 296 // no invisible objects 298 if (SceneEntity::Get GlobalVisibleId() == -1) return true;297 if (SceneEntity::GetCurrentVisibleId() == -1) return true; 299 298 300 299 int geometrySize; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp
r3238 r3259 383 383 } 384 384 385 const bool delGeometry = false;385 const bool delGeometry = true; 386 386 return new Geometry(vertices, normals, texcoords, vertexCount, delGeometry, NULL);//tangents); 387 387 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.cpp
r3245 r3259 15 15 { 16 16 17 int SceneEntity::sCurrentId = 0;17 int sCurrentId = 0; 18 18 bool SceneEntity::sUseLODs = true; 19 int SceneEntity::s VisibleId = -1;19 int SceneEntity::sCurrentVisibleId = -1; 20 20 21 21 SceneEntity::SceneEntity(Transform3 *trafo): -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.h
r3251 r3259 44 44 /** Returns number of shapes in vector. 45 45 */ 46 inline int GetNumShapes() ;46 inline int GetNumShapes() const; 47 47 /** Set pointer to the geometry 48 48 */ … … 118 118 this id is -1 or their id matches this id. 119 119 */ 120 static void SetGlobalVisibleId(int id); 121 122 static int GetGlobalVisibleId(); 120 static void SetCurrentVisibleId(int id); 121 122 static int GetCurrentVisibleId(); 123 123 124 124 125 protected: … … 151 152 /// the center of gravity of this entity 152 153 Vector3 mCenter; 153 154 /// generic id 154 155 int mId; 155 156 /// used to find out if this scene entity is in the current pvs 157 int mVisibleId; 158 static int sCurrentVisibleId; 159 /// if LODs are used for rendering: otherwise we always take the highest lod 156 160 static bool sUseLODs; 157 static int sCurrentId; 158 159 int mVisibleId; 160 static int sVisibleId; 161 161 162 }; 162 163 … … 198 199 199 200 200 inline int SceneEntity::GetNumShapes() 201 inline int SceneEntity::GetNumShapes() const 201 202 { 202 203 return (int)mShapes.size(); … … 216 217 217 218 218 inline void SceneEntity::Set GlobalVisibleId(int id)219 { 220 s VisibleId = id;221 } 222 223 224 inline int SceneEntity::Get GlobalVisibleId()225 { 226 return s VisibleId;219 inline void SceneEntity::SetCurrentVisibleId(int id) 220 { 221 sCurrentVisibleId = id; 222 } 223 224 225 inline int SceneEntity::GetCurrentVisibleId() 226 { 227 return sCurrentVisibleId; 227 228 } 228 229 … … 236 237 inline bool SceneEntity::IsVisible() const 237 238 { 238 return (s VisibleId == -1) || (mVisibleId == sVisibleId);239 return (sCurrentVisibleId == -1) || (mVisibleId == sCurrentVisibleId); 239 240 } 240 241 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntityConverter.cpp
r3245 r3259 39 39 } 40 40 41 Geometry *geom = new Geometry(vertices, normals, NULL, 36, false, NULL);41 Geometry *geom = new Geometry(vertices, normals, NULL, 36, true, NULL); 42 42 43 43 Shape *shape = new Shape(geom, mat); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/StopAndWaitTraverser.cpp
r3065 r3259 22 22 mDistanceQueue.pop(); 23 23 24 if (1 && !IsNodeGeometryVisible(node, 10)) 25 { 26 node->SetVisible(false); 27 continue; 28 } 29 24 30 if (mBvh->IsWithinViewFrustum(node)) 25 31 { -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/VisibilitySolutionLoader.cpp
r3258 r3259 151 151 BvhNode *node = nodes[objectId]; 152 152 153 int geometrySize; 154 SceneEntity **entities; 155 entities = bvh->GetGeometry(node, geometrySize); 156 157 for (int k = 0; k < geometrySize; ++ k) 158 { 159 mViewCells[i]->mPvs.AddEntry(entities[k]); 160 } 153 mViewCells[i]->mPvs.AddEntry(bvh, node); 161 154 } 162 155 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r3258 r3259 1613 1613 // enable / disable view cells 1614 1614 usePvs = !usePvs; 1615 if (!usePvs) SceneEntity::Set GlobalVisibleId(-1);1615 if (!usePvs) SceneEntity::SetCurrentVisibleId(-1); 1616 1616 break; 1617 1617 default: … … 2598 2598 int numTriangles = 0; 2599 2599 2600 SceneEntity::Set GlobalVisibleId(globalVisibleId);2601 2602 for (int i = 0; i < viewCell->mPvs. Size(); ++ i)2600 SceneEntity::SetCurrentVisibleId(globalVisibleId); 2601 2602 for (int i = 0; i < viewCell->mPvs.GetSize(); ++ i) 2603 2603 { 2604 2604 SceneEntity *ent = viewCell->mPvs.GetEntry(i);
Note: See TracChangeset
for help on using the changeset viewer.