Changeset 3259


Ignore:
Timestamp:
01/09/09 02:16:38 (15 years ago)
Author:
mattausch
Message:
 
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  
    160160                        > 
    161161                        <File 
     162                                RelativePath=".\src\BvhExporter.cpp" 
     163                                > 
     164                        </File> 
     165                        <File 
     166                                RelativePath=".\src\BvhExporter.h" 
     167                                > 
     168                        </File> 
     169                        <File 
    162170                                RelativePath=".\src\BvhLoader.cpp" 
    163171                                > 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/default.env

    r3258 r3259  
    9999 
    100100# use full resolution ssao (vs. half resoltion) 
    101 ssaoUseFullResolution=1 
     101ssaoUseFullResolution=0 
    102102# ssao kernel radius 
    103103#ssaoKernelRadius=8e-1f 
     
    115115## powerplant options 
    116116 
    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 
     117filename=PowerPlantM 
     118keyForwardMotion=500.0f 
     119mouseMotion=3.0f 
     120visibilitySolution=power-plant-2c-xx-1000b-pgv2 
     121camPosition=-1320.57 -6306.34 3603 
     122camDirection=0.292156 0.9556 0.0383878 
     123viewCellsScaleFactor=0.05f 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.cpp

    r3245 r3259  
    327327 
    328328 
     329int 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 
    329357void Bvh::CollectNodes(BvhNode *node, BvhNodeContainer &nodes) 
    330358{ 
     
    770798        static BvhNodeContainer nodes; 
    771799        nodes.clear(); 
    772         //nodes.reserve(GetNumNodes()); 
     800 
    773801        CollectNodes(mDynamicRoot, nodes); 
    774802 
     
    15281556        mDynamicRoot->mParent = mRoot; 
    15291557} 
    1530  
    1531  
    1532 } 
     1558   
     1559 
     1560} 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.h

    r3243 r3259  
    3030        friend class Bvh; 
    3131        friend class BvhLoader; 
     32        friend class BvhExporter; 
    3233        friend class mygreaterdistance; 
    3334 
     
    422423        friend class Bvh; 
    423424        friend class BvhLoader; 
     425        friend class BvhExporter; 
    424426 
    425427public: 
     
    474476}; 
    475477 
     478 
    476479typedef std::priority_queue<BvhNode *, std::vector<BvhNode *>, GtDistance> TraversalQueue; 
    477480 
     
    482485{ 
    483486        friend class BvhLoader; 
     487        friend class BvhExporter; 
    484488 
    485489        /** Bvh properties 
     
    524528        */ 
    525529        inline int GetNumNodes() const; 
     530        /** Counts the number of bvh nodes under this node 
     531        */ 
     532        int CountNumNodes(BvhNode *node) const; 
    526533        /** Returns number of bvh leaves. 
    527534        */ 
     
    557564        */ 
    558565        void CollectNodes(BvhNode *node, BvhNodeContainer &nodes, int depth); 
     566        /** Collect all child nodes. 
     567        */ 
    559568        void CollectNodes(BvhNode *node, BvhNodeContainer &nodes); 
    560569        /** Collect the "physical" leaves of the hierarchy 
     
    614623        */ 
    615624        void ResetNodeClassifications(); 
    616         /** Count triangles the node contains. 
     625        /** Counts the number of triangles contained in this node. 
    617626        */ 
    618627        int CountTriangles(BvhNode *node) const; 
     
    654663        //////////////////////////// 
    655664 
    656         /** Returns stats. 
     665        /** Returns statistics. 
    657666        */ 
    658667        const BvhStats &GetBvhStats() const { return mBvhStats; } 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/CHCPlusPlusTraverser.cpp

    r3258 r3259  
    119119                        mDistanceQueue.pop(); 
    120120         
    121                         if (1 && !IsNodeGeometryVisible(node, 10)) 
    122                         { 
     121                        if (!IsNodeGeometryVisible(node, 10)) 
     122                        { 
     123                                node->SetLastVisitedFrame(mFrameId); 
    123124                                node->SetVisible(false); 
     125 
     126                                mBvh->MakeParentsVisible(node); 
     127 
    124128                                continue; 
    125129                        } 
     
    148152 
    149153                                        // node was not recently tested => reset flag  
    150                                         if (node->GetLastVisitedFrame() != mFrameId - 1) 
     154                                        if (node->GetLastVisitedFrame() != (mFrameId - 1)) 
    151155                                        { 
    152156                                                node->SetTimesTestedInvisible(0); 
     
    259263                // node was already part of a mulitquery => avoid recursion 
    260264                if (node->GetLastQueriedFrame() == mFrameId) 
     265                { 
    261266                        newPBatch = 0; 
     267                } 
    262268                else 
     269                { 
    263270                        newPBatch *= mVisibilityPredictor.GetProbability(node); 
     271                } 
    264272 
    265273                if (query->GetNodes().empty()) 
     
    274282                } 
    275283 
    276                 if (newBatchVal <= maxBatchVal) 
    277                         break; 
     284                if (newBatchVal <= maxBatchVal) break; 
    278285 
    279286                iqueue.pop_back(); 
     
    304311 
    305312                while (!mIQueue.empty()) 
     313                { 
    306314                        mQueryQueue.push(GetNextMultiQuery(mIQueue)); 
     315                } 
    307316        } 
    308317        else 
     
    311320 
    312321                for (it = mIQueue.begin(); it != it_end; ++ it) 
     322                { 
    313323                        mQueryQueue.push(IssueOcclusionQuery(*it)); 
     324                } 
    314325 
    315326                mIQueue.clear(); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Geometry.cpp

    r3154 r3259  
    218218 
    219219 
    220 } 
     220Vector3 *Geometry::GetVertices(int &numVertices) const 
     221{ 
     222        numVertices = mNumVertices; 
     223        return mVertices; 
     224} 
     225 
     226 
     227Vector3 *Geometry::GetNormals(int &numNormals) const 
     228{ 
     229        numNormals = mNumVertices; 
     230        return mNormals; 
     231} 
     232 
     233 
     234Vector3 *Geometry::GetTangents(int &numTangents) const 
     235{ 
     236        numTangents = mHasTangents ? mNumVertices : 0;; 
     237        return mTangents; 
     238} 
     239 
     240 
     241Texcoord2 *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  
    1818{ 
    1919        friend class ResourceManager; 
    20         friend class EntityMerger; 
    2120 
    2221public: 
     
    3029                         Texcoord2 *texcoords,  
    3130                         int numVertices,  
    32                          bool delData, 
     31                         bool deleteData, 
    3332                         Vector3 *tangents); 
    3433        /** Detructor destroying the opengl resources. 
     
    4847        inline bool HasTexture() const { return mHasTexture; } 
    4948         
     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 
    5062 
    5163protected: 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Pvs.cpp

    r3242 r3259  
    11#include "Pvs.h" 
    22#include "Timer/PerfTimer.h" 
    3 #include "common.h" 
    43#include <iostream> 
    54 
     
    87{ 
    98 
    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(); 
     9void Pvs::Clear()  
     10{  
     11        mEntries.clear();  
     12} 
    3313 
    3414 
    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"; 
     15bool Pvs::Empty() const  
     16{  
     17        return mEntries.empty();  
    6218} 
    6319 
     20 
     21 
    6422} 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Pvs.h

    r3243 r3259  
    33 
    44#include "common.h" 
    5  
     5#include "Bvh.h" 
    66 
    77namespace CHCDemoEngine 
    88{ 
    99 
    10 /** Template class representing the Potentially Visible Set (PVS)  
    11         mainly from a view cell, but also e.g., from objects. 
     10class BvhNode; 
     11class Bvh; 
     12 
     13 
     14/** Class representing the Potentially Visible Set (PVS) from a view cell. 
    1215*/ 
    1316class Pvs 
     
    1619public: 
    1720 
    18         Pvs() {}; 
     21        //Pvs() {} 
    1922 
    20         void Clear() { mEntries.clear(); } 
     23        void Clear(); 
    2124 
    22         bool Empty() const { return mEntries.empty(); } 
     25        bool Empty() const; 
    2326 
    24         SceneEntity *GetEntry(int i) const { return mEntries[i]; } 
     27        void AddEntry(Bvh *bvh, BvhNode *node); 
    2528 
    26         int Size() { return (int)mEntries.size(); } 
     29        int GetSize() const; 
    2730 
    28         void AddEntry(SceneEntity *ent) { mEntries.push_back(ent); } 
     31        inline SceneEntity *GetEntry(int i) const; 
     32 
     33        inline void AddEntry(SceneEntity *ent); 
    2934 
    3035 
     
    3540}; 
    3641 
     42 
     43inline SceneEntity *Pvs::GetEntry(int i) const  
     44{ 
     45        return mEntries[i];  
     46} 
     47 
     48 
     49inline void Pvs::AddEntry(SceneEntity *ent)  
     50{ 
     51        mEntries.push_back(ent);  
     52} 
     53 
     54 
     55inline int Pvs::GetSize() const 
     56{  
     57        return (int)mEntries.size();  
     58} 
     59 
     60 
     61inline 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 
    3774} 
    3875 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/PvsCollectionRenderer.cpp

    r3258 r3259  
    2323void PvsCollectionRenderer::Traverse() 
    2424{ 
     25        mPIS.clear(); 
     26 
    2527        //////////// 
    2628        //-- part1: do frustum culling + pvs 
     
    4951        } 
    5052 
     53        int pisSize = (int)mPIS.size(); 
     54 
     55 
    5156        //////////// 
    5257        //-- part2: test the potentially invisible nodes 
     
    5762 
    5863        OcclusionQuery *query = mQueryHandler.RequestQuery(); 
    59          
     64        query->Reset(); 
     65 
    6066        int querySize = 50; 
    6167 
     
    8793        probablyVisibleNodes.clear(); 
    8894         
    89          
     95        int qsize = (int)queries.size(); 
     96        int fqueries = 0; 
     97 
    9098        // get query results: collect probably visible nodes 
    9199        while (!queries.empty()) 
     
    98106                if (visiblePixels > 0) 
    99107                { 
     108                        ++ fqueries; 
     109 
    100110                        BvhNodeContainer::const_iterator bit, bit_end = q->GetNodes().end(); 
    101111 
     
    109119        } 
    110120 
     121        //cout << "probably visible: " << fqueries << " of " << qsize << " (" << (int)probablyVisibleNodes.size() << " of " << pisSize << " nodes)" << endl; 
     122 
     123 
    111124 
    112125        ////////////// 
    113126        //-- part4: test probably visible nodes individually, update pvs of current view cell 
    114127 
    115         return; 
    116         //if (!mViewCell) return; 
     128        if (!mViewCell) return; 
    117129         
    118130        // query all nodes individually 
     
    122134        { 
    123135                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                } 
    125147        } 
    126148 
     
    132154         
    133155                const int visiblePixels = q->GetQueryResult(); 
    134  
     156                 
    135157                if (visiblePixels > 0) 
    136158                { 
    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()); 
    146160                } 
    147161        } 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderTraverser.cpp

    r3258 r3259  
    235235{ 
    236236        mUseTightBounds = useTightBounds; 
    237         //cout << "using tight bounds: " << useTightBounds << endl; 
    238237} 
    239238 
     
    296295{ 
    297296        // no invisible objects 
    298         if (SceneEntity::GetGlobalVisibleId() == -1) return true; 
     297        if (SceneEntity::GetCurrentVisibleId() == -1) return true; 
    299298 
    300299        int geometrySize; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp

    r3238 r3259  
    383383        } 
    384384 
    385         const bool delGeometry = false; 
     385        const bool delGeometry = true; 
    386386        return new Geometry(vertices, normals, texcoords, vertexCount, delGeometry, NULL);//tangents); 
    387387} 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.cpp

    r3245 r3259  
    1515{ 
    1616 
    17 int SceneEntity::sCurrentId = 0; 
     17int sCurrentId = 0; 
    1818bool SceneEntity::sUseLODs = true; 
    19 int SceneEntity::sVisibleId = -1; 
     19int SceneEntity::sCurrentVisibleId = -1; 
    2020 
    2121SceneEntity::SceneEntity(Transform3 *trafo):  
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.h

    r3251 r3259  
    4444        /** Returns number of shapes in vector. 
    4545        */ 
    46         inline int GetNumShapes(); 
     46        inline int GetNumShapes() const; 
    4747        /** Set pointer to the geometry 
    4848        */ 
     
    118118                this id is -1 or their id matches this id. 
    119119        */ 
    120         static void SetGlobalVisibleId(int id); 
    121  
    122         static int GetGlobalVisibleId(); 
     120        static void SetCurrentVisibleId(int id); 
     121 
     122        static int GetCurrentVisibleId(); 
     123 
    123124 
    124125protected: 
     
    151152        /// the center of gravity of this entity 
    152153        Vector3 mCenter; 
    153          
     154        /// generic id 
    154155        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 
    156160        static bool sUseLODs; 
    157         static int sCurrentId; 
    158  
    159         int mVisibleId; 
    160         static int sVisibleId; 
     161 
    161162}; 
    162163 
     
    198199 
    199200 
    200 inline int SceneEntity::GetNumShapes() 
     201inline int SceneEntity::GetNumShapes() const 
    201202{ 
    202203        return (int)mShapes.size();  
     
    216217 
    217218 
    218 inline void SceneEntity::SetGlobalVisibleId(int id) 
    219 { 
    220         sVisibleId = id; 
    221 } 
    222  
    223  
    224 inline int SceneEntity::GetGlobalVisibleId() 
    225 { 
    226         return sVisibleId; 
     219inline void SceneEntity::SetCurrentVisibleId(int id) 
     220{ 
     221        sCurrentVisibleId = id; 
     222} 
     223 
     224 
     225inline int SceneEntity::GetCurrentVisibleId() 
     226{ 
     227        return sCurrentVisibleId; 
    227228} 
    228229 
     
    236237inline bool SceneEntity::IsVisible() const 
    237238{ 
    238         return (sVisibleId == -1) || (mVisibleId == sVisibleId); 
     239        return (sCurrentVisibleId == -1) || (mVisibleId == sCurrentVisibleId); 
    239240} 
    240241 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntityConverter.cpp

    r3245 r3259  
    3939        } 
    4040 
    41         Geometry *geom = new Geometry(vertices, normals, NULL, 36, false, NULL); 
     41        Geometry *geom = new Geometry(vertices, normals, NULL, 36, true, NULL); 
    4242 
    4343        Shape *shape = new Shape(geom, mat); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/StopAndWaitTraverser.cpp

    r3065 r3259  
    2222                mDistanceQueue.pop(); 
    2323         
     24                if (1 && !IsNodeGeometryVisible(node, 10)) 
     25                { 
     26                        node->SetVisible(false); 
     27                        continue; 
     28                } 
     29 
    2430                if (mBvh->IsWithinViewFrustum(node)) 
    2531                { 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/VisibilitySolutionLoader.cpp

    r3258 r3259  
    151151                        BvhNode *node = nodes[objectId]; 
    152152 
    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); 
    161154                } 
    162155        } 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r3258 r3259  
    16131613                // enable / disable view cells 
    16141614                usePvs = !usePvs; 
    1615                 if (!usePvs) SceneEntity::SetGlobalVisibleId(-1); 
     1615                if (!usePvs) SceneEntity::SetCurrentVisibleId(-1); 
    16161616                break; 
    16171617        default: 
     
    25982598        int numTriangles = 0; 
    25992599 
    2600         SceneEntity::SetGlobalVisibleId(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) 
    26032603        { 
    26042604                SceneEntity *ent = viewCell->mPvs.GetEntry(i); 
Note: See TracChangeset for help on using the changeset viewer.