From 33479c77687a4c5b3c6c47f16588448bb9ac5de8 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 17 Oct 2011 14:41:49 +0000 Subject: [PATCH] Improvements to the compute near/far --- include/osgUtil/CullVisitor | 13 +++++-- src/osgUtil/CullVisitor.cpp | 78 ++++++++++++++++--------------------- 2 files changed, 44 insertions(+), 47 deletions(-) diff --git a/include/osgUtil/CullVisitor b/include/osgUtil/CullVisitor index 368917b70..240a54485 100644 --- a/include/osgUtil/CullVisitor +++ b/include/osgUtil/CullVisitor @@ -346,10 +346,17 @@ class OSGUTIL_EXPORT CullVisitor : public osg::NodeVisitor, public osg::CullStac struct MatrixPlanesDrawables { - MatrixPlanesDrawables(const osg::Matrix& matrix, const osg::Drawable* drawable, const osg::Polytope& frustum): - _matrix(matrix), - _drawable(drawable) + MatrixPlanesDrawables(): + _drawable(0) { + } + + void set(const osg::Matrix& matrix, const osg::Drawable* drawable, const osg::Polytope& frustum) + { + _matrix = matrix; + _drawable = drawable; + if (!_planes.empty()) _planes.clear(); + // create a new list of planes from the active walls of the frustum. osg::Polytope::ClippingMask result_mask = frustum.getResultMask(); osg::Polytope::ClippingMask selector_mask = 0x1; diff --git a/src/osgUtil/CullVisitor.cpp b/src/osgUtil/CullVisitor.cpp index 0ee9f79f3..fa01dfd2a 100644 --- a/src/osgUtil/CullVisitor.cpp +++ b/src/osgUtil/CullVisitor.cpp @@ -162,12 +162,12 @@ float CullVisitor::getDistanceFromEyePoint(const osg::Vec3& pos, bool withLODSca void CullVisitor::computeNearPlane() { - //OSG_NOTICE<<"CullVisitor::computeNearPlane()"<second._drawable<<", "<first<<", d_near = "<tick(); - //OSG_NOTICE<<"Took "<delta_m(start_t,end_t)<<"ms to test "<tick(); + OSG_NOTICE<<"Took "<delta_m(start_t,end_t)<<"ms to test "<_computed_zfar) { _computed_zfar = d_far; - // OSG_WARN<<"updating znear to "<<_computed_znear< cnpf; - cnpf.set(_computed_znear, matrix, &planes); + cnpf.set(FLT_MAX, matrix, &planes); drawable.accept(cnpf); @@ -695,7 +700,7 @@ CullVisitor::value_type CullVisitor::computeFurthestPointInFrustum(const osg::Ma //OSG_NOTICE<<"CullVisitor::computeFurthestPointInFrustum("< cnpf; - cnpf.set(_computed_zfar, matrix, &planes); + cnpf.set(-FLT_MAX, matrix, &planes); drawable.accept(cnpf); @@ -834,44 +839,29 @@ bool CullVisitor::updateCalculatedNearFar(const osg::Matrix& matrix,const osg::D osg::Polytope& frustum = getCurrentCullingSet().getFrustum(); if (frustum.getResultMask()) { + MatrixPlanesDrawables mpd; if (isBillboard) { // OSG_WARN<<"Adding billboard into deffered list"<_computed_zfar) - { - _farPlaneCandidateMap.insert(DistanceMatrixDrawableMap::value_type(d_far,mpd) ); - } - } + mpd.set(matrix,&drawable,transformed_frustum); } else { - // insert drawable into the deferred list of drawables which will be handled at the popProjectionMatrix(). - MatrixPlanesDrawables mpd(matrix,&drawable,frustum); - if (d_near<_computed_znear) - { - _nearPlaneCandidateMap.insert(DistanceMatrixDrawableMap::value_type(d_near,mpd) ); - } + mpd.set(matrix,&drawable,frustum); + } - if (_computeNearFar==COMPUTE_NEAR_FAR_USING_PRIMITIVES) + if (d_near<_computed_znear) + { + _nearPlaneCandidateMap.insert(DistanceMatrixDrawableMap::value_type(d_near,mpd) ); + } + + if (_computeNearFar==COMPUTE_NEAR_FAR_USING_PRIMITIVES) + { + if (d_far>_computed_zfar) { - if (d_far>_computed_zfar) - { - _farPlaneCandidateMap.insert(DistanceMatrixDrawableMap::value_type(d_far,mpd) ); - } + _farPlaneCandidateMap.insert(DistanceMatrixDrawableMap::value_type(d_far,mpd) ); } } @@ -879,7 +869,7 @@ bool CullVisitor::updateCalculatedNearFar(const osg::Matrix& matrix,const osg::D // while the final computation for this drawable is deferred. if (d_far>=0.0 && d_far<_computed_znear) { - _computed_znear = d_far; + //_computed_znear = d_far; } if (_computeNearFar==COMPUTE_NEAR_FAR_USING_PRIMITIVES) @@ -888,7 +878,7 @@ bool CullVisitor::updateCalculatedNearFar(const osg::Matrix& matrix,const osg::D // while the final computation for this drawable is deferred. if (d_near>=0.0 && d_near>_computed_zfar) { - _computed_zfar = d_near; + // _computed_zfar = d_near; } } else // computing zfar using bounding sphere