Changeset 2947


Ignore:
Timestamp:
09/15/08 10:13:33 (16 years ago)
Author:
mattausch
Message:
 
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  
    10381038 
    10391039 
    1040 float AxisAlignedBox3::GetMinVisibleDistance(const Plane3 &near) const 
     1040float AxisAlignedBox3::GetMinDistance(const Plane3 &near) const 
    10411041{ 
    10421042        return  near.mNormal.x * ((near.mNormal.x > 0.0f) ? mMin.x : mMax.x) + 
    10431043                        near.mNormal.y * ((near.mNormal.y > 0.0f) ? mMin.y : mMax.y) + 
    10441044                        near.mNormal.z * ((near.mNormal.z > 0.0f) ? mMin.z : mMax.z) + 
     1045                        near.mD; 
     1046} 
     1047 
     1048 
     1049float 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) + 
    10451054                        near.mD; 
    10461055} 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/AxisAlignedBox3.h

    r2929 r2947  
    190190            is closest to it (this vertex is unequivocally identified by the direction of the vector) 
    191191        */ 
    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         
    193198        /** Returns cross section of the plane as a polygon. 
    194199        */ 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.cpp

    r2911 r2947  
    389389 
    390390 
    391 void Bvh::CalcDistance(BvhNode *node) const 
    392 { 
    393         node->mDistance = node->GetBox().GetMinVisibleDistance(sNearPlane); 
     391void Bvh::UpdateMinDistance(BvhNode *node) const 
     392{ 
     393        node->mDistance = node->GetBox().GetMinDistance(sNearPlane); 
     394} 
     395 
     396 
     397float Bvh::CalcMaxDistance(BvhNode *node) const 
     398{ 
     399        return node->GetBox().GetMaxDistance(sNearPlane); 
    394400} 
    395401 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.h

    r2897 r2947  
    8585        bool IsVirtualLeaf() const { return mIsVirtualLeaf; } 
    8686 
     87        /** Returns the stored distance to the near plane. 
     88        */ 
     89        float GetDistance() const  { return mDistance; } 
     90 
    8791 
    8892        //////////////// 
     
    405409        bool operator() (BvhNode *v1, BvhNode *v2) const 
    406410    { 
    407                 return (v1->mDistance > v2->mDistance); 
     411                return (v1->GetDistance() > v2->GetDistance()); 
    408412    } 
    409413}; 
     
    520524        */ 
    521525        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; 
    529534        /** Pulls up the last visited classification in the bvh. 
    530535        */ 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.cpp

    r2944 r2947  
    137137                                                                   Vector3 &ntl, Vector3 &ntr, Vector3 &nbl, Vector3 &nbr, 
    138138                                                                   const Vector3 &view, const Vector3 &right, const Vector3 &up, 
    139                                                                    const Vector3 &pos) const 
     139                                                                   const Vector3 &pos, 
     140                                                                   float farthestVisibleDistance) const 
    140141{ 
    141142        float z_near = mNear; 
    142         float z_far = mFar; 
     143        float z_far = min(mFar, farthestVisibleDistance); 
    143144 
    144145        float fov = mFovy; 
     
    177178 
    178179void 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 
    180182{ 
    181183        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} 
    193187 
    194188 
     
    334328 
    335329 
    336 Polyhedron *Camera::ComputeFrustum() const 
     330Polyhedron *Camera::ComputeFrustum(float farthestVisibleDistance) const 
    337331{ 
    338332        Vector3 ftl, ftr, fbl, fbr; 
     
    341335        VertexArray sides[6]; 
    342336 
    343         ComputePoints(ftl, ftr, fbl, fbr, ntl, ntr, nbl, nbr); 
     337        ComputePoints(ftl, ftr, fbl, fbr, ntl, ntr, nbl, nbr, farthestVisibleDistance); 
    344338 
    345339        for (int i = 0; i < 6; ++ i) 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.h

    r2936 r2947  
    8080        void CalcFrustum(Frustum &frustum); 
    8181        /** 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. 
    8284        */ 
    8385        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; 
    8988        /** Returns the near plane. 
    9089        */ 
     
    111110        */ 
    112111        void SetDirection(const Vector3 &direction); 
    113         /** Returns frustum as polyhedron. 
     112        /** Returns frustum as polyhedron.  
    114113        */ 
    115         Polyhedron *Camera::ComputeFrustum() const; 
     114        Polyhedron *ComputeFrustum(float farthestVisibleDistance = 1e25f) const; 
    116115 
    117116protected: 
     
    124123                                                           Vector3 &ntl, Vector3 &ntr, Vector3 &nbl, Vector3 &nbr, 
    125124                                                           const Vector3 &view, const Vector3 &right, const Vector3 &up, 
    126                                                            const Vector3 &pos) const; 
     125                                                           const Vector3 &pos, 
     126                                                           float farthestVisibleDistance = 1e25f) const; 
    127127 
    128128        //////////////// 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderTraverser.cpp

    r2897 r2947  
    5151mUseTightBounds(false),  
    5252mShowBounds(false), 
    53 mRenderQueue(NULL) 
     53mRenderQueue(NULL), 
     54mMaxVisibleDistance(.0f) 
    5455{ 
    5556} 
     
    6465void RenderTraverser::EnqueueNode(BvhNode *node) 
    6566{ 
    66         mBvh->CalcDistance(node); 
     67        mBvh->UpdateMinDistance(node); 
    6768        mDistanceQueue.push(node); 
    6869} 
     
    7879 
    7980                if (mShowBounds) 
    80                         mBvh->RenderBoundsForViz(node, mRenderState, mUseTightBounds);           
     81                        mBvh->RenderBoundsForViz(node, mRenderState, mUseTightBounds); 
    8182        } 
    8283        else  
     
    9394void RenderTraverser::RenderNode(BvhNode *node) 
    9495{ 
     96        // test if node was already rendered in this frame 
    9597        if (node->GetLastRenderedFrame() != mFrameId) 
    9698        { 
     
    120122                        if (mUseDepthPass) 
    121123                                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; 
    123131        } 
    124132} 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderTraverser.h

    r2897 r2947  
    133133        */ 
    134134        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; } 
    135139 
    136140 
     
    187191        SceneEntityContainer mVisibleObjects; 
    188192 
     193        /// the maximal visible distance in the scene 
     194        float mMaxVisibleDistance; 
    189195 
    190196        ///////////////// 
    191         //-- algorithm parametes 
     197        //-- algorithm parameters 
    192198 
    193199        int mVisibilityThreshold; 
     
    213219inline bool RenderTraverser::IntersectsNearPlane(BvhNode *node) const 
    214220{  
    215         return mBvh->GetDistance(node) < mCamera->GetNear(); 
     221        return node->GetDistance() < mCamera->GetNear(); 
    216222} 
    217223 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.cpp

    r2945 r2947  
    141141{ 
    142142        mFbo = new FrameBufferObject(size, size, FrameBufferObject::DEPTH_32, true); 
    143         // the diffuse color buffer 
     143        // need a color buffer to keep opengl happy 
    144144        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); 
    148147        mShadowCam->SetOrtho(true); 
    149148} 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.h

    r2944 r2947  
    5757 
    5858        void RenderShadowView(RenderTraverser *renderer, const Matrix4x4 &projView); 
    59  
    6059 
    6160        static void DrawPolys(); 
Note: See TracChangeset for help on using the changeset viewer.