diff --git a/components/sceneutil/mwshadowtechnique.cpp b/components/sceneutil/mwshadowtechnique.cpp index 522172f42c..1b390e33b3 100644 --- a/components/sceneutil/mwshadowtechnique.cpp +++ b/components/sceneutil/mwshadowtechnique.cpp @@ -769,6 +769,12 @@ void MWShadowTechnique::update(osg::NodeVisitor& nv) void MWShadowTechnique::cull(osgUtil::CullVisitor& cv) { + /* TODO: if (!enableShadows) + { + _shadowedScene->osg::Group::traverse(cv); + return; + }*/ + OSG_INFO<(cv.getCalculatedNearPlane(), minZNear); + reducedFar = osg::minimum(cv.getCalculatedFarPlane(), maxZFar); + } + else + { + reducedNear = minZNear; + reducedFar = maxZFar; + } + // return compute near far mode back to it's original settings cv.setComputeNearFarMode(cachedNearFarMode); @@ -868,11 +886,6 @@ void MWShadowTechnique::cull(osgUtil::CullVisitor& cv) previous_sdl.swap(sdl); unsigned int numShadowMapsPerLight = settings->getNumShadowMapsPerLight(); - if (numShadowMapsPerLight>2) - { - OSG_NOTICE<<"numShadowMapsPerLight of "<getLightDataList(); for(LightDataList::iterator itr = pll.begin(); @@ -943,6 +956,20 @@ void MWShadowTechnique::cull(osgUtil::CullVisitor& cv) double yMid = (clsb._bb.yMin()+clsb._bb.yMax())*0.5f; double yRange = (clsb._bb.yMax()-clsb._bb.yMin()); + osg::Matrixd cornerConverter = osg::Matrixd::inverse(projectionMatrix) * osg::Matrixd::inverse(viewMatrix) * *cv.getModelViewMatrix(); + double minZ = DBL_MAX; + double maxZ = -DBL_MAX; + for (unsigned int i = 0; i < 8; i++) + { + osg::Vec3 corner = clsb._bb.corner(i); + corner = corner * cornerConverter; + + maxZ = osg::maximum(maxZ, -corner.z()); + minZ = osg::minimum(minZ, -corner.z()); + } + reducedNear = osg::maximum(reducedNear, minZ); + reducedFar = osg::minimum(reducedFar, maxZ); + // OSG_NOTICE<<" xMid="<