1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-03-31 23:36:41 +00:00

Move CLSB changes to new shadow technique

This commit is contained in:
AnyOldName3 2018-02-26 14:58:12 +00:00
parent 06b2ce6646
commit 4c31b38f77
2 changed files with 137 additions and 109 deletions

View file

@ -293,11 +293,7 @@ void VDSMCameraCullCallback::operator()(osg::Node* node, osg::NodeVisitor* nv)
} }
} }
MWShadowTechnique::ComputeLightSpaceBounds::ComputeLightSpaceBounds(osg::Viewport* viewport, const osg::Matrixd& projectionMatrix, osg::Matrixd& viewMatrix) :
class ComputeLightSpaceBounds : public osg::NodeVisitor, public osg::CullStack
{
public:
ComputeLightSpaceBounds(osg::Viewport* viewport, const osg::Matrixd& projectionMatrix, osg::Matrixd& viewMatrix):
osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ACTIVE_CHILDREN) osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ACTIVE_CHILDREN)
{ {
setCullingMode(osg::CullSettings::VIEW_FRUSTUM_CULLING); setCullingMode(osg::CullSettings::VIEW_FRUSTUM_CULLING);
@ -307,7 +303,7 @@ public:
pushModelViewMatrix(new osg::RefMatrix(viewMatrix), osg::Transform::ABSOLUTE_RF); pushModelViewMatrix(new osg::RefMatrix(viewMatrix), osg::Transform::ABSOLUTE_RF);
} }
void apply(osg::Node& node) void MWShadowTechnique::ComputeLightSpaceBounds::apply(osg::Node& node)
{ {
if (isCulled(node)) return; if (isCulled(node)) return;
@ -320,7 +316,7 @@ public:
popCurrentMask(); popCurrentMask();
} }
void apply(osg::Drawable& drawable) void MWShadowTechnique::ComputeLightSpaceBounds::apply(osg::Drawable& drawable)
{ {
if (isCulled(drawable)) return; if (isCulled(drawable)) return;
@ -333,19 +329,27 @@ public:
popCurrentMask(); popCurrentMask();
} }
void apply(osg::Billboard&) void MWShadowTechnique::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 MWShadowTechnique::ComputeLightSpaceBounds::apply(osg::Billboard&)
{ {
OSG_INFO << "Warning Billboards not yet supported" << std::endl; OSG_INFO << "Warning Billboards not yet supported" << std::endl;
return; return;
} }
void apply(osg::Projection&) void MWShadowTechnique::ComputeLightSpaceBounds::apply(osg::Projection&)
{ {
// projection nodes won't affect a shadow map so their subgraphs should be ignored // projection nodes won't affect a shadow map so their subgraphs should be ignored
return; return;
} }
void apply(osg::Transform& transform) void MWShadowTechnique::ComputeLightSpaceBounds::apply(osg::Transform& transform)
{ {
if (isCulled(transform)) return; if (isCulled(transform)) return;
@ -369,13 +373,13 @@ public:
} }
void apply(osg::Camera&) void MWShadowTechnique::ComputeLightSpaceBounds::apply(osg::Camera&)
{ {
// camera nodes won't affect a shadow map so their subgraphs should be ignored // camera nodes won't affect a shadow map so their subgraphs should be ignored
return; return;
} }
void updateBound(const osg::BoundingBox& bb) void MWShadowTechnique::ComputeLightSpaceBounds::updateBound(const osg::BoundingBox& bb)
{ {
if (!bb.valid()) return; if (!bb.valid()) return;
@ -391,7 +395,7 @@ public:
update(bb.corner(7) * matrix); update(bb.corner(7) * matrix);
} }
void update(const osg::Vec3& v) void MWShadowTechnique::ComputeLightSpaceBounds::update(const osg::Vec3& v)
{ {
if (v.z()<-1.0f) if (v.z()<-1.0f)
{ {
@ -407,9 +411,6 @@ public:
_bb.expandBy(osg::Vec3(x, y, v.z())); _bb.expandBy(osg::Vec3(x, y, v.z()));
} }
osg::BoundingBox _bb;
};
/////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////
// //
// LightData // LightData

View file

@ -27,6 +27,8 @@
#include <osgShadow/ShadowTechnique> #include <osgShadow/ShadowTechnique>
#include <components/terrain/quadtreeworld.hpp>
namespace SceneUtil { namespace SceneUtil {
/** ViewDependentShadowMap provides an base implementation of view dependent shadow mapping techniques.*/ /** ViewDependentShadowMap provides an base implementation of view dependent shadow mapping techniques.*/
@ -59,6 +61,31 @@ namespace SceneUtil {
/** Clean scene graph from any shadow technique specific nodes, state and drawables.*/ /** Clean scene graph from any shadow technique specific nodes, state and drawables.*/
virtual void cleanSceneGraph(); virtual void cleanSceneGraph();
class ComputeLightSpaceBounds : public osg::NodeVisitor, public osg::CullStack
{
public:
ComputeLightSpaceBounds(osg::Viewport* viewport, const osg::Matrixd& projectionMatrix, osg::Matrixd& viewMatrix);
void apply(osg::Node& node);
void apply(osg::Drawable& drawable);
void apply(Terrain::QuadTreeWorld& quadTreeWorld);
void apply(osg::Billboard&);
void apply(osg::Projection&);
void apply(osg::Transform& transform);
void apply(osg::Camera&);
void updateBound(const osg::BoundingBox& bb);
void update(const osg::Vec3& v);
osg::BoundingBox _bb;
};
struct OSGSHADOW_EXPORT Frustum struct OSGSHADOW_EXPORT Frustum
{ {