From 26e2106636fdf135e0b50df3c164f0237992c2fe Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 24 Aug 2011 13:57:15 +0000 Subject: [PATCH] Changed new ViewDependentShadowMap to default to a perspective shadow map with automatic detection of a spot light/perspetive light projection matrix to prevent inappropriate usage of perspective shadow map. --- examples/osgshadow/osgshadow.cpp | 2 +- include/osgShadow/ViewDependentShadowMap | 10 +-- src/osgShadow/ViewDependentShadowMap.cpp | 87 +++++------------------- 3 files changed, 19 insertions(+), 80 deletions(-) diff --git a/examples/osgshadow/osgshadow.cpp b/examples/osgshadow/osgshadow.cpp index c352f5ec5..3a4e07c86 100644 --- a/examples/osgshadow/osgshadow.cpp +++ b/examples/osgshadow/osgshadow.cpp @@ -799,7 +799,7 @@ int main(int argc, char** argv) while( arguments.read("--debugHUD") ) vdsm->setDebugDraw( true ); if (arguments.read("--persp")) vdsm->setShadowMapProjectionHint(osgShadow::ViewDependentShadowMap::PERSPECTIVE_SHADOW_MAP); - if (arguments.read("--lispsm")) vdsm->setShadowMapProjectionHint(osgShadow::ViewDependentShadowMap::LIGHT_SPACE_PERSPECTIVE_SHADOW_MAP); + if (arguments.read("--ortho")) vdsm->setShadowMapProjectionHint(osgShadow::ViewDependentShadowMap::ORTHOGRAPHIC_SHADOW_MAP); shadowedScene->setShadowTechnique(vdsm.get()); } diff --git a/include/osgShadow/ViewDependentShadowMap b/include/osgShadow/ViewDependentShadowMap index 3b78f51c2..0a27a893b 100644 --- a/include/osgShadow/ViewDependentShadowMap +++ b/include/osgShadow/ViewDependentShadowMap @@ -148,9 +148,8 @@ class OSGSHADOW_EXPORT ViewDependentShadowMap : public ShadowTechnique enum ShadowMapProjectionHint { - STANDARD_SHADOW_MAP, - PERSPECTIVE_SHADOW_MAP, - LIGHT_SPACE_PERSPECTIVE_SHADOW_MAP + ORTHOGRAPHIC_SHADOW_MAP, + PERSPECTIVE_SHADOW_MAP }; void setShadowMapProjectionHint(ShadowMapProjectionHint hint) { _shadowMapProjectionHint = hint; } @@ -158,12 +157,7 @@ class OSGSHADOW_EXPORT ViewDependentShadowMap : public ShadowTechnique virtual bool computeShadowCameraSettings(Frustum& frustum, LightData& positionedLight, osg::Camera* camera); - virtual bool standardShadowMapCameraSettings(Frustum& frustum, LightData& positionedLight, osg::Camera* camera); - virtual bool perspectiveShadowMapCameraSettings(Frustum& frustum, LightData& positionedLight, osg::Camera* camera); - virtual bool lightSpacePerspectiveShadowMapCameraSettings(Frustum& frustum, LightData& positionedLight, osg::Camera* camera); - virtual bool adjustPerspectiveShadowMapCameraSettings(osgUtil::RenderStage* renderStage, Frustum& frustum, LightData& positionedLight, osg::Camera* camera); - virtual bool assignTexGenSettings(osgUtil::CullVisitor* cv, osg::Camera* camera, unsigned int textureUnit, osg::TexGen* texgen); diff --git a/src/osgShadow/ViewDependentShadowMap.cpp b/src/osgShadow/ViewDependentShadowMap.cpp index 8c96a6de8..b969e86be 100644 --- a/src/osgShadow/ViewDependentShadowMap.cpp +++ b/src/osgShadow/ViewDependentShadowMap.cpp @@ -485,7 +485,7 @@ ViewDependentShadowMap::ViewDependentData::ViewDependentData(ViewDependentShadow // ViewDependentShadowMap::ViewDependentShadowMap(): ShadowTechnique(), - _shadowMapProjectionHint(STANDARD_SHADOW_MAP), + _shadowMapProjectionHint(PERSPECTIVE_SHADOW_MAP), _debugDraw(false) { _shadowRecievingPlaceholderStateSet = new osg::StateSet; @@ -643,7 +643,7 @@ void ViewDependentShadowMap::cull(osgUtil::CullVisitor& cv) // 4.2 compute RTT camera view+projection matrix settings // - if (!standardShadowMapCameraSettings(frustum, pl, camera.get())) + if (!computeShadowCameraSettings(frustum, pl, camera.get())) { OSG_NOTICE<<"No valid Camera settings, no shadow to render"<getRenderStage(), frustum, pl, camera.get()); + if (vdsmCallback->getProjectionMatrix()) { - adjustPerspectiveShadowMapCameraSettings(vdsmCallback->getRenderStage(), frustum, pl, camera.get()); - if (vdsmCallback->getProjectionMatrix()) - { - vdsmCallback->getProjectionMatrix()->set(camera->getProjectionMatrix()); - } - break; + vdsmCallback->getProjectionMatrix()->set(camera->getProjectionMatrix()); } - default: break; } // 4.4 compute main scene graph TexGen + uniform settings + setup state @@ -932,18 +926,6 @@ osg::Polytope ViewDependentShadowMap::computeLightViewFrustumPolytope(Frustum& f } bool ViewDependentShadowMap::computeShadowCameraSettings(Frustum& frustum, LightData& positionedLight, osg::Camera* camera) -{ - OSG_INFO<<"computeShadowCameraSettings()"< Vertices; @@ -1410,6 +1385,16 @@ bool ViewDependentShadowMap::adjustPerspectiveShadowMapCameraSettings(osgUtil::R osg::Matrixd light_vp = light_v * light_p; osg::Vec3d lightdir(0.0,0.0,-1.0); + // check whether this light space projection is perspective or orthographic. + bool orthographicLightSpaceProjection = light_p(0,3)==0.0 && light_p(1,3)==0.0 && light_p(2,3)==0.0; + + if (!orthographicLightSpaceProjection) + { + OSG_INFO<<"perspective light space projection not yet supported."<