Changeset 3065 for GTP


Ignore:
Timestamp:
10/24/08 12:29:30 (16 years ago)
Author:
mattausch
Message:

found bug with near plane intersection: q? why did it work with vbo rendering? (probably because of tighter bounds ...)

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

Legend:

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

    r3064 r3065  
    44assumedVisibleFrames=10 
    55maxBatchSize=50 
    6 trianglesPerVirtualLeaf=300 
     6#trianglesPerVirtualLeaf=300 
     7trianglesPerVirtualLeaf=30000 
    78keyForwardMotion=20.0f 
    89keyRotation=1.5f 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/AxisAlignedBox3.cpp

    r3021 r3065  
    5656{ 
    5757        return (mMin == Vector3(-MAXFLOAT)) ||  
    58                 (mMax == Vector3(-MAXFLOAT)); 
     58                   (mMax == Vector3(-MAXFLOAT)); 
    5959} 
    6060 
     
    216216AxisAlignedBox3::IsInside(const Vector3 &v) const 
    217217{ 
    218         return ! ((v.x < mMin.x) || 
    219                 (v.x > mMax.x) || 
    220                 (v.y < mMin.y) || 
    221                 (v.y > mMax.y) || 
    222                 (v.z < mMin.z) || 
    223                 (v.z > mMax.z)); 
     218        return !((v.x < mMin.x) || 
     219                    (v.x > mMax.x) || 
     220                        (v.y < mMin.y) || 
     221                        (v.y > mMax.y) || 
     222                        (v.z < mMin.z) || 
     223                        (v.z > mMax.z)); 
    224224} 
    225225 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.cpp

    r3064 r3065  
    2727#endif 
    2828 
     29#define INVALID_TEST ((unsigned int)-1) 
     30 
     31using namespace std; 
    2932 
    3033namespace CHCDemoEngine 
    3134{ 
    32  
    33 #define INVALID_TEST ((unsigned int)-1) 
    34  
    35 using namespace std; 
    36  
    3735 
    3836int BvhNode::sCurrentState = 0; 
     
    7674 
    7775static Plane3 sNearPlane; 
     76static float sNear; 
    7877static Frustum sFrustum; 
    7978 
     
    147146 
    148147 
    149 /***********************************************************/ 
    150 /*                class Bvh implementation                 */ 
    151 /***********************************************************/ 
     148/**********************************************************/ 
     149/*                class Bvh implementation                */ 
     150/**********************************************************/ 
    152151 
    153152 
     
    183182 
    184183        if (mRoot) delete mRoot; 
    185  
    186184        // delete vbo 
    187185        glDeleteBuffersARB(1, &mVboId); 
     
    191189void Bvh::Init() 
    192190{ 
    193         mStaticRoot = NULL; 
     191        //mStaticRoot = NULL; 
    194192        mDynamicRoot = NULL; 
    195193        mRoot = NULL; 
     
    202200         
    203201        // nodes are tested using the subnodes from 3 levels below 
    204         mMaxDepthForTestingChildren = 3; 
     202        mMaxDepthForTestingChildren = 0;//3; 
    205203        //mMaxDepthForTestingChildren = 4; 
    206204 
     
    311309                tStack.pop(); 
    312310 
    313                 // found depth => take this node 
     311                // found node in specified depth => take this node 
    314312                if ((d == depth) || (node->IsLeaf())) 
    315313                { 
     
    338336        // do the test only if necessary 
    339337        if (!(node->mPlaneMask[BvhNode::sCurrentState] & (1 << i))) 
     338        { 
    340339                return true; 
    341                          
     340        } 
     341 
     342 
    342343        //////// 
    343344        //-- test the n-vertex 
     
    375376 
    376377        //////// 
    377         //-- apply frustum culling for the planes [mPreferredPlane - 5] 
     378        //-- apply frustum culling for the planes with index mPreferredPlane to 6 
    378379 
    379380        for (int i = node->mPreferredPlane[BvhNode::sCurrentState]; i < 6; ++ i) 
     
    382383 
    383384        ////////// 
    384         //-- do the view frustum culling for the planes [0 - m_iPreferredPlane) 
     385        //-- apply frustum culling for the planes with index 0 to mPreferredPlane 
    385386 
    386387        for (int i = 0; i < node->mPreferredPlane[BvhNode::sCurrentState]; ++ i) 
     
    413414        // store near plane 
    414415        sNearPlane = Plane3(cam->GetDirection(), cam->GetPosition()); 
     416        sNear = cam->GetNear(); 
    415417 
    416418        // rebuild dynamic part of the hierarchy 
     
    424426void Bvh::UpdateDistance(BvhNode *node) const 
    425427{ 
    426         // use distance to center rather than the distance to the near plane because 
    427         // otherwise problems with big object penetrating the near plane  
     428        // q: should we use distance to center rather than the distance to the near plane? 
     429         
     430        // because otherwise problems with big object penetrating the near plane  
    428431        // (e.g., big objects in the distance which are then always visible) 
    429432        // especially annoying is this problem when using the frustum  
    430433        // fitting on the visible objects for shadow mapping 
    431  
    432         //node->mDistance = node->GetBox()GetMinDistance(sNearPlane); 
     434        // on the other hand, distance to near plane can also be used  
     435        // for near plane intersection 
    433436        node->mDistance = sNearPlane.Distance(node->GetBox().Center()); 
     437        //node->mDistance = node->GetBox().GetMinDistance(sNearPlane); 
    434438} 
    435439 
     
    458462void Bvh::RenderBounds(BvhNode *node, RenderState *state, bool useTightBounds) 
    459463{ 
    460         // if not using tight bounds, rendering boxes in immediate mode 
    461         // is preferable to vertex arrays (less setup time) 
    462         if (!useTightBounds) 
    463         { 
    464                 RenderBoundingBoxImmediate(node->GetBox()); 
    465         } 
    466         else 
    467         { 
    468                 // hack: use dummy wrapper in order to use function 
    469                 static BvhNodeContainer dummy(1); 
    470                 dummy[0] = node; 
    471                 RenderBounds(dummy, state, useTightBounds); 
    472         } 
     464        // hack: use dummy contayiner as wrapper in order to use multibox function 
     465        static BvhNodeContainer dummy(1); 
     466        dummy[0] = node; 
     467        RenderBounds(dummy, state, useTightBounds); 
    473468} 
    474469 
     
    490485                        RenderBoundingBoxImmediate((*nit)->GetBox()); 
    491486                } 
    492 cout<<"y"; 
     487 
    493488                renderedBoxes = (int)nodes.size(); 
    494489        } 
    495490        else 
    496         {cout<<"x"; 
     491        { 
    497492                renderedBoxes = PrepareBoundsWithDrawArrays(nodes); 
    498493                RenderBoundsWithDrawArrays(renderedBoxes, state); 
     
    529524        { 
    530525                BvhNode *node = *nit; 
    531  
    532526        const int numIndices = node->mNumTestNodes * sNumIndicesPerBox; 
    533527                 
     
    569563        // collect bvh nodes 
    570564        BvhNodeContainer nodes; 
    571         CollectNodes(mStaticRoot, nodes); 
     565        CollectNodes(mRoot, nodes); 
    572566 
    573567        cout << "creating new indices" << endl; 
     
    587581        } 
    588582 
    589  
    590583        cout << "creating global indices buffer" << endl; 
    591584 
     
    607600                // resize array 
    608601                node->mIndicesPtr = mCurrentIndicesPtr; 
    609  
    610602                int numIndices = 0; 
    611603 
    612                 // the bounding box of the test nodes are rendered instead of the root node 
     604                // the bounding boxes of the test nodes are rendered instead of the node itself 
    613605                // => store their indices 
    614606                for (int i = 0; i < node->mNumTestNodes; ++ i, numIndices += sNumIndicesPerBox) 
     
    657649 
    658650        nodes.reserve(GetNumStaticNodes()); 
    659         CollectNodes(mStaticRoot, nodes); 
     651        CollectNodes(mRoot, nodes); 
    660652 
    661653        const unsigned int bufferSize = 8 * (int)nodes.size(); 
     
    717709        // collect all nodes 
    718710        BvhNodeContainer nodes; 
    719         CollectNodes(mStaticRoot, nodes); 
     711        CollectNodes(mRoot, nodes); 
    720712 
    721713        cout << "recomputing bounds, children will be tested in depth " << mMaxDepthForTestingChildren << endl; 
     
    930922        // first invalidate old virtual leaves 
    931923        BvhNodeContainer leaves; 
    932         CollectVirtualLeaves(mStaticRoot, leaves); 
     924        CollectVirtualLeaves(mRoot, leaves); 
    933925 
    934926        BvhNodeContainer::const_iterator bit, bit_end = leaves.end(); 
     
    998990 
    999991        std::stack<BvhNode *> nodeStack; 
    1000         nodeStack.push(mStaticRoot); 
     992        nodeStack.push(mRoot); 
    1001993 
    1002994        while (!nodeStack.empty())  
     
    10391031        const Vector3 u = box.Max(); 
    10401032 
     1033        /////////// 
     1034        //-- render AABB as triangle strips 
     1035 
    10411036        glBegin(GL_TRIANGLE_STRIP); 
    1042         { 
    1043                 /////////// 
    1044                 //-- render AABB as triangle strips 
    1045  
    1046                 // render first half of AABB 
    1047                 glVertex3f(l.x, l.y, u.z); 
    1048                 glVertex3f(u.x, l.y, u.z); 
    1049                 glVertex3f(l.x, u.y, u.z); 
    1050                 glVertex3f(u.x, u.y, u.z); 
    1051                 glVertex3f(l.x, u.y, l.z);  
    1052                 glVertex3f(u.x, u.y, l.z); 
    1053                 glVertex3f(l.x, l.y, l.z);  
    1054                 glVertex3f(u.x, l.y, l.z); 
    1055  
    1056                 glPrimitiveRestartNV(); 
    1057  
    1058                 // render second half of AABB 
    1059                 glVertex3f(l.x, u.y, u.z);  
    1060                 glVertex3f(l.x, u.y, l.z); 
    1061                 glVertex3f(l.x, l.y, u.z); 
    1062                 glVertex3f(l.x, l.y, l.z); 
    1063                 glVertex3f(u.x, l.y, u.z);  
    1064                 glVertex3f(u.x, l.y, l.z); 
    1065                 glVertex3f(u.x, u.y, u.z);  
    1066                 glVertex3f(u.x, u.y, l.z); 
    1067         } 
     1037 
     1038        // render first half of AABB 
     1039        glVertex3f(l.x, l.y, u.z); 
     1040        glVertex3f(u.x, l.y, u.z); 
     1041        glVertex3f(l.x, u.y, u.z); 
     1042        glVertex3f(u.x, u.y, u.z); 
     1043        glVertex3f(l.x, u.y, l.z);  
     1044        glVertex3f(u.x, u.y, l.z); 
     1045        glVertex3f(l.x, l.y, l.z);  
     1046        glVertex3f(u.x, l.y, l.z); 
     1047 
     1048        glPrimitiveRestartNV(); 
     1049 
     1050        // render second half of AABB 
     1051        glVertex3f(l.x, u.y, u.z);  
     1052        glVertex3f(l.x, u.y, l.z); 
     1053        glVertex3f(l.x, l.y, u.z); 
     1054        glVertex3f(l.x, l.y, l.z); 
     1055        glVertex3f(u.x, l.y, u.z);  
     1056        glVertex3f(u.x, l.y, l.z); 
     1057        glVertex3f(u.x, u.y, u.z);  
     1058        glVertex3f(u.x, u.y, l.z); 
     1059 
    10681060        glEnd(); 
    10691061} 
    1070  
    1071  
    10721062 
    10731063 
     
    11231113                                                         bool useTightBounds) 
    11241114{ 
    1125         glDisable(GL_TEXTURE_2D); 
    1126         glDisable(GL_LIGHTING); 
    11271115        glColor3f(1, 1, 1); 
    11281116 
    11291117        // hack: for deferred shading we have to define a material 
    11301118        static Technique boxMat; 
     1119        boxMat.SetLightingEnabled(false); 
     1120 
    11311121        boxMat.SetEmmisive(RgbaColor(1.0f, 1.0f, 1.0f, 1.0f)); 
    11321122 
     
    11351125        if (!useTightBounds) 
    11361126        { 
    1137                 RenderBoxForViz(node->GetBox()); 
     1127                //RenderBoxForViz(node->GetBox()); 
     1128                glPolygonMode(GL_FRONT, GL_LINE); 
     1129                RenderBoundingBoxImmediate(node->GetBox()); 
     1130                glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); 
    11381131        } 
    11391132        else 
     
    11441137                } 
    11451138        } 
    1146  
    1147         glEnable(GL_LIGHTING); 
    1148         glEnable(GL_TEXTURE_2D); 
    11491139} 
    11501140 
     
    12971287 
    12981288 
    1299 } 
     1289bool Bvh::IntersectsNearPlane(BvhNode *node) const 
     1290{  
     1291        float distanceToNearPlane = node->GetBox().GetMinDistance(sNearPlane); 
     1292        // we stored the near plane distance => we can use it also here 
     1293        //float distanceToNearPlane = node->GetDistance(); 
     1294         
     1295        return distanceToNearPlane < sNear; 
     1296} 
     1297 
     1298 
     1299} 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.h

    r3064 r3065  
    6262        */ 
    6363        BvhNode(BvhNode *parent); 
     64        /** Virtual destructor doing nothing. 
     65        */ 
     66        virtual ~BvhNode(); 
     67        /** Reset the status of this node. 
     68        */ 
     69        virtual void ResetVisibility(); 
    6470        /** Returns true if this node is a leaf. 
    6571        */ 
    66         //virtual bool IsPseudoLeaf() = 0; 
    67         /** Virtual destructor doing nothing. 
    68         */ 
    69         virtual ~BvhNode(); 
     72        virtual bool IsLeaf() const = 0; 
    7073        /** Depth of this node in the tree. 
    7174        */ 
    72         inline int GetDepth() const {return mDepth;} 
     75        inline int GetDepth() const; 
    7376        /** Returns parent of this bvh node, NULL if it is root. 
    7477        */ 
    75         inline BvhNode *GetParent() {return mParent;} 
     78        inline BvhNode *GetParent(); 
    7679        /** Number of leaves in the subtree induced by this node. 
    7780        */ 
    78         inline int GetNumLeaves() const {return mNumLeaves;} 
    79         /** Reset the status of this node. 
    80         */ 
    81         virtual void ResetVisibility(); 
    82  
    83         virtual bool IsLeaf() const = 0; 
    84  
    85         bool IsVirtualLeaf() const { return mIsVirtualLeaf; } 
    86  
     81        inline int GetNumLeaves() const; 
     82        /** Returns true if this node is a "virtual" leaf, 
     83                i.e., the node is handled as a leaf during traversal. 
     84        */ 
     85        inline bool IsVirtualLeaf() const; 
    8786        /** Returns the stored distance to the near plane. 
    8887        */ 
    89         float GetDistance() const  { return mDistance; } 
     88        inline float GetDistance() const; 
    9089 
    9190 
     
    131130        /** Returns the bounding box of this node. 
    132131        */ 
    133         inline const AxisAlignedBox3 &GetBox() { return mBox; } 
     132        inline const AxisAlignedBox3 &GetBox() const; 
    134133        /** Return index of this node. 
    135134        */ 
    136         inline int GetId() const { return mId; } 
     135        inline int GetId() const; 
    137136        /** See get 
    138137        */ 
    139         inline void SetId(int id) { mId = id; } 
     138        inline void SetId(int id); 
    140139 
    141140 
     
    160159                order to not break temporal coherency. 
    161160        */ 
    162         static void SetCurrentState(int _state) { sCurrentState = _state; } 
     161        inline static void SetCurrentState(int _state) { sCurrentState = _state; } 
    163162 
    164163 
     
    174173 
    175174        ////////////// 
    176         //-- members that define the current state. There is one state for each camera 
     175        //-- members definig the current visibility state (one state per camera) 
    177176 
    178177        /// the currently used state 
     
    197196        /// #leaves under this node 
    198197        int mNumLeaves; 
    199  
    200  
    201         //////////// 
    202         //-- rendering related options 
    203          
    204          
    205         // Indices to first and last triangle in the triangle array 
    206         // assumes the triangle are placed in continuous chunk of memory 
    207         // however this need not be a global array! 
    208          
    209         /// the index of the first triangle 
    210         int mFirst; 
    211         /// the index of the last triangle 
    212         int mLast; 
    213  
    214         /// the bounding boxes of these nodes are queries instead of the current node 
    215         int mTestNodesIdx; 
    216         /// the number of tighter bounding volumes used for this node 
    217         int mNumTestNodes; 
    218         /// used for efficient element array rendering 
    219         int mIndicesPtr; 
    220  
    221198        /// Area of this node 
    222199        float mArea; 
     
    236213        */ 
    237214        bool mIsMaxDepthForVirtualLeaf; 
     215 
     216 
     217        //////////// 
     218        //-- rendering related options 
     219         
     220        // Indices to first and last triangle in the triangle array 
     221        // assumes the triangle are placed in continuous chunk of memory 
     222        // however this need not be a global array! 
     223         
     224        /// the index of the first triangle 
     225        int mFirst; 
     226        /// the index of the last triangle 
     227        int mLast; 
     228 
     229 
     230        //////////////// 
     231        //-- rendering related options 
     232 
     233        /// the bounding boxes of the test nodes are queries instead of the actual node 
     234        int mTestNodesIdx; 
     235        /// the number of these test nodes 
     236        int mNumTestNodes; 
     237        /// used for efficient element array rendering 
     238        int mIndicesPtr; 
    238239}; 
    239240 
     
    357358} 
    358359 
    359  
     360int BvhNode::GetDepth() const  
     361{  
     362        return mDepth;  
     363} 
     364 
     365 
     366BvhNode *BvhNode::GetParent()  
     367{  
     368        return mParent;  
     369} 
     370 
     371 
     372int BvhNode::GetNumLeaves() const 
     373{ 
     374        return mNumLeaves; 
     375} 
     376 
     377 
     378bool BvhNode::IsVirtualLeaf() const 
     379{  
     380        return mIsVirtualLeaf;  
     381} 
     382 
     383 
     384float BvhNode::GetDistance() const 
     385{ 
     386        return mDistance;  
     387} 
     388 
     389         
     390const AxisAlignedBox3 &BvhNode::GetBox() const 
     391{ 
     392        return mBox;  
     393} 
     394 
     395 
     396int BvhNode::GetId() const  
     397{ 
     398        return mId;  
     399} 
     400 
     401 
     402void BvhNode::SetId(int id)  
     403{ 
     404        mId = id;  
     405} 
    360406 
    361407 
     
    383429        virtual ~BvhInterior(); 
    384430 
     431 
    385432protected: 
    386433 
     
    409456        a lower distance has a higher value in the queue 
    410457*/ 
    411 class mygreaterdistance 
     458class GtDistance 
    412459{ 
    413460public: 
     
    418465}; 
    419466 
    420 typedef std::priority_queue<BvhNode *, std::vector<BvhNode *>, mygreaterdistance> TraversalQueue; 
     467typedef std::priority_queue<BvhNode *, std::vector<BvhNode *>, GtDistance> TraversalQueue; 
    421468 
    422469 
     
    464511        /** Returns number of bvh nodes. 
    465512        */ 
    466         inline int GetNumNodes() const { return mNumNodes; } 
     513        inline int GetNumNodes() const; 
    467514        /** Returns number of bvh leaves. 
    468515        */ 
    469         inline int GetNumLeaves() const { return mNumNodes / 2 + 1;} 
     516        inline int GetNumLeaves() const; 
    470517        /** Returns number of 'virtual' nodes in the hierarchy, i.e. 
    471518                the number of nodes actually used for traversal. 
    472519        */ 
    473         int GetNumVirtualNodes() const  { return mNumVirtualNodes; } 
     520        inline int GetNumVirtualNodes() const; 
    474521        /** Returns number of bvh leaves. 
    475522        */ 
    476         inline int GetNumVirtualLeaves() const { return mNumVirtualNodes / 2 + 1;} 
     523        inline int GetNumVirtualLeaves() const; 
    477524        /** Returns root node of the bvh. 
    478525        */ 
    479         BvhNode *GetRoot() { return mRoot; } 
    480          
     526        inline BvhNode *GetRoot(); 
     527        /** Returns the bounding box of this bvh. 
     528        */ 
     529        inline const AxisAlignedBox3 &GetBox() const; 
     530        /** Returns true if the current bvh node intersects the near plane. 
     531        */ 
     532        bool IntersectsNearPlane(BvhNode *node) const;  
     533 
     534 
    481535        /////////////// 
    482536        //-- functions collecting nodes based on some criteria 
    483537 
    484         /** Collect all nodes higher or equal to a given depth. 
     538        /** Collect all child nodes in a given depth from the specified node. 
    485539        */ 
    486540        void CollectNodes(BvhNode *node, BvhNodeContainer &nodes, int depth); 
     
    489543        */ 
    490544        void CollectLeaves(BvhNode *node, BvhLeafContainer &leaves); 
    491         /** Collect only the virtual leaves (can be anywhere in the Žhierarchy). 
     545        /** Collect only the virtual leaves (can be anywhere in the hierarchy). 
    492546        */ 
    493547        void CollectVirtualLeaves(BvhNode *node, BvhNodeContainer &leaves); 
     
    512566        */ 
    513567        int RenderBounds(const BvhNodeContainer &nodes, RenderState *state, bool useTightBounds); 
    514         /** Returns the bounding box of this bvh. 
    515         */ 
    516         inline const AxisAlignedBox3 &GetBox() { return mBox; } 
     568         
    517569 
    518570 
     
    656708 
    657709        ///////////////////////////// 
    658         // functions that are required to build the dynamic part of the hierarchy 
     710        //-- functions used to construct the dynamic part of the hierarchy 
     711 
    659712        int SortTriangles(BvhLeaf *leaf,  
    660713                              int axis,  
     
    686739        BvhNode *mRoot; 
    687740        /// the root of static part of the the hierarchy 
    688         BvhNode *mStaticRoot; 
     741        //BvhNode *mStaticRoot; 
    689742        /// the root of dynamic part of the the hierarchy 
    690743        BvhNode *mDynamicRoot; 
     
    741794}; 
    742795 
     796 
     797 
     798///////////////// 
     799//-- public inline functions 
     800 
     801 
     802int Bvh::GetNumNodes() const 
     803{ 
     804        return mNumNodes;  
     805} 
     806 
     807 
     808int Bvh::GetNumLeaves() const  
     809{  
     810        return mNumNodes / 2 + 1; 
     811} 
     812 
     813 
     814int Bvh::GetNumVirtualNodes() const   
     815{  
     816        return mNumVirtualNodes;  
     817} 
     818 
     819 
     820int Bvh::GetNumVirtualLeaves() const 
     821{ 
     822        return mNumVirtualNodes / 2 + 1; 
     823} 
     824 
     825 
     826BvhNode *Bvh::GetRoot() 
     827{  
     828        return mRoot;  
     829} 
     830 
     831 
     832const AxisAlignedBox3 &Bvh::GetBox() const  
     833{  
     834        return mBox;  
     835} 
     836 
     837 
    743838} 
    744839 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/BvhLoader.cpp

    r3064 r3065  
    7373 
    7474        Bvh *bvh = new Bvh(entities); 
    75         bvh->mStaticRoot = LoadNextNode(stream, NULL); 
     75 
     76        BvhNode *root = LoadNextNode(stream, NULL); 
    7677 
    7778#if 1 
    78         bvh->mRoot = bvh->mStaticRoot; 
    79         bvh->mNumNodes = 1; 
     79 
     80        bvh->mRoot = root; 
     81 
    8082#else 
     83        // copy root and set new one for dynamic objects 
     84        BvhInterior *newRoot = new BvhInterior(NULL); 
     85         
     86        newRoot->mBox = root->mBox; 
     87        newRoot->mFirst = root->mFirst; 
     88        newRoot->mLast = root->mLast; 
    8189 
    82         // we are setting a new root node  
    83         // and adds one level of indirection to the bvh  
    84         // It allows us to use dynamic objects 
     90        // create 'dynamic' leaf which basically is a container 
     91        // for all dynamic objects 
     92        BvhLeaf *dynamicLeaf = new BvhLeaf(newRoot); 
     93        dynamicLeaf->mBox = root->mBox; 
    8594 
    86         // the new bvh has two main branches 
    87         // a static branch (the old root), and adynamic branch  
    88         // we create a 'dynamic' leaf which basically is a container 
    89         // for all dynamic objects underneath 
    90         // the bounding boxes of the dynamic tree must be updated 
    91         // once each frame in order to be able to incorporate 
    92         // the movements of the objects within 
     95        newRoot->mFront = root; 
     96        root->mParent = newRoot; 
    9397 
    94         // create new root 
    95         BvhInterior *newRoot = new BvhInterior(NULL); 
     98        newRoot->mBack = dynamicLeaf; 
     99 
    96100        bvh->mRoot = newRoot; 
    97  
    98         // the separation is a purely logical one 
    99         // the bounding boxes of the child nodes are  
    100         // identical to those of the root node 
    101  
    102         newRoot->mBox = bvh->mStaticRoot->mBox; 
    103         newRoot->mArea = newRoot->mBox.SurfaceArea(); 
    104  
    105         newRoot->mFirst = bvh->mStaticRoot->mFirst; 
    106         newRoot->mLast = bvh->mStaticRoot->mLast; 
    107  
    108         // add static root on left subtree 
    109         newRoot->mFront = bvh->mStaticRoot; 
    110         bvh->mStaticRoot->mParent = newRoot; 
    111          
    112         // create and add dynamic root 
    113         BvhLeaf *dynamicRoot = new BvhLeaf(newRoot); 
    114          
    115         dynamicRoot->mFirst = 0; 
    116         dynamicRoot->mLast = 0; 
    117         dynamicRoot->mBox = bvh->mStaticRoot->mBox; 
    118         dynamicRoot->mArea = dynamicRoot->mBox.SurfaceArea(); 
    119  
    120         bvh->mDynamicRoot = dynamicRoot; 
    121         newRoot->mBack = dynamicRoot; 
    122  
    123         bvh->mNumNodes = 1; 
    124  
    125101#endif 
    126102 
    127         tQueue.push(bvh->mStaticRoot); 
     103        tQueue.push(bvh->mRoot); 
     104        bvh->mNumNodes = 1; 
    128105 
    129106        while(!tQueue.empty()) 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/CHCPlusPlusTraverser.cpp

    r3038 r3065  
    123123                                // for near plane intersecting bounding box possible  
    124124                                // wrong results => skip occlusion query 
    125                                 if (IntersectsNearPlane(node)) 
     125                                if (mBvh->IntersectsNearPlane(node)) 
    126126                                { 
    127127                                        // update node's visited flag 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/CHCTraverser.cpp

    r2818 r3065  
    7171                                // for near plane intersecting bounding box possible  
    7272                                // wrong results => skip occlusion query 
    73                                 if (IntersectsNearPlane(node)) 
     73                                if (mBvh->IntersectsNearPlane(node)) 
    7474                                { 
    7575                                        // update node's visited flag 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.cpp

    r3058 r3065  
    3636        /// if depth write should be enabled 
    3737        mDepthWriteEnabled = true; 
    38  
     38        /// the render queue bucket this technique is assigned to 
    3939        mRenderQueueBucket = NULL; 
    4040} 
     
    6060} 
    6161 
    62 /* 
    63 Technique::Technique(const Technique &tech) 
    64 { 
    65         mAmbientColor = tech.mAmbientColor; 
    66         mDiffuseColor = tech.mDiffuseColor; 
    67         mSpecularColor = tech.mSpecularColor; 
    68         mEmmisiveColor = tech.mEmmisiveColor; 
    69  
    70         mVertexProgram = tech.mVertexProgram; 
    71         mFragmentProgram = tech.mFragmentProgram; 
    72  
    73         mAlphaTestEnabled = tech.mAlphaTestEnabled; 
    74         mCullFaceEnabled = tech.mCullFaceEnabled; 
    75  
    76         mTexture = tech.mTexture; 
    77  
    78         mVertexProgramParameters = tech.mVertexProgramParameters; 
    79         mFragmentProgramParameters = tech.mFragmentProgramParameters; 
    80  
    81         mColorWriteEnabled = tech.mColorWriteEnabled; 
    82         mLightingEnabled = tech.mLightingEnabled; 
    83         mDepthWriteEnabled = tech.mDepthWriteEnabled; 
    84 }*/ 
    85  
    86  
    87 Technique::~Technique() 
    88 { 
    89 } 
    90  
    9162 
    9263void Technique::Render(RenderState *state) 
     
    10374void Technique::SetFragmentProgram(ShaderProgram *p)  
    10475{  
    105         mFragmentProgram = p;  
    106  
     76        mFragmentProgram = p; 
    10777        mFragmentProgramParameters.Reset(); 
    10878        mFragmentProgramParameters.SetProgram(p); 
     
    11383{  
    11484        mVertexProgram = p;  
    115  
    11685        mVertexProgramParameters.Reset(); 
    11786        mVertexProgramParameters.SetProgram(p); 
     
    11988 
    12089 
    121 /***********************************************/ 
    122 /*        class Material implementation        */ 
    123 /***********************************************/ 
     90 
     91/***************************************************/ 
     92/*          class Material implementation          */ 
     93/***************************************************/ 
    12494 
    12595 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.h

    r3054 r3065  
    5656        */ 
    5757        Technique(); 
    58  
    59         //Technique(const Technique &tech); 
    6058        /** Sets ambient and diffuse color to color 
    6159        */ 
    6260        Technique(const RgbaColor &color); 
    63  
    64         ~Technique(); 
    6561        /** Renders this technique. 
    6662        */ 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.cpp

    r3057 r3065  
    8686 
    8787 
    88 // q matt: is this function really necessary or would it be better 
    89 // to just create a query material and use the setstate function? 
     88static Technique GetDummyTechnique() 
     89{ 
     90        Technique tech; 
     91        tech.Init(); 
     92 
     93        tech.SetColorWriteEnabled(true); 
     94        tech.SetLightingEnabled(true); 
     95        tech.SetDepthWriteEnabled(false); 
     96        //tech.SetCullFaceEnabled(false); 
     97 
     98        return tech; 
     99} 
     100 
     101/** A special technique for occlusion queries. This material 
     102        has color write, depth write, and lighting turned off 
     103*/ 
     104static Technique GetQueryTechnique() 
     105{ 
     106        Technique tech; 
     107        tech.Init(); 
     108 
     109        tech.SetColorWriteEnabled(false); 
     110        tech.SetLightingEnabled(false); 
     111        tech.SetDepthWriteEnabled(false); 
     112        //tech.SetCullFaceEnabled(false); 
     113 
     114        return tech; 
     115} 
     116 
     117 
    90118bool RenderState::SetMode(Mode mode) 
    91119{ 
     
    101129                /// the query box material 
    102130                static Technique queryTech = GetQueryTechnique(); 
    103                 SetState(&queryTech); 
     131                static Technique dummyTech = GetDummyTechnique(); 
     132 
     133                //if ((float)rand() / RAND_MAX < 0.2) 
     134                //      SetState(&dummyTech); 
     135                //else  
     136                        SetState(&queryTech); 
    104137        } 
    105138 
     
    286319 
    287320 
    288 Technique RenderState::GetQueryTechnique() 
    289 { 
    290         Technique tech; 
    291  
    292         tech.Init(); 
    293  
    294         tech.SetColorWriteEnabled(false); 
    295         tech.SetLightingEnabled(false); 
    296         tech.SetDepthWriteEnabled(false); 
    297  
    298         return tech; 
    299 } 
    300  
    301  
    302321void RenderState::SetUseAlphaToCoverage(bool useAlphaToCoverage) 
    303322{ 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.h

    r3061 r3065  
    7373protected: 
    7474 
    75         /** A special technique for occlusion queries. This material 
    76                 has color write, depth write, and lighting turned off 
    77         */ 
    78         static Technique GetQueryTechnique(); 
    79  
    8075 
    8176        ////////////////// 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderTraverser.h

    r2951 r3065  
    154154        */ 
    155155        void IssueOcclusionQuery(const OcclusionQuery &query); 
    156         /** Retunrs true if the current bvh node intersects the near plane. 
    157         */ 
    158         inline bool IntersectsNearPlane(BvhNode *node) const;  
    159156        /** Enqueues a bvh node for distance traversal 
    160157        */ 
     
    216213 
    217214 
    218 inline bool RenderTraverser::IntersectsNearPlane(BvhNode *node) const 
    219 {  
    220         return node->GetDistance() < mCamera->GetNear(); 
    221215} 
    222216 
    223217 
    224218 
    225 } 
    226  
    227  
    228  
    229219#endif // RENDERTRAVERSER_H 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/StopAndWaitTraverser.cpp

    r2802 r3065  
    2525                { 
    2626                        // if intersects near plane assume visible and don't issue test 
    27                         if (IntersectsNearPlane(node)) 
     27                        if (mBvh->IntersectsNearPlane(node)) 
    2828                        { 
    2929                                TraverseNode(node); 
     
    3333                                OcclusionQuery *query = IssueOcclusionQuery(node); 
    3434 
    35                                 const bool visible = query->GetQueryResult() > mVisibilityThreshold; 
     35                                const bool visible = (query->GetQueryResult() > mVisibilityThreshold); 
    3636                         
    3737                                if (visible) 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r3064 r3065  
    178178 
    179179bool useOptimization = false; 
    180 //bool useTightBounds = true; 
    181 bool useTightBounds = false; 
     180bool useTightBounds = true; 
     181//bool useTightBounds = false; 
    182182bool useRenderQueue = true; 
    183183bool useMultiQueries = true; 
     
    17651765 
    17661766                glEnable(GL_TEXTURE_2D); 
    1767  
    17681767                myfont.Begin(); 
    17691768 
     
    17711770                { 
    17721771                        glColor3f(0.0f, 1.0f, 0.0f); 
    1773  
    17741772                        int i = 0; 
    17751773 
    1776                         static char *renderMethodStr[] = {"forward", "depth pass + forward", "deferred shading", "depth pass + deferred"}; 
     1774                        static char *renderMethodStr[] =  
     1775                                {"forward", "depth pass + forward", "deferred shading", "depth pass + deferred"}; 
    17771776         
    17781777                        sprintf(msg[i ++], "multiqueries: %d, tight bounds: %d, render queue: %d",  
    1779                                                         useMultiQueries, useTightBounds, useRenderQueue); 
     1778                                        useMultiQueries, useTightBounds, useRenderQueue); 
    17801779 
    17811780                        sprintf(msg[i ++], "render technique: %s, SSAO: %d", renderMethodStr[renderMethod], useAdvancedShading); 
     
    18311830                 
    18321831                if (!showAlgorithmTime) 
    1833                                 sprintf(msg[7], "%s:  %6.1f fps", alg_str[renderMode], fps); 
     1832                        sprintf(msg[7], "%s:  %6.1f fps", alg_str[renderMode], fps); 
    18341833                else 
    18351834                        sprintf(msg[7], "%s:  %6.1f ms", alg_str[renderMode], rTime); 
     
    18501849void RenderSky() 
    18511850{ 
    1852         buddha->Render(&state); 
     1851        //buddha->Render(&state); 
    18531852 
    18541853        if ((renderMethod == RENDER_DEFERRED) || (renderMethod == RENDER_DEPTH_PASS_DEFERRED)) 
Note: See TracChangeset for help on using the changeset viewer.