Changeset 2947 for GTP/trunk/App/Demos/Vis/FriendlyCulling
- Timestamp:
- 09/15/08 10:13:33 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling/src
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/AxisAlignedBox3.cpp
r2944 r2947 1038 1038 1039 1039 1040 float AxisAlignedBox3::GetMin VisibleDistance(const Plane3 &near) const1040 float AxisAlignedBox3::GetMinDistance(const Plane3 &near) const 1041 1041 { 1042 1042 return near.mNormal.x * ((near.mNormal.x > 0.0f) ? mMin.x : mMax.x) + 1043 1043 near.mNormal.y * ((near.mNormal.y > 0.0f) ? mMin.y : mMax.y) + 1044 1044 near.mNormal.z * ((near.mNormal.z > 0.0f) ? mMin.z : mMax.z) + 1045 near.mD; 1046 } 1047 1048 1049 float AxisAlignedBox3::GetMaxDistance(const Plane3 &near) const 1050 { 1051 return near.mNormal.x * ((near.mNormal.x <= 0.0f) ? mMin.x : mMax.x) + 1052 near.mNormal.y * ((near.mNormal.y <= 0.0f) ? mMin.y : mMax.y) + 1053 near.mNormal.z * ((near.mNormal.z <= 0.0f) ? mMin.z : mMax.z) + 1045 1054 near.mD; 1046 1055 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/AxisAlignedBox3.h
r2929 r2947 190 190 is closest to it (this vertex is unequivocally identified by the direction of the vector) 191 191 */ 192 float GetMinVisibleDistance(const Plane3 &near) const; 192 float GetMinDistance(const Plane3 &near) const; 193 /** Returns the distance between the plane given by 'vecNearplaneNormal' and the vertex that 194 is farthest to it (this vertex is unequivocally identified by the direction of the vector) 195 */ 196 float GetMaxDistance(const Plane3 &near) const; 197 193 198 /** Returns cross section of the plane as a polygon. 194 199 */ -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.cpp
r2911 r2947 389 389 390 390 391 void Bvh::CalcDistance(BvhNode *node) const 392 { 393 node->mDistance = node->GetBox().GetMinVisibleDistance(sNearPlane); 391 void Bvh::UpdateMinDistance(BvhNode *node) const 392 { 393 node->mDistance = node->GetBox().GetMinDistance(sNearPlane); 394 } 395 396 397 float Bvh::CalcMaxDistance(BvhNode *node) const 398 { 399 return node->GetBox().GetMaxDistance(sNearPlane); 394 400 } 395 401 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.h
r2897 r2947 85 85 bool IsVirtualLeaf() const { return mIsVirtualLeaf; } 86 86 87 /** Returns the stored distance to the near plane. 88 */ 89 float GetDistance() const { return mDistance; } 90 87 91 88 92 //////////////// … … 405 409 bool operator() (BvhNode *v1, BvhNode *v2) const 406 410 { 407 return (v1-> mDistance > v2->mDistance);411 return (v1->GetDistance() > v2->GetDistance()); 408 412 } 409 413 }; … … 520 524 */ 521 525 void InitFrame(Camera *camera); 522 /** This gives the orthogonal distance from the viewpoint to the nearest bounding box vertex 523 note that negative values can appear because culling is done only afterwards 524 */ 525 void CalcDistance(BvhNode *node) const; 526 /** Returns the stored distance. 527 */ 528 float GetDistance(BvhNode *node) const { return node->mDistance; } 526 /** Stores the orthogonal distance from the viewpoint 527 to the nearest bounding box vertex with the node. 528 Note that negative values can appear because culling is done only afterwards 529 */ 530 void UpdateMinDistance(BvhNode *node) const; 531 /** Returns the maximum distance from the near plane to this node. 532 */ 533 float CalcMaxDistance(BvhNode *node) const; 529 534 /** Pulls up the last visited classification in the bvh. 530 535 */ -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.cpp
r2944 r2947 137 137 Vector3 &ntl, Vector3 &ntr, Vector3 &nbl, Vector3 &nbr, 138 138 const Vector3 &view, const Vector3 &right, const Vector3 &up, 139 const Vector3 &pos) const 139 const Vector3 &pos, 140 float farthestVisibleDistance) const 140 141 { 141 142 float z_near = mNear; 142 float z_far = m Far;143 float z_far = min(mFar, farthestVisibleDistance); 143 144 144 145 float fov = mFovy; … … 177 178 178 179 void Camera::ComputePoints(Vector3 &ftl, Vector3 &ftr, Vector3 &fbl, Vector3 &fbr, 179 Vector3 &ntl, Vector3 &ntr, Vector3 &nbl, Vector3 &nbr) const 180 Vector3 &ntl, Vector3 &ntr, Vector3 &nbl, Vector3 &nbr, 181 float farthestVisibleDistance) const 180 182 { 181 183 ComputePointsInternal(ftl, ftr, fbl, fbr, ntl, ntr, nbl, nbr, 182 GetDirection(), GetRightVector(), GetUpVector(), GetPosition()); 183 } 184 185 186 void Camera::ComputeBasePoints(Vector3 &ftl, Vector3 &ftr, Vector3 &fbl, Vector3 &fbr, 187 Vector3 &ntl, Vector3 &ntr, Vector3 &nbl, Vector3 &nbr) const 188 { 189 ComputePointsInternal(ftl, ftr, fbl, fbr, ntl, ntr, nbl, nbr, 190 GetBaseDirection(), GetBaseRightVector(), GetBaseUpVector(), Vector3(0, 0, 0)); 191 } 192 184 GetDirection(), GetRightVector(), GetUpVector(), GetPosition(), 185 farthestVisibleDistance); 186 } 193 187 194 188 … … 334 328 335 329 336 Polyhedron *Camera::ComputeFrustum( ) const330 Polyhedron *Camera::ComputeFrustum(float farthestVisibleDistance) const 337 331 { 338 332 Vector3 ftl, ftr, fbl, fbr; … … 341 335 VertexArray sides[6]; 342 336 343 ComputePoints(ftl, ftr, fbl, fbr, ntl, ntr, nbl, nbr );337 ComputePoints(ftl, ftr, fbl, fbr, ntl, ntr, nbl, nbr, farthestVisibleDistance); 344 338 345 339 for (int i = 0; i < 6; ++ i) -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.h
r2936 r2947 80 80 void CalcFrustum(Frustum &frustum); 81 81 /** Computes the extremal points of this frustum. 82 If farthestVisibleDistance is nearer than the far plane, 83 it is used to define the far plane instead. 82 84 */ 83 85 void ComputePoints(Vector3 &ftl, Vector3 &ftr, Vector3 &fbl, Vector3 &fbr, 84 Vector3 &ntl, Vector3 &ntr, Vector3 &nbl, Vector3 &nbr) const; 85 /** Computes the extremal points of the base frustum. 86 */ 87 void ComputeBasePoints(Vector3 &ftl, Vector3 &ftr, Vector3 &fbl, Vector3 &fbr, 88 Vector3 &ntl, Vector3 &ntr, Vector3 &nbl, Vector3 &nbr) const; 86 Vector3 &ntl, Vector3 &ntr, Vector3 &nbl, Vector3 &nbr, 87 float farthestVisibleDistance = 1e25f) const; 89 88 /** Returns the near plane. 90 89 */ … … 111 110 */ 112 111 void SetDirection(const Vector3 &direction); 113 /** Returns frustum as polyhedron. 112 /** Returns frustum as polyhedron. 114 113 */ 115 Polyhedron *C amera::ComputeFrustum() const;114 Polyhedron *ComputeFrustum(float farthestVisibleDistance = 1e25f) const; 116 115 117 116 protected: … … 124 123 Vector3 &ntl, Vector3 &ntr, Vector3 &nbl, Vector3 &nbr, 125 124 const Vector3 &view, const Vector3 &right, const Vector3 &up, 126 const Vector3 &pos) const; 125 const Vector3 &pos, 126 float farthestVisibleDistance = 1e25f) const; 127 127 128 128 //////////////// -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderTraverser.cpp
r2897 r2947 51 51 mUseTightBounds(false), 52 52 mShowBounds(false), 53 mRenderQueue(NULL) 53 mRenderQueue(NULL), 54 mMaxVisibleDistance(.0f) 54 55 { 55 56 } … … 64 65 void RenderTraverser::EnqueueNode(BvhNode *node) 65 66 { 66 mBvh-> CalcDistance(node);67 mBvh->UpdateMinDistance(node); 67 68 mDistanceQueue.push(node); 68 69 } … … 78 79 79 80 if (mShowBounds) 80 mBvh->RenderBoundsForViz(node, mRenderState, mUseTightBounds); 81 mBvh->RenderBoundsForViz(node, mRenderState, mUseTightBounds); 81 82 } 82 83 else … … 93 94 void RenderTraverser::RenderNode(BvhNode *node) 94 95 { 96 // test if node was already rendered in this frame 95 97 if (node->GetLastRenderedFrame() != mFrameId) 96 98 { … … 120 122 if (mUseDepthPass) 121 123 mVisibleObjects.push_back(ent); 122 } 124 } 125 126 // store the max distance in the scene for later use 127 float maxDist = mBvh->CalcMaxDistance(node); 128 129 if (maxDist > mMaxVisibleDistance) 130 mMaxVisibleDistance = maxDist; 123 131 } 124 132 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderTraverser.h
r2897 r2947 133 133 */ 134 134 Camera *GetCamera() const { return mCamera; } 135 /** Returns the maximal visible distance encountered in the scene. 136 Useful for e.g., shadow map focussing 137 */ 138 float GetMaxVisibleDistance() const { return mMaxVisibleDistance; } 135 139 136 140 … … 187 191 SceneEntityContainer mVisibleObjects; 188 192 193 /// the maximal visible distance in the scene 194 float mMaxVisibleDistance; 189 195 190 196 ///////////////// 191 //-- algorithm paramete s197 //-- algorithm parameters 192 198 193 199 int mVisibilityThreshold; … … 213 219 inline bool RenderTraverser::IntersectsNearPlane(BvhNode *node) const 214 220 { 215 return mBvh->GetDistance(node) < mCamera->GetNear();221 return node->GetDistance() < mCamera->GetNear(); 216 222 } 217 223 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.cpp
r2945 r2947 141 141 { 142 142 mFbo = new FrameBufferObject(size, size, FrameBufferObject::DEPTH_32, true); 143 // the diffuse color buffer143 // need a color buffer to keep opengl happy 144 144 mFbo->AddColorBuffer(ColorBufferObject::BUFFER_UBYTE, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false); 145 //mFbo->AddColorBuffer(ColorBufferObject::BUFFER_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, false); 146 147 mShadowCam = new Camera(mSize, mSize);//mSceneBox.Size().x * 0.5f, mSceneBox.Size().y * 0.5f); 145 146 mShadowCam = new Camera(mSize, mSize); 148 147 mShadowCam->SetOrtho(true); 149 148 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.h
r2944 r2947 57 57 58 58 void RenderShadowView(RenderTraverser *renderer, const Matrix4x4 &projView); 59 60 59 61 60 static void DrawPolys();
Note: See TracChangeset
for help on using the changeset viewer.