Further work on occludision code.
This commit is contained in:
parent
fa13d948b5
commit
c7e99ff77a
@ -317,7 +317,7 @@ SOURCE=..\..\src\osg\ShadeModel.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\src\osg\ShadowOccluderVolume.cpp
|
||||
SOURCE=..\..\src\osg\ShadowVolumeOccluder.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
@ -649,7 +649,7 @@ SOURCE=..\..\Include\Osg\ShadeModel
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Include\Osg\ShadowOccluderVolume
|
||||
SOURCE=..\..\Include\Osg\ShadowVolumeOccluder
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
|
@ -79,6 +79,11 @@ class SG_EXPORT CullStack
|
||||
_modelviewCullingStack.back()->disableOccluder(nodePath);
|
||||
}
|
||||
|
||||
inline bool isCulled(const std::vector<Vec3>& vertices)
|
||||
{
|
||||
return _modelviewCullingStack.back()->isCulled(vertices);
|
||||
}
|
||||
|
||||
inline bool isCulled(const BoundingBox& bb)
|
||||
{
|
||||
return bb.isValid() && _modelviewCullingStack.back()->isCulled(bb);
|
||||
|
@ -94,6 +94,35 @@ class SG_EXPORT CullingSet : public Referenced
|
||||
}
|
||||
|
||||
|
||||
inline bool isCulled(const std::vector<Vec3>& vertices)
|
||||
{
|
||||
if (_mask&VIEW_FRUSTUM_CULLING)
|
||||
{
|
||||
// is it outside the view frustum...
|
||||
if (!_frustum.contains(vertices)) return true;
|
||||
}
|
||||
|
||||
if (_mask&SMALL_FEATURE_CULLING)
|
||||
{
|
||||
}
|
||||
|
||||
if (_mask&SHADOW_OCCLUSION_CULLING)
|
||||
{
|
||||
// is it in one of the shadow occluder volumes.
|
||||
if (!_occluderList.empty())
|
||||
{
|
||||
for(OccluderList::iterator itr=_occluderList.begin();
|
||||
itr!=_occluderList.end();
|
||||
++itr)
|
||||
{
|
||||
if (itr->contains(vertices)) return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
inline bool isCulled(const BoundingBox& bb)
|
||||
{
|
||||
if (_mask&VIEW_FRUSTUM_CULLING)
|
||||
|
@ -11,6 +11,8 @@
|
||||
#include <osg/BoundingSphere>
|
||||
#include <osg/BoundingBox>
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace osg {
|
||||
|
||||
/** A plane class. It can be used to represent an infinite plane.*/
|
||||
@ -89,6 +91,35 @@ class SG_EXPORT Plane
|
||||
_fv[3];
|
||||
}
|
||||
|
||||
/** intersection test between plane and vertex list
|
||||
return 1 if the bs is completely above plane,
|
||||
return 0 if the bs intersects the plane,
|
||||
return -1 if the bs is completely below the plane.*/
|
||||
inline const int intersect(const std::vector<Vec3>& vertices) const
|
||||
{
|
||||
if (vertices.empty()) return -1;
|
||||
|
||||
int noAbove = 0;
|
||||
int noBelow = 0;
|
||||
int noOn = 0;
|
||||
for(std::vector<Vec3>::const_iterator itr=vertices.begin();
|
||||
itr != vertices.end();
|
||||
++itr)
|
||||
{
|
||||
float d = distance(*itr);
|
||||
if (d>0.0f) ++noAbove;
|
||||
else if (d<0.0f) ++noBelow;
|
||||
else ++noOn;
|
||||
}
|
||||
|
||||
if (noAbove>0)
|
||||
{
|
||||
if (noBelow>0) return 0;
|
||||
else return 1;
|
||||
}
|
||||
return -1; // treat points on line as outside...
|
||||
}
|
||||
|
||||
/** intersection test between plane and bounding sphere.
|
||||
return 1 if the bs is completely above plane,
|
||||
return 0 if the bs intersects the plane,
|
||||
|
@ -120,6 +120,29 @@ class SG_EXPORT Polytope
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Check whether any part of vertex list is contained with clipping set.*/
|
||||
inline const bool contains(const std::vector<Vec3>& vertices)
|
||||
{
|
||||
if (!_maskStack.back()) return true;
|
||||
|
||||
_resultMask = _maskStack.back();
|
||||
ClippingMask selector_mask = 0x1;
|
||||
|
||||
for(PlaneList::const_iterator itr=_planeList.begin();
|
||||
itr!=_planeList.end();
|
||||
++itr)
|
||||
{
|
||||
if (_resultMask&selector_mask)
|
||||
{
|
||||
int res=itr->intersect(vertices);
|
||||
if (res<0) return false; // outside clipping set.
|
||||
else if (res>0) _resultMask ^= selector_mask; // subsequent checks against this plane not required.
|
||||
}
|
||||
selector_mask <<= 1;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Check whether any part of a bounding sphere is contained within clipping set.
|
||||
Using a mask to determine which planes should be used for the check, and
|
||||
modifying the mask to turn off planes which wouldn't contribute to clipping
|
||||
@ -174,6 +197,29 @@ class SG_EXPORT Polytope
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Check whether all of vertex list is contained with clipping set.*/
|
||||
inline const bool containsAllOf(const std::vector<Vec3>& vertices)
|
||||
{
|
||||
if (!_maskStack.back()) return false;
|
||||
|
||||
_resultMask = _maskStack.back();
|
||||
ClippingMask selector_mask = 0x1;
|
||||
|
||||
for(PlaneList::const_iterator itr=_planeList.begin();
|
||||
itr!=_planeList.end();
|
||||
++itr)
|
||||
{
|
||||
if (_resultMask&selector_mask)
|
||||
{
|
||||
int res=itr->intersect(vertices);
|
||||
if (res<1) return false; // intersects, or is below plane.
|
||||
_resultMask ^= selector_mask; // subsequent checks against this plane not required.
|
||||
}
|
||||
selector_mask <<= 1;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Check whether the entire bounding sphere is contained within clipping set.*/
|
||||
inline const bool containsAllOf(const osg::BoundingSphere& bs)
|
||||
{
|
||||
|
@ -49,6 +49,10 @@ class SG_EXPORT ShadowVolumeOccluder
|
||||
|
||||
float quality() { return _quality; }
|
||||
|
||||
/** return true if the specified vertex list is contaned entirely
|
||||
* within this shadow occluder volume.*/
|
||||
bool contains(const std::vector<Vec3>& vertices);
|
||||
|
||||
/** return true if the specified bounding sphere is contaned entirely
|
||||
* within this shadow occluder volume.*/
|
||||
bool contains(const BoundingSphere& bound);
|
@ -100,14 +100,23 @@ void CollectOccludersVisitor::apply(osg::OccluderNode& node)
|
||||
// list, if so disable the appropriate ShadowOccluderVolume
|
||||
disableOccluder(_nodePath);
|
||||
|
||||
std::cout<<"CollectOccludersVisitor:: We have found an Occlusion node in frustum"<<&node<<std::endl;
|
||||
|
||||
|
||||
if (isCulled(node)) return;
|
||||
|
||||
std::cout<<"CollectOccludersVisitor:: We have found an Occlusion node in frustum"<<&node<<std::endl;
|
||||
|
||||
// push the culling mode.
|
||||
pushCurrentMask();
|
||||
|
||||
|
||||
if (node.getOccluder()&& !isCulled(node.getOccluder()->getOccluder().getVertexList()))
|
||||
{
|
||||
|
||||
// need to test occluder against view frustum.
|
||||
std::cout << " adding in Occluder"<<std::endl;
|
||||
_occluderList.push_back(ShadowVolumeOccluder(_nodePath, *node.getOccluder(), getModelViewMatrix()));
|
||||
}
|
||||
|
||||
traverse(node);
|
||||
|
||||
// pop the culling mode.
|
||||
|
@ -58,7 +58,7 @@ CXXFILES =\
|
||||
Projection.cpp\
|
||||
Quat.cpp\
|
||||
ShadeModel.cpp\
|
||||
ShadowOccluderVolume.cpp\
|
||||
ShadowVolumeOccluder.cpp\
|
||||
State.cpp\
|
||||
StateSet.cpp\
|
||||
Stencil.cpp\
|
||||
|
@ -5,6 +5,22 @@ using namespace osg;
|
||||
|
||||
void ShadowVolumeOccluder::computeOccluder(const NodePath& nodePath,const ConvexPlanerOccluder& occluder,const Matrix& MVP)
|
||||
{
|
||||
std::cout<<" Computing Occluder"<<std::endl;
|
||||
}
|
||||
|
||||
bool ShadowVolumeOccluder::contains(const std::vector<Vec3>& vertices)
|
||||
{
|
||||
if (_occluderVolume.containsAllOf(vertices))
|
||||
{
|
||||
for(HoleList::iterator itr=_holeList.begin();
|
||||
itr!=_holeList.end();
|
||||
++itr)
|
||||
{
|
||||
if (itr->contains(vertices)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ShadowVolumeOccluder::contains(const BoundingSphere& bound)
|
Loading…
Reference in New Issue
Block a user