From 9ec59783bac3dd69f0e0754591842bd733d5fef5 Mon Sep 17 00:00:00 2001 From: AnyOldName3 Date: Mon, 5 Feb 2018 23:03:18 +0000 Subject: [PATCH] Add basic support for distant terrain CLSB (cherry picked from commit 0f9dc3e65b72e6fff762f7a0933bae6f861e5fd4) --- components/sceneutil/shadow.cpp | 8 ++++++++ components/sceneutil/shadow.hpp | 3 +++ components/terrain/quadtreeworld.cpp | 7 +++++++ 3 files changed, 18 insertions(+) diff --git a/components/sceneutil/shadow.cpp b/components/sceneutil/shadow.cpp index 1e4112971f..cc3eb0be6c 100644 --- a/components/sceneutil/shadow.cpp +++ b/components/sceneutil/shadow.cpp @@ -282,6 +282,14 @@ namespace SceneUtil popCurrentMask(); } + void MWShadow::ComputeLightSpaceBounds::apply(Terrain::QuadTreeWorld & quadTreeWorld) + { + // For now, just expand the bounds fully as terrain will fill them up and possible ways to detect which terrain definitely won't cast shadows aren't implemented. + + update(osg::Vec3(-1.0, -1.0, 0.0)); + update(osg::Vec3(1.0, 1.0, 0.0)); + } + void MWShadow::ComputeLightSpaceBounds::apply(osg::Billboard&) { OSG_INFO << "Warning Billboards not yet supported" << std::endl; diff --git a/components/sceneutil/shadow.hpp b/components/sceneutil/shadow.hpp index b92e8658b2..897b8759da 100644 --- a/components/sceneutil/shadow.hpp +++ b/components/sceneutil/shadow.hpp @@ -4,6 +4,7 @@ #include #include +#include #include namespace SceneUtil @@ -34,6 +35,8 @@ namespace SceneUtil void apply(osg::Drawable& drawable); + void apply(Terrain::QuadTreeWorld& quadTreeWorld); + void apply(osg::Billboard&); void apply(osg::Projection&); diff --git a/components/terrain/quadtreeworld.cpp b/components/terrain/quadtreeworld.cpp index f310648050..76baa2f45b 100644 --- a/components/terrain/quadtreeworld.cpp +++ b/components/terrain/quadtreeworld.cpp @@ -4,6 +4,8 @@ #include +#include + #include "quadtreenode.hpp" #include "storage.hpp" #include "viewdata.hpp" @@ -344,7 +346,12 @@ void loadRenderingNode(ViewData::Entry& entry, ViewData* vd, ChunkManager* chunk void QuadTreeWorld::accept(osg::NodeVisitor &nv) { if (nv.getVisitorType() != osg::NodeVisitor::CULL_VISITOR && nv.getVisitorType() != osg::NodeVisitor::INTERSECTION_VISITOR) + { + SceneUtil::MWShadow::ComputeLightSpaceBounds* shadowBoundsVisitor = dynamic_cast(&nv); + if (shadowBoundsVisitor) + shadowBoundsVisitor->apply(*this); return; + } ViewData* vd = mRootNode->getView(nv);