diff --git a/examples/osgshadow/osgshadow.cpp b/examples/osgshadow/osgshadow.cpp index 2c2579763..1f17fbe94 100644 --- a/examples/osgshadow/osgshadow.cpp +++ b/examples/osgshadow/osgshadow.cpp @@ -150,7 +150,12 @@ int main(int argc, char** argv) //geode->addDrawable(occluder.get()); osg::ref_ptr shadowVolume = new osgShadow::ShadowVolumeGeometry; + +#if 0 + occluder->comptueShadowVolumeGeometry(osg::Vec4(bb.xMin(), bb.yMin(), bb.zMax() + bb.radius() ,1.0f), *shadowVolume); +#else occluder->comptueShadowVolumeGeometry(osg::Vec4(0.5f,-.5f,-1.0f,0.0f), *shadowVolume); +#endif geode->addDrawable(shadowVolume.get()); diff --git a/include/osgShadow/OccluderGeometry b/include/osgShadow/OccluderGeometry index 574af937f..44a6955a0 100644 --- a/include/osgShadow/OccluderGeometry +++ b/include/osgShadow/OccluderGeometry @@ -44,19 +44,44 @@ class OSGSHADOW_EXPORT OccluderGeometry : public osg::Drawable virtual const char* libraryName() const { return "osgShadow"; } virtual const char* className() const { return "OccluderGeometry"; } + /** Compute an occluder geometry containing all the geometry in specified subgraph.*/ + void computeOccluderGeometry(osg::Node* subgraph, osg::Matrix* matrix=0, float sampleRatio=1.0f); + + /** Compute an occluder geometry containing the geometry in specified drawable.*/ + void computeOccluderGeometry(osg::Drawable* drawable, osg::Matrix* matrix=0, float sampleRatio=1.0f); + + + /** Compute ShadowVolumeGeometry. */ + void comptueShadowVolumeGeometry(const osg::Vec4& lightpos, ShadowVolumeGeometry& svg) const; + + + /** Set the bounding polytope of the OccluderGeometry.*/ + void setBoundingPolytope(const osg::Polytope& polytope) { _boundingPolytope = polytope; } + + /** Get the bounding polytope of the OccluderGeometry.*/ + osg::Polytope& getBoundingPolytope() { return _boundingPolytope; } + + /** Get the const bounding polytope of the OccluderGeometry.*/ + const osg::Polytope& getBoundingPolytope() const { return _boundingPolytope; } + + + /** Render the occluder geometry. */ + virtual void drawImplementation(osg::RenderInfo& renderInfo) const; + + /** Compute the bounding box around occluder geometry.*/ + virtual osg::BoundingBox computeBound() const; typedef std::vector Vec3List; typedef std::vector UIntList; - struct Point - { - Point() {} + public: - UIntList _edges; - }; + void processGeometry(osg::Drawable* drawable, osg::Matrix* matrix=0, float sampleRatio=1.0f); - typedef std::vector PointList; + protected : + virtual ~OccluderGeometry() {} + struct Edge { Edge(): @@ -115,42 +140,6 @@ class OSGSHADOW_EXPORT OccluderGeometry : public osg::Drawable typedef std::vector EdgeList; - - /** Compute an occluder geometry containing all the geometry in specified subgraph.*/ - void computeOccluderGeometry(osg::Node* subgraph, osg::Matrix* matrix=0, float sampleRatio=1.0f); - - /** Compute an occluder geometry containing the geometry in specified drawable.*/ - void computeOccluderGeometry(osg::Drawable* drawable, osg::Matrix* matrix=0, float sampleRatio=1.0f); - - - /** Compute ShadowVolumeGeometry. */ - void comptueShadowVolumeGeometry(const osg::Vec4& lightpos, ShadowVolumeGeometry& svg); - - - /** Set the bounding polytope of the OccluderGeometry.*/ - void setBoundingPolytope(const osg::Polytope& polytope) { _boundingPolytope = polytope; } - - /** Get the bounding polytope of the OccluderGeometry.*/ - osg::Polytope& getBoundingPolytope() { return _boundingPolytope; } - - /** Get the const bounding polytope of the OccluderGeometry.*/ - const osg::Polytope& getBoundingPolytope() const { return _boundingPolytope; } - - - /** Render the occluder geometry. */ - virtual void drawImplementation(osg::RenderInfo& renderInfo) const; - - /** Compute the bounding box around occluder geometry.*/ - virtual osg::BoundingBox computeBound() const; - - public: - - void processGeometry(osg::Drawable* drawable, osg::Matrix* matrix=0, float sampleRatio=1.0f); - - protected : - - virtual ~OccluderGeometry() {} - inline bool isLightPointSilhouetteEdge(const osg::Vec3& lightpos, const Edge& edge) const { if (edge.boundaryEdge()) return true; @@ -183,8 +172,8 @@ class OSGSHADOW_EXPORT OccluderGeometry : public osg::Drawable void computeNormals(); void buildEdgeMaps(); - void computeLightPointSlihouetteEdges(const osg::Vec3& lightpos); - void computeLightDirectionSlihouetteEdges(const osg::Vec3& lightdirection); + void computeLightDirectionSlihouetteEdges(const osg::Vec3& lightdirection, UIntList& silhouetteIndices) const; + void computeLightPositionSlihouetteEdges(const osg::Vec3& lightpos, UIntList& silhouetteIndices) const; osg::Polytope _boundingPolytope; @@ -193,9 +182,7 @@ class OSGSHADOW_EXPORT OccluderGeometry : public osg::Drawable Vec3List _triangleNormals; UIntList _triangleIndices; - PointList _points; EdgeList _edges; - UIntList _silhouetteIndices; }; class OSGSHADOW_EXPORT ShadowVolumeGeometry : public osg::Drawable diff --git a/src/osgShadow/OccluderGeometry.cpp b/src/osgShadow/OccluderGeometry.cpp index be1bebb0e..437f935cd 100644 --- a/src/osgShadow/OccluderGeometry.cpp +++ b/src/osgShadow/OccluderGeometry.cpp @@ -319,21 +319,12 @@ void OccluderGeometry::setUpInternalStructures() osg::Timer_t t4 = osg::Timer::instance()->tick(); - computeLightDirectionSlihouetteEdges(osg::Vec3(0.0,0.0,1.0f)); - - osg::Timer_t t45 = osg::Timer::instance()->tick(); - - computeLightDirectionSlihouetteEdges(osg::Vec3(0.0,0.0,1.0f)); - - osg::Timer_t t5 = osg::Timer::instance()->tick(); osg::notify(osg::NOTICE)<<"removeDuplicateVertices "<delta_m(t0,t1)<<" ms"<delta_m(t1,t2)<<" ms"<delta_m(t2,t3)<<" ms"<delta_m(t3,t4)<<" ms"<delta_m(t4,t45)<<" ms"<delta_m(t45,t5)<<" ms"<delta_m(t0,t5)<<" ms"<delta_m(t0,t4)<<" ms"<tick(); + ShadowVolumeGeometry::Vec3List& shadowVertices = svg.getVertices(); shadowVertices.clear(); @@ -746,25 +752,27 @@ void OccluderGeometry::comptueShadowVolumeGeometry(const osg::Vec4& lightpos, Sh basePlane = planes[0]; } - osg::Vec3 offset; - if (lightpos.w()==0.0) { + // directional light. osg::Vec3 lightdirection( lightpos.x(), lightpos.y(), lightpos.z()); osg::notify(osg::NOTICE)<<"Directional light"<tick(); + osg::notify(osg::NOTICE)<<"comptueShadowVolumeGeometry "<delta_m(t0,t1)<<" ms"<