Changeset 3202
- Timestamp:
- 12/01/08 16:50:13 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj
r3173 r3202 812 812 </File> 813 813 <File 814 RelativePath=".\src\AxisAlignedBox3.h" 815 > 816 </File> 817 <File 814 818 RelativePath=".\src\Halton.cpp" 815 819 > -
GTP/trunk/App/Demos/Vis/FriendlyCulling/default.env
r3201 r3202 11 11 maxBatchSize=50 12 12 # triangles per bvh leaf (influences hierarchy depth vs. occlusion power) 13 trianglesPerVirtualLeaf= 1290013 trianglesPerVirtualLeaf=300 14 14 15 maxDepthForTestingChildren= 015 maxDepthForTestingChildren=3 16 16 17 17 ################ … … 85 85 # skylight turbitity 86 86 turbitity=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 260 260 // compute the vertex for number N = <0..7>, N = 4.x + 2.y + z, where 261 261 // x,y,z are either 0 or 1; (0 .. min coordinate, 1 .. max coordinate) 262 void AxisAlignedBox3::GetVertex(const int N, Vector3 &vertex) const 262 void 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) 283 void AxisAlignedBox3::GetVertex(int N, Vector3 &vertex) const 263 284 { 264 285 switch (N) … … 844 865 const float epsAdd = 1e-6f; 845 866 const float epsMul = 1.000005f; 867 846 868 float dir = mMax.x - mMin.x; 847 869 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/AxisAlignedBox3.h
r3070 r3202 17 17 18 18 19 /** A very simple ray structure. 20 */ 19 21 struct SimpleRay 20 22 { … … 22 24 23 25 SimpleRay(const Vector3 &o, const Vector3 &d): mOrigin(o), mDirection(d) {} 24 25 Vector3 mOrigin;26 Vector3 mDirection;27 26 28 27 Vector3 Extrap(const float t) const … … 30 29 return mOrigin + mDirection * t; 31 30 } 31 32 33 //////////////7 34 35 Vector3 mOrigin; 36 Vector3 mDirection; 37 32 38 }; 33 39 … … 45 51 //-- Constructors. 46 52 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 */ 47 57 AxisAlignedBox3(); 48 58 /** Constructor taking the minimum and maximum as parameters. 59 */ 49 60 AxisAlignedBox3(const Vector3 &nMin, const Vector3 &nMax); 50 61 /** initialization to the non existing bounding box … … 57 68 */ 58 69 Vector3 Diagonal() const; 59 70 /** Computes the mid point in the given axis. 71 */ 60 72 float Center(const int axis) const; 61 73 /** The vertex of the box with the smallest values in all dimensions. 74 */ 62 75 float Min(const int axis) const; 63 76 /** The vertex of the box with the largest values in all dimensions. 77 */ 64 78 float Max(const int axis) const; 65 79 /** The extent of the box in the given axis. 80 */ 66 81 float Size(const int axis) const; 67 82 /** Returns axis where box has largest extent. … … 71 86 */ 72 87 const Vector3& Min() const; 88 /** See Min 89 */ 73 90 const Vector3& Max() const; 74 91 /** Enlarges box in all dimensions by adding with the given value. 92 */ 75 93 void Enlarge(const Vector3 &v); 76 94 /** If the box is degenerate, this function enlarges the box 95 to the minimum valid size. 96 */ 77 97 void EnlargeToMinSize(); 78 98 /** Sets a new minimum of the box. 99 */ 79 100 void SetMin(const Vector3 &v); 80 101 /** Sets a new maximum of the box. 102 */ 81 103 void SetMax(const Vector3 &v); 82 104 /** Sets the minimum for one dimension. 105 */ 83 106 void SetMin(int axis, const float value); 84 107 /** Sets the maximum for one dimension. 108 */ 85 109 void SetMax(int axis, const float value); 86 110 /** Decrease box by given splitting plane 87 111 */ 88 112 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 */ 90 116 bool Intersects(const Vector3 &lStart, const Vector3 &lEnd) const; 91 92 // the size of the box along all the axes117 /** The size of the box along all the axes 118 */ 93 119 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; 96 126 /** Return whether the box is unbounded. Unbounded boxes appear 97 127 when unbounded objects such as quadric surfaces are included. … … 99 129 bool Unbounded() const; 100 130 101 // Expand the axis-aligned box to include the given object. 131 /** Expand the axis-aligned box to include the given object. 132 */ 102 133 void Include(const Vector3 &newpt); 103 134 void Include(const AxisAlignedBox3 &bbox); … … 111 142 */ 112 143 bool Includes(const AxisAlignedBox3 &b) const; 113 114 144 /** Returns true if this point is inside box. 115 145 */ … … 160 190 ID_Top = 5}; 161 191 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 */ 164 195 virtual void Describe(std::ostream& app, int ind) const; 165 196 166 // For edge .. number <0..11> returns two incident vertices 197 /** For edge .. number <0..11> returns two incident vertices 198 */ 167 199 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 axis170 // 0 .. smaller coordinates, 1 .. large coordinates200 /** Compute the coordinates of one vertex of the box for 0/1 in each axis 201 0 .. smaller coordinates, 1 .. large coordinates 202 */ 171 203 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, where174 // 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 */ 176 208 void GetVertex(int N, Vector3 &vertex) const; 177 209 /** Convencience method that returns a vertex internally using the 210 above routine. 211 */ 178 212 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; 179 217 /** get the extent of face. 180 218 */ … … 322 360 // -------------------------------------------------------------------------- 323 361 // Implementation of inline (member) functions 362 363 inline float AxisAlignedBox3::Radius() const 364 { 365 return 0.5f * Magnitude(Size()); 366 } 367 368 369 inline float AxisAlignedBox3::SqrRadius() const 370 { 371 return 0.5f * SqrMagnitude(Size()); 372 } 373 324 374 325 375 inline bool -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.cpp
r3201 r3202 61 61 62 62 63 const static int sNumIndicesPerBox= 20;63 const static int NUM_INDICES_PER_BOX = 20; 64 64 65 65 /* Order of vertices … … 548 548 else 549 549 { 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 550 562 renderedBoxes = PrepareBoundsWithDrawArrays(nodes); 551 563 RenderBoundsWithDrawArrays(renderedBoxes, state); … … 582 594 { 583 595 BvhNode *node = *nit; 584 const int numIndices = node->mNumTestNodes * sNumIndicesPerBox;596 const int numIndices = node->mNumTestNodes * NUM_INDICES_PER_BOX; 585 597 586 598 // copy indices 587 memcpy(mIndices + numNodes * sNumIndicesPerBox,599 memcpy(mIndices + numNodes * NUM_INDICES_PER_BOX, 588 600 mTestIndices + node->mIndicesPtr, 589 601 numIndices * sizeof(unsigned int)); … … 610 622 } 611 623 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; 614 626 // don't render first degenerate index 615 627 glDrawElements(GL_TRIANGLE_STRIP, numElements, GL_UNSIGNED_INT, mIndices + 1); … … 621 633 // collect bvh nodes 622 634 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); 624 640 625 641 cout << "creating new indices" << endl; … … 631 647 for (lit = nodes.begin(); lit != lit_end; ++ lit) 632 648 { 633 int offset = (*lit)->mNumTestNodes * sNumIndicesPerBox;649 int offset = (*lit)->mNumTestNodes * NUM_INDICES_PER_BOX; 634 650 #ifdef ALIGN_INDICES 635 651 // align with 32 in order to speed up memcopy … … 641 657 cout << "creating global indices buffer" << endl; 642 658 643 if (mIndices) delete [] mIndices;659 if (mIndices) delete [] mIndices; 644 660 if (mTestIndices) delete [] mTestIndices; 645 661 646 662 // global buffer: create it once so we don't have 647 // to allocate memory f rom the chunksof the node663 // to allocate memory for each individual chunk of the node 648 664 mIndices = new unsigned int[numMaxIndices]; 649 665 // create new index buffer for the individual nodes … … 662 678 // the bounding boxes of the test nodes are rendered instead of the node itself 663 679 // => 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) 665 681 { 666 682 BvhNode *testNode = mTestNodes[node->mTestNodesIdx + i]; 667 683 668 // add indices to root node669 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) 670 686 { 671 687 mTestIndices[mCurrentIndicesPtr + numIndices + j] = sIndices[j] + testNode->GetId() * 8; … … 732 748 BvhNode *node = *lit; 733 749 750 Vector3 v; 751 734 752 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 } 736 757 } 737 758 … … 1294 1315 else 1295 1316 { 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) 1297 1325 { 1298 1326 RenderBoxForViz(mTestNodes[node->mTestNodesIdx + i]->GetBox()); 1299 } 1327 }*/ 1300 1328 } 1301 1329 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h
r3199 r3202 10 10 //#define NUM_SAMPLES 24 11 11 12 //#define SAMPLE_INTENSITY 0. 5f13 #define SAMPLE_INTENSITY 1.0f12 //#define SAMPLE_INTENSITY 0.1f 13 #define SAMPLE_INTENSITY 2.0f 14 14 15 15 #define SAMPLE_RADIUS 8e-1f
Note: See TracChangeset
for help on using the changeset viewer.