diff --git a/include/osgShadow/OccluderGeometry b/include/osgShadow/OccluderGeometry index eedd8dbd3..5fda16945 100644 --- a/include/osgShadow/OccluderGeometry +++ b/include/osgShadow/OccluderGeometry @@ -128,12 +128,18 @@ class OSGSHADOW_EXPORT OccluderGeometry : public osg::Drawable virtual ~OccluderGeometry() {} - inline bool isSilhouetteEdge(const osg::Vec3& lightpos, const Edge& edge) const + inline float testLightPointSilhouetteEdge(const osg::Vec3& lightpos, const Edge& edge) const { osg::Vec3 delta(lightpos-_vertices[edge._p1]); return ( delta * _triangleNormals[edge._t1] ) * ( delta * _triangleNormals[edge._t2] ); } + + inline float testLightDirectionSilhouetteEdge(const osg::Vec3& lightdirection, const Edge& edge) const + { + return ( lightdirection * _triangleNormals[edge._t1] ) * + ( lightdirection * _triangleNormals[edge._t2] ); + } void setUpInternalStructures(); @@ -141,6 +147,9 @@ class OSGSHADOW_EXPORT OccluderGeometry : public osg::Drawable void removeNullTriangles(); void computeNormals(); void buildEdgeMaps(); + + void computeLightPointSlihouetteEdges(const osg::Vec3& lightpos); + void computeLightDirectionSlihouetteEdges(const osg::Vec3& lightdirection); Vec3List _vertices; Vec3List _normals; @@ -149,7 +158,7 @@ class OSGSHADOW_EXPORT OccluderGeometry : public osg::Drawable PointList _points; EdgeList _edges; - + UIntList _silhouetteIndices; }; } diff --git a/src/osgShadow/OccluderGeometry.cpp b/src/osgShadow/OccluderGeometry.cpp index 3090d1337..dce50ad5d 100644 --- a/src/osgShadow/OccluderGeometry.cpp +++ b/src/osgShadow/OccluderGeometry.cpp @@ -300,13 +300,41 @@ void OccluderGeometry::processGeometry(osg::Drawable* drawable, osg::Matrix* mat void OccluderGeometry::setUpInternalStructures() { + + osg::Timer_t t0 = osg::Timer::instance()->tick(); + removeDuplicateVertices(); + osg::Timer_t t1 = osg::Timer::instance()->tick(); + removeNullTriangles(); + osg::Timer_t t2 = osg::Timer::instance()->tick(); + computeNormals(); + osg::Timer_t t3 = osg::Timer::instance()->tick(); + buildEdgeMaps(); + + 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"< EdgeSet; EdgeSet edgeSet; @@ -601,6 +629,7 @@ void OccluderGeometry::buildEdgeMaps() } } +#if 0 osg::notify(osg::NOTICE)<<"Num of indices "<<_triangleIndices.size()<setNormalPointer( GL_FLOAT, 0, &(_normals.front()) ); } - glDrawElements(GL_TRIANGLES, _triangleIndices.size(), GL_UNSIGNED_INT, &(_triangleIndices.front()) ); + if (!_triangleIndices.empty()) + { + glDrawElements(GL_TRIANGLES, _triangleIndices.size(), GL_UNSIGNED_INT, &(_triangleIndices.front()) ); + } + + if (!_silhouetteIndices.empty()) + { + glColor4f(1.0f, 0.0f, 0.0f, 1.0f); + glDrawElements(GL_LINES, _silhouetteIndices.size(), GL_UNSIGNED_INT, &(_silhouetteIndices.front()) ); + } + } osg::BoundingBox OccluderGeometry::computeBound() const