From c9fed221a5484ffa3c1c66c637cf170ff8a64103 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 7 Nov 2006 13:43:01 +0000 Subject: [PATCH] Added initial cut of osgShadow::OccluderGeometry --- VisualStudio/osgShadow/osgShadow.dsp | 8 +++ include/osgShadow/OccluderGeometry | 100 +++++++++++++++++++++++++++ src/osgShadow/GNUmakefile | 1 + src/osgShadow/OccluderGeometry.cpp | 39 +++++++++++ src/osgShadow/ShadowedScene.cpp | 1 - 5 files changed, 148 insertions(+), 1 deletion(-) create mode 100644 include/osgShadow/OccluderGeometry create mode 100644 src/osgShadow/OccluderGeometry.cpp diff --git a/VisualStudio/osgShadow/osgShadow.dsp b/VisualStudio/osgShadow/osgShadow.dsp index 374204bf6..bd44bf806 100644 --- a/VisualStudio/osgShadow/osgShadow.dsp +++ b/VisualStudio/osgShadow/osgShadow.dsp @@ -155,6 +155,10 @@ LIB32=link.exe -lib # PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" # Begin Source File +SOURCE=..\..\src\osgShadow\OccluderGeometry.cpp +# End Source File +# Begin Source File + SOURCE=..\..\src\osgShadow\ShadowedScene.cpp # End Source File # Begin Source File @@ -191,6 +195,10 @@ SOURCE=..\..\include\osgShadow\Export # End Source File # Begin Source File +SOURCE=..\..\include\osgShadow\OccluderGeometry +# End Source File +# Begin Source File + SOURCE=..\..\include\osgShadow\ShadowedScene # End Source File # Begin Source File diff --git a/include/osgShadow/OccluderGeometry b/include/osgShadow/OccluderGeometry new file mode 100644 index 000000000..7cca6b0c7 --- /dev/null +++ b/include/osgShadow/OccluderGeometry @@ -0,0 +1,100 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield + * + * This library is open source and may be redistributed and/or modified under + * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * OpenSceneGraph Public License for more details. +*/ + +#ifndef OSGSHADOW_OCCLUDERGEOMETRY +#define OSGSHADOW_OCCLUDERGEOMETRY 1 + +#include +#include +#include + +#include + +namespace osgShadow { + +/** OccluderGeometry provides a sepecialised geometry representation of objects in scene that occlude light and therefore cast shadows. + * OccluderGeometry supports the computation of silhouette edges and shadow volume geometries, as well as use as geometry that one can rendering + * into a shadow map or end caps for the ZP+ algorithm. OccluderGeometry may be of the same resolution as an underlying geometry that it + * represents, or can be of lower resolution and combine manager seperate geometries together into a single shadow casting object. + * OccluderGeometry may be attached as UserData to Nodes or to Drawables. */ +class OSGSHADOW_EXPORT OccluderGeometry : public osg::Drawable +{ + public : + OccluderGeometry(); + + OccluderGeometry(const OccluderGeometry& oc, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); + + virtual Object* cloneType() const { return new OccluderGeometry(); } + virtual Object* clone(const osg::CopyOp& copyop) const { return new OccluderGeometry(*this,copyop); } + virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast(obj)!=NULL; } + virtual const char* libraryName() const { return "osg"; } + virtual const char* className() const { return "OccluderGeometry"; } + + + struct Edge + { + Edge(): + _p1(0), + _p2(0), + _t1(0), + _t2(0) {} + + Edge(unsigned int p1, unsigned int p2, unsigned int t1, unsigned int t2): + _p1(p1), + _p2(p2), + _t1(t1), + _t2(t2) {} + + unsigned int _p1; + unsigned int _p2; + + unsigned int _t1; + unsigned int _t2; + }; + + typedef std::vector Vec3List; + typedef std::vector UIntList; + typedef std::vector EdgeList; + + + /** Compute an occluder geometry containing all the geometry in specified subgraph.*/ + void computeOccluderGeometry(osg::Node* subgraph, float sampleRatio=1.0f); + + /** Compute an occluder geometry containing the geometry in specified drawable.*/ + void computeOccluderGeometry(osg::Drawable* drawable, float sampleRatio=1.0f); + + /** Render the occluder geometry. */ + virtual void drawImplementation(osg::RenderInfo& renderInfo) const; + + + protected : + + virtual ~OccluderGeometry() {} + + inline bool isSilhouetteEdge(const osg::Vec3& lightpos, const Edge& edge) const + { + osg::Vec3 delta(lightpos-_vertices[edge._p1]); + return ( delta * _triangleNormals[edge._t1] ) * + ( delta * _triangleNormals[edge._t2] ); + } + + + Vec3List _vertices; + Vec3List _triangleNormals; + UIntList _triangleIndices; + +}; + +} + +#endif diff --git a/src/osgShadow/GNUmakefile b/src/osgShadow/GNUmakefile index d3e0c8662..9681fe3a2 100644 --- a/src/osgShadow/GNUmakefile +++ b/src/osgShadow/GNUmakefile @@ -3,6 +3,7 @@ include $(TOPDIR)/Make/makedefs CXXFILES = \ + OccluderGeometry.cpp\ ShadowedScene.cpp\ ShadowTechnique.cpp\ ShadowMap.cpp\ diff --git a/src/osgShadow/OccluderGeometry.cpp b/src/osgShadow/OccluderGeometry.cpp new file mode 100644 index 000000000..6e376a13b --- /dev/null +++ b/src/osgShadow/OccluderGeometry.cpp @@ -0,0 +1,39 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield + * + * This library is open source and may be redistributed and/or modified under + * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * OpenSceneGraph Public License for more details. +*/ + +#include + +using namespace osgShadow; + +OccluderGeometry::OccluderGeometry() +{ +} + +OccluderGeometry::OccluderGeometry(const OccluderGeometry& oc, const osg::CopyOp& copyop): + osg::Drawable(oc,copyop) +{ + +} + + +void OccluderGeometry::computeOccluderGeometry(osg::Node* subgraph, float sampleRatio) +{ +} + +void OccluderGeometry::computeOccluderGeometry(osg::Drawable* drawable, float sampleRatio) +{ +} + +void OccluderGeometry::drawImplementation(osg::RenderInfo& renderInfo) const +{ +} diff --git a/src/osgShadow/ShadowedScene.cpp b/src/osgShadow/ShadowedScene.cpp index c64025e8a..68ffb694c 100644 --- a/src/osgShadow/ShadowedScene.cpp +++ b/src/osgShadow/ShadowedScene.cpp @@ -20,7 +20,6 @@ #include using namespace osgShadow; -using namespace osg; ShadowedScene::ShadowedScene() {