Changeset 3245


Ignore:
Timestamp:
01/04/09 16:06:56 (15 years ago)
Author:
mattausch
Message:

pvs seems to work now

Location:
GTP/trunk/App/Demos/Vis/FriendlyCulling
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/default.env

    r3243 r3245  
    1616statsFilename=mystats.log 
    1717 
    18 visibilitySolution=vienna_full-8x3-refu 
     18#visibilitySolution=vienna_full-8x3-refu 
     19visibilitySolution=vienna_full-8x3-pgv 
     20#visibilitySolution=vienna_full-8x3-spgvu 
    1921 
    2022############ 
     
    3941 
    4042# initial camera position 
    41 #camPosition=483.398f 242.364f 186.078f 
     43camPosition=483.398f 242.364f 186.078f 
    4244# initial camera orientation 
    43 #camDirection=1 0 0 
     45camDirection=1 0 0 
    4446 
    45 camPosition=468.025 267.591 182.478 
    46 camDirection=0.937282 0.348573 -0 
     47#camPosition=468.025 267.591 182.478 
     48#camDirection=0.937282 0.348573 -0 
    4749 
    4850#lightDirection=-0.8f 1.0f -0.7f 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.cpp

    r3244 r3245  
    12951295        if (!useTightBounds) 
    12961296        { 
     1297#if 1 
    12971298                RenderBoxForViz(node->GetBox()); 
    1298                 /*glPolygonMode(GL_FRONT, GL_LINE); 
     1299#else 
     1300                glPolygonMode(GL_FRONT, GL_LINE); 
    12991301                RenderBoundingBoxImmediate(node->GetBox()); 
    1300                 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);*/ 
     1302                glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); 
     1303#endif 
    13011304        } 
    13021305        else 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.cpp

    r3214 r3245  
    9797        tech.SetLightingEnabled(false); 
    9898        tech.SetDepthWriteEnabled(false); 
    99         //tech.SetCullFaceEnabled(false); 
    10099 
    101100        return tech; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderTraverser.cpp

    r3244 r3245  
    112112                { 
    113113                        SceneEntity *ent = entities[i]; 
    114                  
     114         
     115                        if (!ent->IsVisible()) continue; 
     116 
    115117                        mStats.mNumRenderedTriangles += ent->CountNumTriangles(); 
    116118 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.cpp

    r3120 r3245  
    1717int SceneEntity::sCurrentId = 0; 
    1818bool SceneEntity::sUseLODs = true; 
    19  
     19int SceneEntity::sVisibleId = -1; 
    2020 
    2121SceneEntity::SceneEntity(Transform3 *trafo):  
    22 mTransform(trafo), mCurrentLODLevel(0), mLODLastUpdated(-1), mId(sCurrentId ++) 
     22mTransform(trafo),  
     23mCurrentLODLevel(0),  
     24mLODLastUpdated(-1), 
     25mId(sCurrentId ++), 
     26mVisibleId(0) 
    2327{ 
    2428        mBox.Initialize(); 
     
    121125 
    122126 
    123 void SceneEntity::SetLastRendered(int lastRendered) 
     127void SceneEntity::SetLastRenderedFrame(int lastRenderedFrame) 
    124128{ 
    125         mLastRendered = lastRendered; 
     129        mLastRenderedFrame = lastRenderedFrame; 
    126130} 
    127131 
    128132 
    129 int SceneEntity::GetLastRendered() const 
     133int SceneEntity::GetLastRenderedFrame() const 
    130134{ 
    131         return mLastRendered; 
     135        return mLastRenderedFrame; 
    132136} 
    133137 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.h

    r3243 r3245  
    2424{ 
    2525        friend class RenderQueue; 
    26         friend class EntityMerger; 
    2726 
    2827public: 
     
    3130        */ 
    3231        SceneEntity(Transform3 *trafo); 
    33         /** Copy constructur. 
    34         */ 
    35         //SceneEntity(const SceneEntity &e); 
    3632        /** Destructor. 
    3733        */ 
     
    4541        /** See set 
    4642        */ 
    47         inline Shape *GetShape(int i) const { return mShapes[i]; } 
     43        inline Shape *GetShape(int i) const; 
    4844        /** Returns number of shapes in vector. 
    4945        */ 
    50         inline int GetNumShapes() { return (int)mShapes.size(); } 
     46        inline int GetNumShapes(); 
    5147        /** Set pointer to the geometry 
    5248        */ 
     
    5450        /** set frame where we last rendered this node 
    5551        */ 
    56         void SetLastRendered(int lastRendered); 
     52        void SetLastRenderedFrame(int lastRendered); 
    5753        /** returns frame where we last visited this node 
    5854        */ 
    59         int GetLastRendered() const; 
     55        int GetLastRenderedFrame() const; 
    6056        /** Returns the trafo of this scene entity. 
    6157        */ 
    62         inline Transform3 *GetTransform() const  { return mTransform; } 
     58        inline Transform3 *GetTransform() const; 
    6359        /** Counts number of triangles in this entity using the specified lod level 
    6460                with 0 being the highest or the current lod level (if the argument is -1). 
     
    7167        */ 
    7268        AxisAlignedBox3 GetWorldBoundingBox() const; 
    73          
     69        /** Only the scene entities are visible that match the global id. 
     70        */ 
     71        void SetVisibleId(int id); 
     72        /** See set 
     73        */ 
     74        int GetVisibleId(int id) const; 
     75        /** Returns true if this entity is visible. 
     76        */ 
     77        bool IsVisible() const; 
    7478 
    7579 
     
    8589        /** Adds a new lod level. 
    8690        */ 
    87         void AddLODLevel(const LODLevel &lod) { mLODLevels.push_back(lod); } 
     91        void AddLODLevel(const LODLevel &lod); 
    8892        /** Returns numbers of lod levels. 
    8993        */ 
    90         int GetNumLODLevels() const { return (int)mLODLevels.size(); } 
     94        int GetNumLODLevels() const; 
    9195        /** Returns center point of this shape. 
    9296        */ 
    93         Vector3 GetCenter() const {return mCenter; } 
     97        Vector3 GetCenter() const; 
    9498        /** Returns transformed center point of this shape. 
    9599        */ 
     
    107111        /** If false, the highest (most detailed) LOD level is used for all entities. 
    108112        */ 
    109         static void SetUseLODs(bool useLODs) { sUseLODs = useLODs; } 
     113        static void SetUseLODs(bool useLODs); 
    110114        /** See set 
    111115        */ 
    112         static bool GetUseLODs() { return sUseLODs; } 
     116        static bool GetUseLODs(); 
     117        /** Sets the global visible id. Scene entities are visible only if 
     118                this id is -1 or their id matches this id. 
     119        */ 
     120        static void SetGlobalVisibleId(int id); 
    113121 
    114122protected: 
     
    133141        ShapeContainer mShapes; 
    134142        /// when this entity was last rendered 
    135         int mLastRendered; 
     143        int mLastRenderedFrame; 
    136144        /// the LOD level currently used for rendering 
    137145        int mCurrentLODLevel; 
     
    145153        static bool sUseLODs; 
    146154        static int sCurrentId; 
     155 
     156        int mVisibleId; 
     157        static int sVisibleId; 
    147158}; 
    148159 
    149160 
     161inline void SceneEntity::AddLODLevel(const LODLevel &lod) 
     162{  
     163        mLODLevels.push_back(lod);  
     164} 
     165 
     166 
     167inline int SceneEntity::GetNumLODLevels() const  
     168{ 
     169        return (int)mLODLevels.size();  
     170} 
     171 
     172 
     173inline Vector3 SceneEntity::GetCenter() const  
     174{  
     175        return mCenter;  
     176} 
     177 
     178 
     179inline void SceneEntity::SetUseLODs(bool useLODs)  
     180{ 
     181        sUseLODs = useLODs;  
     182} 
     183 
     184 
     185inline bool SceneEntity::GetUseLODs()  
     186{  
     187        return sUseLODs;  
     188} 
     189 
     190 
     191inline Shape *SceneEntity::GetShape(int i) const  
     192{  
     193        return mShapes[i];  
     194} 
     195 
     196 
     197inline int SceneEntity::GetNumShapes() 
     198{ 
     199        return (int)mShapes.size();  
     200} 
     201 
     202 
     203inline Transform3 *SceneEntity::GetTransform() const   
     204{  
     205        return mTransform;  
     206} 
     207 
     208 
     209inline void SceneEntity::SetVisibleId(int id) 
     210{ 
     211        mVisibleId = id; 
     212} 
     213 
     214 
     215inline void SceneEntity::SetGlobalVisibleId(int id) 
     216{ 
     217        sVisibleId = id; 
     218} 
     219 
     220 
     221inline int SceneEntity::GetVisibleId(int id) const 
     222{ 
     223        return mVisibleId; 
     224} 
     225 
     226 
     227inline bool SceneEntity::IsVisible() const 
     228{ 
     229        return (sVisibleId == -1) || (mVisibleId == sVisibleId); 
     230} 
     231 
     232 
    150233} 
    151234 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntityConverter.cpp

    r3126 r3245  
    3939        } 
    4040 
    41         cout << "number of triangles in box: " << (int)triangles.size() << endl; 
    42  
    4341        Geometry *geom = new Geometry(vertices, normals, NULL, 36, false, NULL); 
    4442 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.h

    r3147 r3245  
    3737        */ 
    3838        GPUProgramParameters(ShaderProgram *p); 
    39         /** Sets the assoziated program (a 1:n relationship) 
     39        /** Sets the program associated with these parameters (a 1:n relationship) 
    4040        */ 
    4141        void SetProgram(ShaderProgram *p) { mProgram = p; } 
     
    4646 
    4747        /////////// 
    48         //-- set parameters by index 
     48        //-- functions for setting parameters by index 
    4949 
    5050        void SetValue1f(int idx, float value); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ViewCellsTree.cpp

    r3244 r3245  
    7676 
    7777        // get the bounding box 
     78        // exchange x and y coordinates and recompute box 
    7879        fread(&mBox, sizeof(AxisAlignedBox3), 1, fr); 
    7980 
     
    8182        Vector3 v2(mBox.Max().x, -mBox.Max().z, mBox.Max().y); 
    8283         
    83         Vector3 newMin = v1; 
    84         Vector3 newMax = v2; 
     84        mBox.Initialize(); 
    8585 
    86         Minimize(newMin, v2); 
    87         Maximize(newMax, v1); 
    88  
    89         mBox.SetMin(newMin); 
    90         mBox.SetMax(newMax); 
     86        mBox.Include(v1); 
     87        mBox.Include(v2); 
    9188 
    9289        stack<ViewCellsTreeNode **> nodeStack; 
     
    9693 
    9794        int numViewCells = 0; 
     95 
     96        int axes[] = {0, 0, 0}; 
    9897 
    9998        while (!nodeStack.empty())  
     
    108107                fread(&axis, sizeof(int), 1, fr); 
    109108 
    110                 // exchange y and z axis like we have to do for the scene 
     109                // exchange y and z axis like for whole scene 
    111110                if (axis == 2) axis = 1; 
    112111                else if (axis == 1) axis = 2; 
     
    114113                node->mAxis = axis; 
    115114 
    116                 if (node->mAxis > 2 || node->mAxis < -1) cout << "a " << node->mAxis << " "; 
    117  
    118115                if (!node->IsLeaf()) 
    119116                { 
    120                         float pos; 
    121                         fread(&pos, sizeof(float), 1, fr); 
     117                        ++ axes[node->mAxis]; 
    122118 
    123                         if (axis == 1) pos = -pos; 
    124                         node->mPosition = pos; 
    125                          
    126                         nodeStack.push(&node->mFront); 
    127                         nodeStack.push(&node->mBack); 
     119                        float mypos; 
     120                        fread(&mypos, sizeof(float), 1, fr); 
     121                        // changed coordinate system must be considered also here 
     122                        if (node->mAxis == 1)  
     123                        { 
     124                                node->mPosition = -mypos; 
     125 
     126                                nodeStack.push(&node->mBack); 
     127                                nodeStack.push(&node->mFront); 
     128                                //cout << mypos << " "; 
     129                        } 
     130                        else 
     131                        { 
     132                                node->mPosition = mypos; 
     133                                 
     134                                nodeStack.push(&node->mFront); 
     135                                nodeStack.push(&node->mBack); 
     136                        } 
    128137                } 
    129138        } 
    130139 
    131         cout << "loaded " << numViewCells << " view cells" << endl; 
     140        cout << "\nloaded " << numViewCells << " view cells" << " " << axes[0] << " " << axes[1] << " " << axes[2] << endl; 
    132141        return true; 
    133142} 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/VisibilitySolutionLoader.cpp

    r3244 r3245  
    9090{ 
    9191        std::stack<BvhNode *> tStack; 
    92         tStack.push(bvh->GetRoot()); 
     92        tStack.push(bvh->GetStaticRoot()); 
    9393         
    9494        while (!tStack.empty()) 
     
    140140                fread(&entries, sizeof(int), 1, fw); 
    141141 
    142                 for (int j=0; j < entries; ++ j)  
     142                for (int j = 0; j < entries; ++ j)  
    143143                { 
    144144                        int objectId; 
     
    154154                        entities = bvh->GetGeometry(node, geometrySize); 
    155155 
     156                        //if (node->IsLeaf() && (geometrySize != 1)) 
     157                        //if (geometrySize != 1) cout << "Error!! " << geometrySize << endl; 
    156158                        for (int k = 0; k < geometrySize; ++ k) 
    157159                        { 
     
    175177 
    176178        mViewCells.clear(); 
    177          
     179        int axes[] = {0, 0, 0}; 
     180 
    178181        while (!nodeStack.empty())  
    179182        { 
     
    198201                        nodeStack.pop(); 
    199202 
    200                         AxisAlignedBox3 newBox = box; 
    201                         newBox.SetMin(node->mAxis, node->mPosition); 
    202  
    203                         nodeStack.push( 
    204                                 pair<ViewCellsTreeNode *, AxisAlignedBox3>(node->mFront, newBox) 
    205                                 ); 
    206  
    207                         newBox = box; 
    208                         newBox.SetMax(node->mAxis, node->mPosition); 
    209  
    210                         nodeStack.push( 
    211                                 pair<ViewCellsTreeNode *, AxisAlignedBox3>(node->mBack, newBox) 
    212                                 ); 
     203                        AxisAlignedBox3 newBox1 = box; 
     204                        AxisAlignedBox3 newBox2 = box; 
     205                        /*if (node->mPosition < newBox.Min(node->mAxis)) 
     206                                cout << "e: " << node->mPosition << " " << newBox.Min(node->mAxis) << endl; 
     207                        else if (node->mPosition > newBox.Min(node->mAxis)) 
     208                                cout << "o: " << node->mPosition << " " << newBox.Min(node->mAxis) << endl; 
     209*/ 
     210                        newBox1.SetMin(node->mAxis, node->mPosition); 
     211                        newBox2.SetMax(node->mAxis, node->mPosition); 
     212 
     213                        ++ axes[node->mAxis]; 
     214 
     215                        if (node->mAxis == 1) 
     216                        { 
     217                                nodeStack.push(pair<ViewCellsTreeNode *, AxisAlignedBox3>(node->mBack, newBox2)); 
     218                                nodeStack.push(pair<ViewCellsTreeNode *, AxisAlignedBox3>(node->mFront, newBox1)); 
     219                        } 
     220                        else 
     221                        { 
     222                                nodeStack.push(pair<ViewCellsTreeNode *, AxisAlignedBox3>(node->mFront, newBox1)); 
     223                                nodeStack.push(pair<ViewCellsTreeNode *, AxisAlignedBox3>(node->mBack, newBox2)); 
     224                        } 
    213225                } 
    214226        } 
    215227 
    216         cout << "#of viewcells = " << id << endl; 
    217 } 
    218  
    219  
    220 } 
     228        cout << "#of viewcells = " << id << " " << axes[0] << " " << axes[1] << " " << axes[2] << endl; 
     229} 
     230 
     231 
     232} 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Visualization.cpp

    r3063 r3245  
    66#include "RenderState.h" 
    77#include "ShadowMapping.h" 
     8#include "ViewCellsTree.h" 
     9#include "Material.h" 
     10 
     11 
    812#include <stack> 
    913 
     
    1620 
    1721 
    18 static void RenderBoxForViz(const AxisAlignedBox3 &box) 
     22void Visualization::RenderBoxForViz(const AxisAlignedBox3 &box) 
    1923{ 
    2024        glBegin(GL_LINE_LOOP); 
     
    7680mVizCamera(vizCamera), 
    7781mRenderState(renderState), 
    78 mFrameId(0) 
     82mFrameId(0), 
     83mViewCell(NULL) 
    7984{ 
    8085} 
     
    101106{ 
    102107        mFrameId = frameId; 
     108} 
     109 
     110 
     111void Visualization::SetViewCell(ViewCell *vc) 
     112{ 
     113        mViewCell = vc; 
     114} 
     115 
     116 
     117static Technique GetVizTechnique() 
     118{ 
     119        Technique tech; 
     120        tech.Init(); 
     121 
     122        //tech.SetLightingEnabled(false); 
     123        //tech.SetDepthWriteEnabled(false); 
     124 
     125        tech.SetEmmisive(RgbaColor(1.0f, 1.0f, 1.0f, 1.0f)); 
     126        tech.SetDiffuse(RgbaColor(1.0f, 1.0f, 1.0f, 1.0f)); 
     127        tech.SetAmbient(RgbaColor(1.0f, 1.0f, 1.0f, 1.0f)); 
     128 
     129        return tech; 
    103130} 
    104131 
     
    134161                                { 
    135162                                        SceneEntity *ent = entities[i]; 
    136                                         ent->Render(mRenderState); 
     163                                         
     164                                        if (ent->IsVisible()) 
     165                                                ent->Render(mRenderState); 
    137166                                }                
    138167                        } 
    139168                } 
     169        } 
     170 
     171        // render current view cell 
     172        static Technique vcTechnique = GetVizTechnique(); 
     173 
     174        if (mViewCell) 
     175        { 
     176                vcTechnique.Render(mRenderState); 
     177                Visualization::RenderBoxForViz(mViewCell->GetBox()); 
    140178        } 
    141179 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Visualization.h

    r3063 r3245  
    1414class AxisAlignedBox3; 
    1515class GLUquadric; 
     16struct ViewCell; 
    1617 
    1718 
     
    4849        */ 
    4950        void RenderFrustum(); 
     51        /** Sets the current view cell. 
     52        */ 
     53        void SetViewCell(ViewCell *vc); 
    5054 
     55        /** Renders box as wireframe. 
     56        */ 
     57        static void RenderBoxForViz(const AxisAlignedBox3 &box); 
    5158 
    5259protected: 
     
    6572        /// the current frame id 
    6673        int mFrameId; 
     74 
     75        ViewCell *mViewCell; 
    6776}; 
    6877 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r3244 r3245  
    141141ViewCellsTree *viewCellsTree = NULL; 
    142142 
     143static int globalVisibleId = 0; 
     144 
     145ViewCell *viewCell = NULL; 
     146 
    143147 
    144148/// the technique used for rendering 
     
    655659        SceneEntityConverter conv; 
    656660 
    657         // toto clean up material 
     661 
     662        ////////////////// 
     663        //-- occlusion query for sun 
     664 
     665        // todo: clean up material 
    658666        Material *mat = resourceManager->CreateMaterial(); 
    659667 
     
    662670 
    663671        sunBox = conv.ConvertBox(sbox, mat, trafo); 
    664          
    665672        resourceManager->AddSceneEntity(sunBox); 
    666673 
     
    12531260        else 
    12541261        { 
     1262                RenderPvs(); 
     1263 
    12551264                // actually render the scene geometry using the specified algorithm 
    1256                 //traverser->RenderScene(); 
    1257  
    1258                 RenderPvs(); 
     1265                traverser->RenderScene(); 
    12591266        } 
    12601267 
     
    19541961{ 
    19551962        visualization->SetFrameId(traverser->GetCurrentFrameId()); 
    1956          
     1963        visualization->SetViewCell(viewCell); 
     1964 
    19571965        Begin2D(); 
    19581966        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 
     
    25182526 
    25192527 
     2528static Technique GetVizTechnique() 
     2529{ 
     2530        Technique tech; 
     2531        tech.Init(); 
     2532 
     2533        //tech.SetLightingEnabled(false); 
     2534        //tech.SetDepthWriteEnabled(false); 
     2535 
     2536        tech.SetEmmisive(RgbaColor(1.0f, 1.0f, 1.0f, 1.0f)); 
     2537        tech.SetDiffuse(RgbaColor(1.0f, 1.0f, 1.0f, 1.0f)); 
     2538        tech.SetAmbient(RgbaColor(1.0f, 1.0f, 1.0f, 1.0f)); 
     2539 
     2540        return tech; 
     2541} 
     2542 
     2543 
    25202544void RenderPvs() 
    25212545{ 
    2522         ViewCell *vc = viewCellsTree->GetViewCell(camera->GetPosition()); 
    2523  
    2524         for (int i = 0; i < vc->mPvs.Size(); ++ i) 
    2525         { 
    2526                 SceneEntity *ent = vc->mPvs.GetEntry(i); 
    2527                 ent->Render(&renderState); 
    2528         } 
    2529 } 
     2546        viewCell = viewCellsTree->GetViewCell(camera->GetPosition()); 
     2547 
     2548        int numTriangles = 0; 
     2549 
     2550        for (int i = 0; i < viewCell->mPvs.Size(); ++ i) 
     2551        { 
     2552                SceneEntity *ent = viewCell->mPvs.GetEntry(i); 
     2553                //ent->Render(&renderState); 
     2554                ent->SetVisibleId(globalVisibleId); 
     2555 
     2556                numTriangles += ent->CountNumTriangles(); 
     2557        } 
     2558 
     2559        SceneEntity::SetGlobalVisibleId(globalVisibleId ++); 
     2560 
     2561        // render current view cell 
     2562        static Technique vcTechnique = GetVizTechnique(); 
     2563 
     2564        vcTechnique.Render(&renderState); 
     2565        Visualization::RenderBoxForViz(viewCell->GetBox()); 
     2566 
     2567        visualization->SetViewCell(viewCell); 
     2568 
     2569        //cout << "pvs: " << vc->mPvs.Size() << " triangles: " << numTriangles << endl; 
     2570} 
Note: See TracChangeset for help on using the changeset viewer.