Fixed shadows warnings

This commit is contained in:
Robert Osfield
2016-05-25 11:00:35 +01:00
parent 831f406d17
commit 9ba599fe4c
5 changed files with 54 additions and 53 deletions

View File

@@ -323,22 +323,22 @@ void ConvexPolyhedron::transformClip(const osg::Matrix& matrix, const osg::Matri
double min = FLT_MAX, max = -FLT_MAX; //Hull max & min point distances
FaceDistancesList::iterator fd = faceDistances.begin();
// First step compute each face points distances to cutting plane
for( Faces::iterator itr = _faces.begin();
itr != _faces.end();
++itr, ++fd )
Faces::iterator faces_itr = _faces.begin();
for(FaceDistancesList::iterator fd = faceDistances.begin();
faces_itr != _faces.end();
++faces_itr, ++fd)
{
fd->itr = itr;
fd->distances.reserve( itr->vertices.size() );
fd->itr = faces_itr;
fd->distances.reserve( faces_itr->vertices.size() );
fd->on = 0;
fd->above = 0;
fd->below = 0;
itr->plane.transformProvidingInverse(inverse);
faces_itr->plane.transformProvidingInverse(inverse);
for( Vertices::iterator vitr = itr->vertices.begin();
vitr != itr->vertices.end();
for( Vertices::iterator vitr = faces_itr->vertices.begin();
vitr != faces_itr->vertices.end();
++vitr)
{
osg::Vec4d p( *vitr, 1.0 );
@@ -1236,32 +1236,33 @@ void ConvexPolyhedron::cut(const osg::Plane& plane, const std::string& name)
double min = FLT_MAX, max = -FLT_MAX; //Hull max & min point distances
FaceDistancesList::iterator fd = faceDistances.begin();
// First step compute each face points distances to cutting plane
for( Faces::iterator itr = _faces.begin();
itr != _faces.end();
++itr, ++fd )
Faces::iterator faces_itr = _faces.begin();
for(FaceDistancesList::iterator fd = faceDistances.begin();
faces_itr != _faces.end();
++faces_itr, ++fd )
{
fd->itr = itr;
fd->distances.reserve( itr->vertices.size() );
fd->itr = faces_itr;
fd->distances.reserve( faces_itr->vertices.size() );
fd->on = 0;
fd->above = 0;
fd->below = 0;
#if 0 // Skip if cutting plane the same as one of faces
if( plane.ptr()[0] ) == itr->plane.ptr()[0] &&
plane.ptr()[1] ) == itr->plane.ptr()[1] &&
plane.ptr()[2] ) == itr->plane.ptr()[2] &&
if( plane.ptr()[0] == faces_itr->plane.ptr()[0] &&
plane.ptr()[1] == faces_itr->plane.ptr()[1] &&
plane.ptr()[2] == faces_itr->plane.ptr()[2] &&
#else // check plane using less precise float values
if( float( plane.ptr()[0] ) == float( itr->plane.ptr()[0] ) &&
float( plane.ptr()[1] ) == float( itr->plane.ptr()[1] ) &&
float( plane.ptr()[2] ) == float( itr->plane.ptr()[2] ) &&
if( float( plane.ptr()[0] ) == float( faces_itr->plane.ptr()[0] ) &&
float( plane.ptr()[1] ) == float( faces_itr->plane.ptr()[1] ) &&
float( plane.ptr()[2] ) == float( faces_itr->plane.ptr()[2] ) &&
#endif
plane_hull_tolerance >= fabs( float( plane.ptr()[3] )- float( itr->plane.ptr()[3] ) ) )
plane_hull_tolerance >= fabs( float( plane.ptr()[3] )- float( faces_itr->plane.ptr()[3] ) ) )
return;
for( Vertices::iterator vitr = itr->vertices.begin();
vitr != itr->vertices.end();
for(Vertices::iterator vitr = faces_itr->vertices.begin();
vitr != faces_itr->vertices.end();
++vitr)
{
double d = plane.distance( *vitr );
@@ -1815,28 +1816,28 @@ bool ConvexPolyhedron::dumpGeometry
for( unsigned int i = 0; i < vertices.size(); i++ )
bb.expandBy( vertices[i] );
ConvexPolyhedron cp( *this ), cpFace;
ConvexPolyhedron cph( *this ), cpFace;
for( Faces::iterator itr = cp._faces.begin(); itr != cp._faces.end(); )
for( Faces::iterator itr = cph._faces.begin(); itr != cph._faces.end(); )
{
bool found = ( face &&
itr->name == face->name &&
itr->plane == face->plane &&
itr->vertices == face->vertices );
#if 1
if( cp.isFacePolygonConvex( *itr ) < 0 )
if( cph.isFacePolygonConvex( *itr ) < 0 )
std::reverse( itr->vertices.begin(), itr->vertices.end() );
#endif
if( found ) {
cpFace.createFace() = *face;
itr = cp._faces.erase( itr );
itr = cph._faces.erase( itr );
} else {
++itr;
}
}
osg::Geometry * geometry = cp.buildGeometry( colorOutline, colorInside );
osg::Geometry * geometry = cph.buildGeometry( colorOutline, colorInside );
geometry->getOrCreateStateSet()->setMode( GL_CULL_FACE, osg::StateAttribute::ON );
geode->addDrawable( geometry );
@@ -1847,10 +1848,10 @@ bool ConvexPolyhedron::dumpGeometry
if( plane )
{
ConvexPolyhedron cp;
Face & face = cp.createFace();
face.plane = *plane;
Face & cp_face = cp.createFace();
cp_face.plane = *plane;
osg::Vec3d normal = face.plane.getNormal();
osg::Vec3d normal = cp_face.plane.getNormal();
osg::Vec3d side = fabs(normal.x()) < fabs(normal.y()) ?
osg::Vec3d(1.0, 0.0, 0.0) :
osg::Vec3d(0.0, 1.0, 0.0);
@@ -1864,12 +1865,12 @@ bool ConvexPolyhedron::dumpGeometry
u *= bb.radius();
osg::Vec3d c = bb.center();
c -= face.plane.getNormal() * face.plane.distance( c );
c -= cp_face.plane.getNormal() * cp_face.plane.distance( c );
face.vertices.push_back( c - u - v );
face.vertices.push_back( c - u + v );
face.vertices.push_back( c + u + v );
face.vertices.push_back( c + u - v );
cp_face.vertices.push_back( c - u - v );
cp_face.vertices.push_back( c - u + v );
cp_face.vertices.push_back( c + u + v );
cp_face.vertices.push_back( c + u - v );
geode->addDrawable( cp.buildGeometry( planeColorOutline, planeColorInside ) );
}

View File

@@ -248,19 +248,19 @@ void MinimalShadowMap::ViewData::frameShadowCastingCamera
{
#if 1
{
osg::Matrix mvp = cameraShadow->getViewMatrix() * cameraShadow->getProjectionMatrix();
osg::Matrix debug_mvp = cameraShadow->getViewMatrix() * cameraShadow->getProjectionMatrix();
ConvexPolyhedron frustum;
frustum.setToUnitFrustum();
frustum.transform( osg::Matrix::inverse( mvp ), mvp );
frustum.transform( osg::Matrix::inverse( debug_mvp ), debug_mvp );
setDebugPolytope( "shadowCamFrustum", frustum, osg::Vec4(0,0,1,1) );
}
{
osg::Matrix mvp = cameraMain->getViewMatrix() * cameraMain->getProjectionMatrix();
osg::Matrix debug_mvp = cameraMain->getViewMatrix() * cameraMain->getProjectionMatrix();
ConvexPolyhedron frustum;
frustum.setToUnitFrustum();
frustum.transform( osg::Matrix::inverse( mvp ), mvp );
frustum.transform( osg::Matrix::inverse( debug_mvp ), debug_mvp );
setDebugPolytope( "mainCamFrustum", frustum, osg::Vec4(1,1,1,1) );
}

View File

@@ -604,13 +604,13 @@ void ParallelSplitShadowMap::cull(osgUtil::CullVisitor& cv){
osgUtil::RenderStage* orig_rs = cv.getRenderStage();
#ifdef SHADOW_TEXTURE_GLSL
PSSMShadowSplitTextureMap::iterator it=_PSSMShadowSplitTextureMap.begin();
PSSMShadowSplitTextureMap::iterator tm_itr=_PSSMShadowSplitTextureMap.begin();
#else
// do traversal of shadow receiving scene which does need to be decorated by the shadow map
for (PSSMShadowSplitTextureMap::iterator it=_PSSMShadowSplitTextureMap.begin();it!=_PSSMShadowSplitTextureMap.end();it++)
for (PSSMShadowSplitTextureMap::iterator tm_itr=_PSSMShadowSplitTextureMap.begin();it!=_PSSMShadowSplitTextureMap.end();it++)
#endif
{
PSSMShadowSplitTexture pssmShadowSplitTexture = it->second;
PSSMShadowSplitTexture pssmShadowSplitTexture = tm_itr->second;
cv.pushStateSet(pssmShadowSplitTexture._stateset.get());
//////////////////////////////////////////////////////////////////////////
@@ -677,7 +677,7 @@ void ParallelSplitShadowMap::cull(osgUtil::CullVisitor& cv){
// do traversal of shadow receiving scene which does need to be decorated by the shadow map
//unsigned int iMaxSplit = _PSSMShadowSplitTextureMap.size();
for (PSSMShadowSplitTextureMap::iterator it=_PSSMShadowSplitTextureMap.begin();it!=_PSSMShadowSplitTextureMap.end();it++)
for(PSSMShadowSplitTextureMap::iterator it=_PSSMShadowSplitTextureMap.begin();it!=_PSSMShadowSplitTextureMap.end();it++)
{
PSSMShadowSplitTexture pssmShadowSplitTexture = it->second;

View File

@@ -466,11 +466,11 @@ void ShadowMap::cull(osgUtil::CullVisitor& cv)
else // directional light
{
// make an orthographic projection
osg::Vec3 lightDir(lightpos.x(), lightpos.y(), lightpos.z());
lightDir.normalize();
osg::Vec3 ortho_lightDir(lightpos.x(), lightpos.y(), lightpos.z());
ortho_lightDir.normalize();
// set the position far away along the light direction
osg::Vec3 position = bb.center() + lightDir * bb.radius() * 2;
osg::Vec3 position = bb.center() + ortho_lightDir * bb.radius() * 2;
float centerDistance = (position-bb.center()).length();
@@ -483,7 +483,7 @@ void ShadowMap::cull(osgUtil::CullVisitor& cv)
float right = top;
_camera->setProjectionMatrixAsOrtho(-right, right, -top, top, znear, zfar);
_camera->setViewMatrixAsLookAt(position,bb.center(),computeOrthogonalVector(lightDir));
_camera->setViewMatrixAsLookAt(position,bb.center(),computeOrthogonalVector(ortho_lightDir));
}

View File

@@ -269,16 +269,16 @@ void ShadowVolume::cull(osgUtil::CullVisitor& cv)
cv.setCurrentRenderBin(original_bin.get());
osgUtil::RenderBin::RenderBinList::iterator itr = new_bin->getRenderBinList().find(1000);
osg::ref_ptr<osgUtil::RenderBin> shadowVolumeBin;
if (itr != new_bin->getRenderBinList().end())
osgUtil::RenderBin::RenderBinList::iterator rb_itr = new_bin->getRenderBinList().find(1000);
if (rb_itr != new_bin->getRenderBinList().end())
{
shadowVolumeBin = itr->second;
shadowVolumeBin = rb_itr->second;
if (shadowVolumeBin.valid())
{
//OSG_NOTICE<<"Found shadow volume bin, now removing it"<<std::endl;
new_bin->getRenderBinList().erase(itr);
new_bin->getRenderBinList().erase(rb_itr);
}
}