Changeset 3202


Ignore:
Timestamp:
12/01/08 16:50:13 (15 years ago)
Author:
mattausch
Message:

finally found bvh tighter bounds bug

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

Legend:

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

    r3173 r3202  
    812812                        </File> 
    813813                        <File 
     814                                RelativePath=".\src\AxisAlignedBox3.h" 
     815                                > 
     816                        </File> 
     817                        <File 
    814818                                RelativePath=".\src\Halton.cpp" 
    815819                                > 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/default.env

    r3201 r3202  
    1111maxBatchSize=50 
    1212# triangles per bvh leaf (influences hierarchy depth vs. occlusion power) 
    13 trianglesPerVirtualLeaf=12900 
     13trianglesPerVirtualLeaf=300 
    1414 
    15 maxDepthForTestingChildren=0 
     15maxDepthForTestingChildren=3 
    1616 
    1717################ 
     
    8585# skylight turbitity 
    8686turbitity=3.0f 
     87 
     88#second bad view point 
     89//camPosition=465.626 248.788 184.978 
     90//camDirection=0.0592959 0.998021 0.0209425 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/AxisAlignedBox3.cpp

    r3070 r3202  
    260260// compute the vertex for number N = <0..7>, N = 4.x + 2.y + z, where 
    261261// x,y,z are either 0 or 1; (0 .. min coordinate, 1 .. max coordinate) 
    262 void AxisAlignedBox3::GetVertex(const int N, Vector3 &vertex) const 
     262void AxisAlignedBox3::GetVertex2(int N, Vector3 &vertex) const 
     263{ 
     264        switch (N)  
     265        { 
     266        case 0: vertex.SetValue(mMin.x, mMin.y, mMin.z); break; 
     267        case 1: vertex.SetValue(mMax.x, mMin.y, mMin.z); break; 
     268        case 2: vertex.SetValue(mMax.x, mMax.y, mMin.z); break; 
     269        case 3: vertex.SetValue(mMin.x, mMax.y, mMin.z); break; 
     270        case 4: vertex.SetValue(mMin.x, mMax.y, mMax.z); break; 
     271        case 5: vertex.SetValue(mMax.x, mMax.y, mMax.z); break; 
     272        case 6: vertex.SetValue(mMax.x, mMin.y, mMax.z); break; 
     273        case 7: vertex.SetValue(mMin.x, mMin.y, mMax.z); break; 
     274        default:  
     275                { 
     276                        cerr << "ERROR in AxisAlignedBox3::GetVertex N=" << N <<  "\n"; 
     277                } 
     278        } 
     279} 
     280 
     281// compute the vertex for number N = <0..7>, N = 4.x + 2.y + z, where 
     282// x,y,z are either 0 or 1; (0 .. min coordinate, 1 .. max coordinate) 
     283void AxisAlignedBox3::GetVertex(int N, Vector3 &vertex) const 
    263284{ 
    264285        switch (N)  
     
    844865        const float epsAdd = 1e-6f; 
    845866        const float epsMul = 1.000005f; 
     867         
    846868        float dir = mMax.x - mMin.x; 
    847869 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/AxisAlignedBox3.h

    r3070 r3202  
    1717 
    1818 
     19/** A very simple ray structure. 
     20*/ 
    1921struct SimpleRay 
    2022{ 
     
    2224 
    2325        SimpleRay(const Vector3 &o, const Vector3 &d): mOrigin(o), mDirection(d) {} 
    24  
    25         Vector3 mOrigin; 
    26         Vector3 mDirection; 
    2726 
    2827        Vector3 Extrap(const float t) const  
     
    3029                return mOrigin + mDirection * t; 
    3130        } 
     31 
     32 
     33        //////////////7 
     34         
     35        Vector3 mOrigin; 
     36        Vector3 mDirection; 
     37 
    3238}; 
    3339 
     
    4551        //-- Constructors. 
    4652 
     53        /** Default constructor creating an existing box. 
     54                The user has to call Initialize once in order 
     55                to be able to use the box. 
     56        */ 
    4757        AxisAlignedBox3(); 
    48  
     58        /** Constructor taking the minimum and maximum as parameters. 
     59        */ 
    4960        AxisAlignedBox3(const Vector3 &nMin, const Vector3 &nMax); 
    5061        /** initialization to the non existing bounding box 
     
    5768        */ 
    5869        Vector3 Diagonal() const; 
    59  
     70        /** Computes the mid point in the given axis. 
     71        */ 
    6072        float Center(const int axis) const; 
    61  
     73        /** The vertex of the box with the smallest values in all dimensions. 
     74        */ 
    6275        float Min(const int axis) const; 
    63  
     76        /** The vertex of the box with the largest values in all dimensions. 
     77        */ 
    6478        float Max(const int axis) const; 
    65  
     79        /** The extent of the box in the given axis. 
     80        */ 
    6681        float Size(const int axis) const; 
    6782        /** Returns axis where box has largest extent. 
     
    7186        */ 
    7287        const Vector3& Min() const; 
     88        /** See Min 
     89        */ 
    7390        const Vector3& Max() const; 
    74  
     91        /** Enlarges box in all dimensions by adding with the given value. 
     92        */ 
    7593        void Enlarge(const Vector3 &v); 
    76  
     94        /** If the box is degenerate, this function enlarges the box 
     95                to the minimum valid size. 
     96        */ 
    7797        void EnlargeToMinSize(); 
    78  
     98        /** Sets a new minimum of the box. 
     99        */ 
    79100        void SetMin(const Vector3 &v); 
    80  
     101        /** Sets a new maximum of the box. 
     102        */ 
    81103        void SetMax(const Vector3 &v); 
    82  
     104        /** Sets the minimum for one dimension. 
     105        */ 
    83106        void SetMin(int axis, const float value); 
    84  
     107        /** Sets the maximum for one dimension. 
     108        */ 
    85109        void SetMax(int axis, const float value); 
    86110        /** Decrease box by given splitting plane 
    87111        */ 
    88112        void Reduce(int axis, int right, float value);  
    89  
     113        /** Returns true if the box intersects the line given by the end 
     114                vertices. 
     115        */ 
    90116        bool Intersects(const Vector3 &lStart, const Vector3 &lEnd) const; 
    91  
    92         // the size of the box along all the axes 
     117        /** The size of the box along all the axes 
     118        */ 
    93119        Vector3 Size() const; 
    94         float Radius() const { return 0.5f * Magnitude(Size()); } 
    95         float SqrRadius() const { return 0.5f * SqrMagnitude(Size()); } 
     120        /** The diagonal radius of the box. 
     121        */ 
     122        float Radius() const; 
     123        /** The square radius. 
     124        */ 
     125        float SqrRadius() const; 
    96126        /** Return whether the box is unbounded.  Unbounded boxes appear 
    97127                when unbounded objects such as quadric surfaces are included. 
     
    99129        bool Unbounded() const; 
    100130 
    101         // Expand the axis-aligned box to include the given object. 
     131        /** Expand the axis-aligned box to include the given object. 
     132        */ 
    102133        void Include(const Vector3 &newpt); 
    103134        void Include(const AxisAlignedBox3 &bbox); 
     
    111142        */ 
    112143        bool Includes(const AxisAlignedBox3 &b) const; 
    113  
    114144        /** Returns true if this point is inside box. 
    115145        */ 
     
    160190                                 ID_Top = 5}; 
    161191 
    162         // Writes a brief description of the object, indenting by the given 
    163         // number of spaces first. 
     192        /** Writes a brief description of the object, indenting by the given 
     193            number of spaces first. 
     194        */ 
    164195        virtual void Describe(std::ostream& app, int ind) const; 
    165196 
    166         // For edge .. number <0..11> returns two incident vertices 
     197        /** For edge .. number <0..11> returns two incident vertices 
     198        */ 
    167199        void GetEdge(int edge, Vector3 *a, Vector3 *b) const; 
    168  
    169         // Compute the coordinates of one vertex of the box for 0/1 in each axis 
    170         // 0 .. smaller coordinates, 1 .. large coordinates 
     200        /** Compute the coordinates of one vertex of the box for 0/1 in each axis 
     201            0 .. smaller coordinates, 1 .. large coordinates 
     202        */ 
    171203        Vector3 GetVertex(int xAxis, int yAxis, int zAxis) const; 
    172  
    173         // Compute the vertex for number N=<0..7>, N = 4*x + 2*y + z, where 
    174         // x,y,z are either 0 or 1; (0 .. lower coordinate, 1 .. large coordinate) 
    175         // (xmin,ymin, zmin) .. N = 0, (xmax, ymax, zmax) .. N= 7 
     204        /** Compute the vertex for number N=<0..7>, N = 4*x + 2*y + z, where 
     205            x,y,z are either 0 or 1; (0 .. lower coordinate, 1 .. large coordinate) 
     206           (xmin,ymin, zmin) .. N = 0, (xmax, ymax, zmax) .. N= 7 
     207    */ 
    176208        void GetVertex(int N, Vector3 &vertex) const; 
    177  
     209        /** Convencience method that returns a vertex internally using the  
     210                above routine. 
     211        */ 
    178212        Vector3 GetVertex(int N) const; 
     213        /** Uses different vertex order: vertices are chosen so that they 
     214                only differ by one value (min or max) in the x, y, z triple 
     215        */ 
     216        void GetVertex2(int N, Vector3 &vertex) const; 
    179217        /** get the extent of face. 
    180218        */ 
     
    322360// -------------------------------------------------------------------------- 
    323361// Implementation of inline (member) functions 
     362 
     363inline float AxisAlignedBox3::Radius() const  
     364{  
     365        return 0.5f * Magnitude(Size());  
     366} 
     367 
     368 
     369inline float AxisAlignedBox3::SqrRadius() const  
     370{  
     371        return 0.5f * SqrMagnitude(Size());  
     372} 
     373 
    324374 
    325375inline bool 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.cpp

    r3201 r3202  
    6161 
    6262 
    63 const static int sNumIndicesPerBox = 20; 
     63const static int NUM_INDICES_PER_BOX = 20; 
    6464 
    6565/*      Order of vertices 
     
    548548        else 
    549549        { 
     550                BvhNodeContainer::const_iterator nit, nit_end = nodes.end(); 
     551 
     552                /*for (nit = nodes.begin(); nit != nit_end; ++ nit) 
     553                { 
     554                        BvhNode *node = *nit; 
     555 
     556                        for (int i = 0; i < node->mNumTestNodes; ++ i) 
     557                        { 
     558                                RenderBoundingBoxImmediate(mTestNodes[node->mTestNodesIdx + i]->GetBox()); 
     559                        } 
     560                }*/ 
     561 
    550562                renderedBoxes = PrepareBoundsWithDrawArrays(nodes); 
    551563                RenderBoundsWithDrawArrays(renderedBoxes, state); 
     
    582594        { 
    583595                BvhNode *node = *nit; 
    584         const int numIndices = node->mNumTestNodes * sNumIndicesPerBox; 
     596        const int numIndices = node->mNumTestNodes * NUM_INDICES_PER_BOX; 
    585597                 
    586598                // copy indices 
    587                 memcpy(mIndices + numNodes * sNumIndicesPerBox,  
     599                memcpy(mIndices + numNodes * NUM_INDICES_PER_BOX,  
    588600                           mTestIndices + node->mIndicesPtr,  
    589601                           numIndices * sizeof(unsigned int)); 
     
    610622        } 
    611623 
    612         // we do use the last or the first index (they are generate and only used to connect strips) 
    613         int numElements = numNodes * sNumIndicesPerBox - 1; 
     624        // we don't use the last or the first index (they are generate and only used to connect strips) 
     625        int numElements = numNodes * NUM_INDICES_PER_BOX - 1; 
    614626        // don't render first degenerate index 
    615627        glDrawElements(GL_TRIANGLE_STRIP, numElements, GL_UNSIGNED_INT, mIndices + 1);  
     
    621633        // collect bvh nodes 
    622634        BvhNodeContainer nodes; 
    623         CollectNodes(mRoot, nodes); 
     635        // first collect dynamic nodes so we make sure that they are in the beginning 
     636        CollectNodes(mDynamicRoot, nodes); 
     637        // then collect static nodes 
     638        CollectNodes(mStaticRoot, nodes); 
     639        //CollectNodes(mRoot, nodes); 
    624640 
    625641        cout << "creating new indices" << endl; 
     
    631647        for (lit = nodes.begin(); lit != lit_end; ++ lit) 
    632648        { 
    633                 int offset = (*lit)->mNumTestNodes * sNumIndicesPerBox; 
     649                int offset = (*lit)->mNumTestNodes * NUM_INDICES_PER_BOX; 
    634650#ifdef ALIGN_INDICES 
    635651                // align with 32 in order to speed up memcopy 
     
    641657        cout << "creating global indices buffer" << endl; 
    642658 
    643         if (mIndices) delete [] mIndices; 
     659        if (mIndices)     delete [] mIndices; 
    644660        if (mTestIndices) delete [] mTestIndices; 
    645661 
    646662        // global buffer: create it once so we don't have 
    647         // to allocate memory from the chunks of the node 
     663        // to allocate memory for each individual chunk of the node 
    648664        mIndices = new unsigned int[numMaxIndices]; 
    649665        // create new index buffer for the individual nodes 
     
    662678                // the bounding boxes of the test nodes are rendered instead of the node itself 
    663679                // => store their indices 
    664                 for (int i = 0; i < node->mNumTestNodes; ++ i, numIndices += sNumIndicesPerBox) 
     680                for (int i = 0; i < node->mNumTestNodes; ++ i, numIndices += NUM_INDICES_PER_BOX) 
    665681                { 
    666682                        BvhNode *testNode = mTestNodes[node->mTestNodesIdx + i]; 
    667683 
    668                         // add indices to root node 
    669                         for (int j = 0; j < sNumIndicesPerBox; ++ j) 
     684                        // add vertex indices of boxes to root node 
     685                        for (int j = 0; j < NUM_INDICES_PER_BOX; ++ j) 
    670686                        { 
    671687                                mTestIndices[mCurrentIndicesPtr + numIndices + j] = sIndices[j] + testNode->GetId() * 8; 
     
    732748                BvhNode *node = *lit; 
    733749 
     750                Vector3 v; 
     751 
    734752                for (int j = 0; j < 8; ++ j) 
    735                         (static_cast<Vector3 *>(mVertices))[node->GetId() * 8 + j] = node->GetBox().GetVertex(j); 
     753                { 
     754                        node->GetBox().GetVertex2(j, v); 
     755                        (static_cast<Vector3 *>(mVertices))[node->GetId() * 8 + j] = v; 
     756                } 
    736757        } 
    737758 
     
    12941315        else 
    12951316        { 
    1296                 for (int i = 0; i < node->mNumTestNodes; ++ i) 
     1317                glPolygonMode(GL_FRONT, GL_LINE); 
     1318                BvhNodeContainer nodes; 
     1319                nodes.push_back(node); 
     1320                int renderedBoxes = PrepareBoundsWithDrawArrays(nodes); 
     1321                RenderBoundsWithDrawArrays(renderedBoxes, state); 
     1322                glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); 
     1323 
     1324                /*for (int i = 0; i < node->mNumTestNodes; ++ i) 
    12971325                { 
    12981326                        RenderBoxForViz(mTestNodes[node->mTestNodesIdx + i]->GetBox()); 
    1299                 } 
     1327                }*/ 
    13001328        } 
    13011329 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h

    r3199 r3202  
    1010//#define NUM_SAMPLES 24 
    1111 
    12 //#define SAMPLE_INTENSITY 0.5f 
    13 #define SAMPLE_INTENSITY 1.0f 
     12//#define SAMPLE_INTENSITY 0.1f 
     13#define SAMPLE_INTENSITY 2.0f 
    1414 
    1515#define SAMPLE_RADIUS 8e-1f 
Note: See TracChangeset for help on using the changeset viewer.