More more occlusion culling.
This commit is contained in:
@@ -75,6 +75,7 @@ DEMOS_DIRS = \
|
||||
osgcube\
|
||||
osghud\
|
||||
osgimpostor\
|
||||
osgoccluder\
|
||||
osgparticle\
|
||||
osgreflect\
|
||||
osgscribe\
|
||||
|
||||
190
VisualStudio/Demos/osgoccluder/osgoccluder.dsp
Normal file
190
VisualStudio/Demos/osgoccluder/osgoccluder.dsp
Normal file
@@ -0,0 +1,190 @@
|
||||
# Microsoft Developer Studio Project File - Name="Demo osgoccluder" - Package Owner=<4>
|
||||
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
|
||||
|
||||
# TARGTYPE "Win32 (x86) Console Application" 0x0103
|
||||
|
||||
|
||||
|
||||
CFG=Demo osgoccluder - Win32 Release
|
||||
|
||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||
|
||||
!MESSAGE use the Export Makefile command and run
|
||||
|
||||
!MESSAGE
|
||||
|
||||
!MESSAGE NMAKE /f "osgoccluder.mak".
|
||||
|
||||
!MESSAGE
|
||||
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
|
||||
!MESSAGE
|
||||
|
||||
!MESSAGE NMAKE /f "osgoccluder.mak" CFG="Demo osgoccluder - Win32 Release"
|
||||
|
||||
!MESSAGE
|
||||
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
|
||||
!MESSAGE
|
||||
|
||||
!MESSAGE "Demo osgoccluder - Win32 Release" (based on "Win32 (x86) Console Application")
|
||||
|
||||
!MESSAGE "Demo osgoccluder - Win32 Debug" (based on "Win32 (x86) Console Application")
|
||||
|
||||
!MESSAGE
|
||||
|
||||
|
||||
|
||||
# Begin Project
|
||||
|
||||
# PROP AllowPerConfigDependencies 0
|
||||
|
||||
# PROP Scc_ProjName ""
|
||||
|
||||
# PROP Scc_LocalPath ""
|
||||
|
||||
CPP=cl.exe
|
||||
|
||||
RSC=rc.exe
|
||||
|
||||
|
||||
|
||||
!IF "$(CFG)" == "Demo osgoccluder - Win32 Release"
|
||||
|
||||
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
|
||||
# PROP BASE Output_Dir "Release"
|
||||
|
||||
# PROP BASE Intermediate_Dir "Release"
|
||||
|
||||
# PROP BASE Target_Dir ""
|
||||
|
||||
# PROP Use_MFC 0
|
||||
|
||||
# PROP Use_Debug_Libraries 0
|
||||
|
||||
# PROP Output_Dir "Release"
|
||||
|
||||
# PROP Intermediate_Dir "Release"
|
||||
|
||||
# PROP Ignore_Export_Lib 0
|
||||
|
||||
# PROP Target_Dir ""
|
||||
|
||||
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||
|
||||
# ADD CPP /nologo /MD /W3 /GR /GX /O2 /I "../../../include" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||
|
||||
# ADD BASE RSC /l 0x809 /d "NDEBUG"
|
||||
|
||||
# ADD RSC /l 0x809 /d "NDEBUG"
|
||||
|
||||
BSC32=bscmake.exe
|
||||
|
||||
# ADD BASE BSC32 /nologo
|
||||
|
||||
# ADD BSC32 /nologo
|
||||
|
||||
LINK32=link.exe
|
||||
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||
|
||||
# ADD LINK32 /nologo /subsystem:console /pdb:none /machine:I386 /out:"../../../bin/osgoccluder.exe" /libpath:"../../../lib"
|
||||
|
||||
|
||||
|
||||
!ELSEIF "$(CFG)" == "Demo osgoccluder - Win32 Debug"
|
||||
|
||||
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
|
||||
# PROP BASE Output_Dir "Debug"
|
||||
|
||||
# PROP BASE Intermediate_Dir "Debug"
|
||||
|
||||
# PROP BASE Target_Dir ""
|
||||
|
||||
# PROP Use_MFC 0
|
||||
|
||||
# PROP Use_Debug_Libraries 1
|
||||
|
||||
# PROP Output_Dir "Debug"
|
||||
|
||||
# PROP Intermediate_Dir "Debug"
|
||||
|
||||
# PROP Ignore_Export_Lib 0
|
||||
|
||||
# PROP Target_Dir ""
|
||||
|
||||
# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||
|
||||
# ADD CPP /nologo /MDd /W3 /Gm /vd0 /GR /GX /Zi /Od /I "../../../include" /D "_CONSOLE" /D "_MBCS" /D "FL_DLL" /D "WIN32" /D "_DEBUG" /FR /YX /FD /c
|
||||
|
||||
# ADD BASE RSC /l 0x809 /d "_DEBUG"
|
||||
|
||||
# ADD RSC /l 0x809 /d "_DEBUG"
|
||||
|
||||
BSC32=bscmake.exe
|
||||
|
||||
# ADD BASE BSC32 /nologo
|
||||
|
||||
# ADD BSC32 /nologo
|
||||
|
||||
LINK32=link.exe
|
||||
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||
|
||||
# ADD LINK32 glut32.lib glu32.lib opengl32.lib /nologo /subsystem:console /debug /machine:I386 /nodefaultlib:"libcmt" /out:"../../../bin/osgoccluderd.exe" /pdbtype:sept /libpath:"../../../lib"
|
||||
|
||||
# SUBTRACT LINK32 /incremental:no
|
||||
|
||||
|
||||
|
||||
!ENDIF
|
||||
|
||||
|
||||
|
||||
# Begin Target
|
||||
|
||||
|
||||
|
||||
# Name "Demo osgoccluder - Win32 Release"
|
||||
|
||||
# Name "Demo osgoccluder - Win32 Debug"
|
||||
|
||||
# Begin Source File
|
||||
|
||||
|
||||
|
||||
SOURCE=..\..\..\src\Demos\osgoccluder\osgoccluder.cpp
|
||||
|
||||
# End Source File
|
||||
|
||||
# End Target
|
||||
|
||||
# Begin Group "Resource Files"
|
||||
|
||||
|
||||
|
||||
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
|
||||
|
||||
# End Group
|
||||
|
||||
# End Project
|
||||
|
||||
@@ -726,6 +726,60 @@ Package=<4>
|
||||
|
||||
|
||||
|
||||
Project: "Demo osgoccluder"=.\Demos\osgoccluder\osgoccluder.dsp - Package Owner=<4>
|
||||
|
||||
|
||||
|
||||
Package=<5>
|
||||
|
||||
{{{
|
||||
|
||||
}}}
|
||||
|
||||
|
||||
|
||||
Package=<4>
|
||||
|
||||
{{{
|
||||
|
||||
Begin Project Dependency
|
||||
|
||||
Project_Dep_Name Core osg
|
||||
|
||||
End Project Dependency
|
||||
|
||||
Begin Project Dependency
|
||||
|
||||
Project_Dep_Name Core osgDB
|
||||
|
||||
End Project Dependency
|
||||
|
||||
Begin Project Dependency
|
||||
|
||||
Project_Dep_Name Core osgGA
|
||||
|
||||
End Project Dependency
|
||||
|
||||
Begin Project Dependency
|
||||
|
||||
Project_Dep_Name Core osgGLUT
|
||||
|
||||
End Project Dependency
|
||||
|
||||
Begin Project Dependency
|
||||
|
||||
Project_Dep_Name Core osgUtil
|
||||
|
||||
End Project Dependency
|
||||
|
||||
}}}
|
||||
|
||||
|
||||
|
||||
###############################################################################
|
||||
|
||||
|
||||
|
||||
Project: "Demo osgreflect"=.\Demos\osgreflect\osgreflect.dsp - Package Owner=<4>
|
||||
|
||||
|
||||
|
||||
@@ -53,11 +53,19 @@ Unix</li>
|
||||
|
||||
<ul><b>export PATH = ${PATH}:/home/myaccount/OpenSceneGraph/bin</b>
|
||||
<br><b>export LD_LIBRARY_PATH = ${LD_LIBRARY_PATH}:/home/myaccount/OpenSceneGraph/lib</b>
|
||||
<br><b>export OSG_FILE_PATH = /home/myaccount/OpenSceneGraph-Data:C:/OpenSceneGraph-Data/Images:C:/OpenSceneGraph-Data/Fonts</b>
|
||||
<br><b>export OSG_FILE_PATH = /home/myaccount/OpenSceneGraph-Data:/home/myaccount/OpenSceneGraph-Data/Images:/home/myaccount/OpenSceneGraph-Data/Fonts</b>
|
||||
<br>or
|
||||
<br><b>setenv PATH ${PATH}:/home/myaccount/OpenSceneGraph/bin</b>
|
||||
<br><b>setenv LD_LIBRARY_PATH = ${LD_LIBRARY_PATH}:/home/myaccount/OpenSceneGraph/lib</b>
|
||||
<br><b>setenv OSG_FILE_PATH /home/myaccount/OpenSceneGraph-Data:C:/OpenSceneGraph-Data/Images:C:/OpenSceneGraph-Data/Fonts</b></ul>
|
||||
<br><b>setenv OSG_FILE_PATH /home/myaccount/OpenSceneGraph-Data:/home/myaccount/OpenSceneGraph-Data/Images:/home/myaccount/OpenSceneGraph-Data/Fonts</b></ul>
|
||||
|
||||
<li>
|
||||
MacOSX:</li>
|
||||
|
||||
<ul><b>setenv PATH "${PATH}:${OSGHOME}/lib:${OSGHOME}/lib/osgPlugins"</b>
|
||||
<br><b>setenv DYLD_LIBRARY_PATH "${OSGHOME}/lib:${OSGHOME}/lib/osgPlugins"</b>
|
||||
<br><b>setenv OSG_FILE_PATH "/home/myaccount/OpenSceneGraph-Data:/home/myaccount/OpenSceneGraph-Data/Images:/home/myaccount/OpenSceneGraph-Data/Fonts"</b></ul>
|
||||
|
||||
All the demos run on the commandline, most requiring parameters, such as
|
||||
what file to load, if you are in any doubt just run the application and
|
||||
it will either run, or provide help on what options it accepts.
|
||||
|
||||
@@ -77,6 +77,23 @@ class SG_EXPORT CullingSet : public Referenced
|
||||
/** Compute the pixel of an bounding sphere.*/
|
||||
float pixelSize(const BoundingSphere& bs) const { return bs.radius()/(bs.center()*_pixelSizeVector); }
|
||||
|
||||
inline void disableOccluder(NodePath& nodePath)
|
||||
{
|
||||
for(OccluderList::iterator itr=_occluderList.begin();
|
||||
itr!=_occluderList.end();
|
||||
++itr)
|
||||
{
|
||||
if (itr->getNodePath()==nodePath)
|
||||
{
|
||||
// we have trapped for the case an occlude potentially occluding itself,
|
||||
// to prevent this we disable the results mask so that no subsequnt
|
||||
// when the next pushCurrentMask calls happens this occluder is switched off.
|
||||
itr->disableResultMasks();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline bool isCulled(const BoundingBox& bb)
|
||||
{
|
||||
if (_mask&VIEW_FRUSTUM_CULLING)
|
||||
|
||||
@@ -25,7 +25,7 @@ class SG_EXPORT Polytope
|
||||
|
||||
inline Polytope(const Polytope& cv) :
|
||||
_maskStack(cv._maskStack),
|
||||
_resultsMask(cv._resultsMask),
|
||||
_resultMask(cv._resultMask),
|
||||
_planeList(cv._planeList) {}
|
||||
|
||||
inline Polytope(const PlaneList& pl) : _planeList(pl) {setupMask();}
|
||||
@@ -38,7 +38,7 @@ class SG_EXPORT Polytope
|
||||
{
|
||||
if (&cv==this) return *this;
|
||||
_maskStack = cv._maskStack;
|
||||
_resultsMask = cv._resultsMask;
|
||||
_resultMask = cv._resultMask;
|
||||
_planeList = cv._planeList;
|
||||
return *this;
|
||||
}
|
||||
@@ -76,26 +76,27 @@ class SG_EXPORT Polytope
|
||||
|
||||
inline void setupMask()
|
||||
{
|
||||
_resultsMask = 0;
|
||||
_resultMask = 0;
|
||||
for(unsigned int i=0;i<_planeList.size();++i)
|
||||
{
|
||||
_resultsMask = (_resultsMask<<1) | 1;
|
||||
_resultMask = (_resultMask<<1) | 1;
|
||||
}
|
||||
_maskStack.back() = _resultsMask;
|
||||
_maskStack.back() = _resultMask;
|
||||
}
|
||||
|
||||
inline ClippingMask& getCurrentMask() { return _maskStack.back(); }
|
||||
|
||||
inline ClippingMask getCurrentMask() const { return _maskStack.back(); }
|
||||
|
||||
inline ClippingMask getResultsMask() const
|
||||
{
|
||||
return _resultsMask;
|
||||
}
|
||||
inline void setResultMask(ClippingMask mask) { _resultMask=mask; }
|
||||
|
||||
inline ClippingMask getResultMask() const { return _resultMask; }
|
||||
|
||||
|
||||
|
||||
inline void pushCurrentMask()
|
||||
{
|
||||
_maskStack.push_back(_resultsMask);
|
||||
_maskStack.push_back(_resultMask);
|
||||
}
|
||||
|
||||
inline void popCurrentMask()
|
||||
@@ -128,18 +129,18 @@ class SG_EXPORT Polytope
|
||||
{
|
||||
if (!_maskStack.back()) return true;
|
||||
|
||||
_resultsMask = _maskStack.back();
|
||||
_resultMask = _maskStack.back();
|
||||
ClippingMask selector_mask = 0x1;
|
||||
|
||||
for(PlaneList::const_iterator itr=_planeList.begin();
|
||||
itr!=_planeList.end();
|
||||
++itr)
|
||||
{
|
||||
if (_resultsMask&selector_mask)
|
||||
if (_resultMask&selector_mask)
|
||||
{
|
||||
int res=itr->intersect(bs);
|
||||
if (res<0) return false; // outside clipping set.
|
||||
else if (res>0) _resultsMask ^= selector_mask; // subsequent checks against this plane not required.
|
||||
else if (res>0) _resultMask ^= selector_mask; // subsequent checks against this plane not required.
|
||||
}
|
||||
selector_mask <<= 1;
|
||||
}
|
||||
@@ -155,18 +156,18 @@ class SG_EXPORT Polytope
|
||||
{
|
||||
if (!_maskStack.back()) return true;
|
||||
|
||||
_resultsMask = _maskStack.back();
|
||||
_resultMask = _maskStack.back();
|
||||
ClippingMask selector_mask = 0x1;
|
||||
|
||||
for(PlaneList::const_iterator itr=_planeList.begin();
|
||||
itr!=_planeList.end();
|
||||
++itr)
|
||||
{
|
||||
if (_resultsMask&selector_mask)
|
||||
if (_resultMask&selector_mask)
|
||||
{
|
||||
int res=itr->intersect(bb);
|
||||
if (res<0) return false; // outside clipping set.
|
||||
else if (res>0) _resultsMask ^= selector_mask; // subsequent checks against this plane not required.
|
||||
else if (res>0) _resultMask ^= selector_mask; // subsequent checks against this plane not required.
|
||||
}
|
||||
selector_mask <<= 1;
|
||||
}
|
||||
@@ -178,18 +179,18 @@ class SG_EXPORT Polytope
|
||||
{
|
||||
if (!_maskStack.back()) return false;
|
||||
|
||||
_resultsMask = _maskStack.back();
|
||||
_resultMask = _maskStack.back();
|
||||
ClippingMask selector_mask = 0x1;
|
||||
|
||||
for(PlaneList::const_iterator itr=_planeList.begin();
|
||||
itr!=_planeList.end();
|
||||
++itr)
|
||||
{
|
||||
if (_resultsMask&selector_mask)
|
||||
if (_resultMask&selector_mask)
|
||||
{
|
||||
int res=itr->intersect(bs);
|
||||
if (res<1) return false; // intersects, or is below plane.
|
||||
_resultsMask ^= selector_mask; // subsequent checks against this plane not required.
|
||||
_resultMask ^= selector_mask; // subsequent checks against this plane not required.
|
||||
}
|
||||
selector_mask <<= 1;
|
||||
}
|
||||
@@ -201,18 +202,18 @@ class SG_EXPORT Polytope
|
||||
{
|
||||
if (!_maskStack.back()) return false;
|
||||
|
||||
_resultsMask = _maskStack.back();
|
||||
_resultMask = _maskStack.back();
|
||||
ClippingMask selector_mask = 0x1;
|
||||
|
||||
for(PlaneList::const_iterator itr=_planeList.begin();
|
||||
itr!=_planeList.end();
|
||||
++itr)
|
||||
{
|
||||
if (_resultsMask&selector_mask)
|
||||
if (_resultMask&selector_mask)
|
||||
{
|
||||
int res=itr->intersect(bb);
|
||||
if (res<1) return false; // intersects, or is below plane.
|
||||
_resultsMask ^= selector_mask; // subsequent checks against this plane not required.
|
||||
_resultMask ^= selector_mask; // subsequent checks against this plane not required.
|
||||
}
|
||||
selector_mask <<= 1;
|
||||
}
|
||||
@@ -239,13 +240,13 @@ class SG_EXPORT Polytope
|
||||
{
|
||||
if (!_maskStack.back()) return;
|
||||
|
||||
_resultsMask = _maskStack.back();
|
||||
_resultMask = _maskStack.back();
|
||||
ClippingMask selector_mask = 0x1;
|
||||
for(PlaneList::iterator itr=_planeList.begin();
|
||||
itr!=_planeList.end();
|
||||
++itr)
|
||||
{
|
||||
if (_resultsMask&selector_mask)
|
||||
if (_resultMask&selector_mask)
|
||||
{
|
||||
itr->transformProvidingInverse(matrix);
|
||||
selector_mask <<= 1;
|
||||
@@ -257,7 +258,7 @@ class SG_EXPORT Polytope
|
||||
|
||||
|
||||
fast_back_stack<ClippingMask> _maskStack;
|
||||
ClippingMask _resultsMask;
|
||||
ClippingMask _resultMask;
|
||||
PlaneList _planeList;
|
||||
|
||||
};
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <osg/ref_ptr>
|
||||
#include <osg/Polytope>
|
||||
#include <osg/ConvexPlanerOccluder>
|
||||
#include <osg/Node>
|
||||
|
||||
namespace osg {
|
||||
|
||||
@@ -21,6 +22,7 @@ class SG_EXPORT ShadowOccluderVolume
|
||||
typedef std::vector<Polytope> HoleList;
|
||||
|
||||
ShadowOccluderVolume(const ShadowOccluderVolume& soc):
|
||||
_nodePath(soc._nodePath),
|
||||
_occluderVolume(soc._occluderVolume),
|
||||
_holeList(soc._holeList) {}
|
||||
|
||||
@@ -28,9 +30,18 @@ class SG_EXPORT ShadowOccluderVolume
|
||||
|
||||
ShadowOccluderVolume(const ConvexPlanerOccluder& occluder,Matrix& MVP);
|
||||
|
||||
inline void disableResultMasks();
|
||||
|
||||
inline void pushCurrentMask();
|
||||
inline void popCurrentMask();
|
||||
|
||||
/** Set the NodePath which describes the which node in the scene graph
|
||||
* that this occluder was attached to.*/
|
||||
inline void setNodePath(NodePath& nodePath) { _nodePath = nodePath; }
|
||||
inline NodePath& getNodePath() { return _nodePath; }
|
||||
inline const NodePath& getNodePath() const { return _nodePath; }
|
||||
|
||||
|
||||
/** Convert shadow occluder into local coords by multiplying the
|
||||
* clip space occluder by the ModelViewProjectionMatrix.*/
|
||||
void set(const ShadowOccluderVolume& soc,Matrix& MVP);
|
||||
@@ -60,11 +71,23 @@ class SG_EXPORT ShadowOccluderVolume
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
NodePath _nodePath;
|
||||
Polytope _occluderVolume;
|
||||
HoleList _holeList;
|
||||
};
|
||||
|
||||
inline void ShadowOccluderVolume::disableResultMasks()
|
||||
{
|
||||
_occluderVolume.setResultMask(0);
|
||||
for(HoleList::iterator itr=_holeList.begin();
|
||||
itr!=_holeList.end();
|
||||
++itr)
|
||||
{
|
||||
itr->setResultMask(0);
|
||||
}
|
||||
}
|
||||
|
||||
inline void ShadowOccluderVolume::pushCurrentMask()
|
||||
{
|
||||
_occluderVolume.pushCurrentMask();
|
||||
|
||||
@@ -715,9 +715,11 @@ void CullVisitor::apply(osg::OccluderNode& node)
|
||||
{
|
||||
// need to check if occlusion node is in the occluder
|
||||
// list, if so disable the appropriate ShadowOccluderVolume
|
||||
_modelviewCullingStack.back()->disableOccluder(_nodePath);
|
||||
|
||||
std::cout<<"We are in an Occlusion node"<<&node<<std::endl;
|
||||
|
||||
|
||||
if (isCulled(node)) return;
|
||||
|
||||
// push the culling mode.
|
||||
|
||||
Reference in New Issue
Block a user